diff --git a/.changes/fix-stdout-readline-encoding.md b/.changes/fix-stdout-readline-encoding.md new file mode 100644 index 000000000..8d32deab8 --- /dev/null +++ b/.changes/fix-stdout-readline-encoding.md @@ -0,0 +1,6 @@ +--- +"shell": patch +"shell-js": patch +--- + +Fix incorrect stdout encoding when readline. \ No newline at end of file diff --git a/plugins/shell/src/process/mod.rs b/plugins/shell/src/process/mod.rs index 6f350c181..757464e52 100644 --- a/plugins/shell/src/process/mod.rs +++ b/plugins/shell/src/process/mod.rs @@ -23,6 +23,10 @@ const NEWLINE_BYTE: u8 = b'\n'; use tauri::async_runtime::{block_on as block_on_task, channel, Receiver, Sender}; pub use encoding_rs::Encoding; +#[cfg(not(windows))] +use encoding_rs::UTF_8 as SYSTEM_ENCODING; +#[cfg(windows)] +use encoding_rs::WINDOWS_1252 as SYSTEM_ENCODING; use os_pipe::{pipe, PipeReader, PipeWriter}; use serde::Serialize; use shared_child::SharedChild; @@ -435,8 +439,10 @@ fn read_line) -> CommandEvent + Send + Copy + 'static>( if n == 0 { break; } + let (cow, _, _) = SYSTEM_ENCODING.decode(&buf); + let decode_bytes = cow.into_owned().into_bytes(); let tx_ = tx.clone(); - let _ = block_on_task(async move { tx_.send(wrapper(buf)).await }); + let _ = block_on_task(async move { tx_.send(wrapper(decode_bytes)).await }); } Err(e) => { let tx_ = tx.clone();