Skip to content
Merged
4 changes: 4 additions & 0 deletions .changes/doc-to-Encoding-usage-in-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"shell": patch
---
Docs on example to Encoding usage in `Command::spawn`. No user facing changes.
25 changes: 25 additions & 0 deletions plugins/shell/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ impl Command {
/// Ok(())
/// });
/// ```
///
/// # Examples Mannual Encoding
Comment thread
Tunglies marked this conversation as resolved.
Outdated
///
/// ```rust,no_run
/// use tauri_plugin_shell::{process::{CommandEvent, Encoding}, ShellExt};
/// tauri::Builder::default()
/// .setup(|app| {
/// let handle = app.handle().clone();
/// tauri::async_runtime::spawn(async move {
/// let (mut rx, mut child) = handle.shell().command("cargo")
Comment thread
Tunglies marked this conversation as resolved.
Outdated
/// .args(["tauri", "dev"])
/// .spawn()
/// .expect("Failed to spawn cargo");
///
/// let encoding = Encoding::for_label(b"utf-8").unwrap();
Comment thread
Tunglies marked this conversation as resolved.
Outdated
/// while let Some(event) = rx.recv().await {
/// if let CommandEvent::Stdout(line) = event {
/// let (decoded, _, _) = encoding.decode(&line);
/// println!("got: {}", decoded);
Comment thread
Tunglies marked this conversation as resolved.
Outdated
/// }
/// }
/// });
/// Ok(())
/// });
/// ```
pub fn spawn(self) -> crate::Result<(Receiver<CommandEvent>, CommandChild)> {
let raw = self.raw_out;
let mut command: StdCommand = self.into();
Expand Down