Skip to content

Commit 31415ef

Browse files
authored
docs(shell): update example to include Encoding usage in Command::spawn (#3183)
* docs(shell): update example to include Encoding usage in `Command::spawn` * docs(shell): update patch level to minor for Encoding usage in `Command::spawn` documentation * Update .changes/doc-to-Encoding-usage-in-shell.md Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * docs(shell): update examples to demonstrate manual Encoding usage in command output * Update plugins/shell/src/process/mod.rs Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * docs(shell): update example to use 'windows-1252' encoding in command output * Update plugins/shell/src/process/mod.rs Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * docs(shell): update example command in documentation to use 'some-program' with 'some-arg' * Bump shell-js in change file * Fix indent
1 parent 04b33ea commit 31415ef

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
shell: patch
3+
shell-js: patch
4+
---
5+
6+
Docs on example to Encoding usage in `Command::spawn`. No user facing changes.

plugins/shell/src/process/mod.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ impl Command {
242242
/// .setup(|app| {
243243
/// let handle = app.handle().clone();
244244
/// tauri::async_runtime::spawn(async move {
245-
/// let (mut rx, mut child) = handle.shell().command("cargo")
245+
/// let (mut rx, mut child) = handle
246+
/// .shell()
247+
/// .command("cargo")
246248
/// .args(["tauri", "dev"])
247249
/// .spawn()
248250
/// .expect("Failed to spawn cargo");
@@ -260,7 +262,34 @@ impl Command {
260262
/// }
261263
/// });
262264
/// Ok(())
263-
/// });
265+
/// });
266+
/// ```
267+
///
268+
/// Depending on the command you spawn, it might output in a specific encoding, to parse the output lines in this case:
269+
///
270+
/// ```rust,no_run
271+
/// use tauri_plugin_shell::{process::{CommandEvent, Encoding}, ShellExt};
272+
/// tauri::Builder::default()
273+
/// .setup(|app| {
274+
/// let handle = app.handle().clone();
275+
/// tauri::async_runtime::spawn(async move {
276+
/// let (mut rx, mut child) = handle
277+
/// .shell()
278+
/// .command("some-program")
279+
/// .arg("some-arg")
280+
/// .spawn()
281+
/// .expect("Failed to spawn some-program");
282+
///
283+
/// let encoding = Encoding::for_label(b"windows-1252").unwrap();
284+
/// while let Some(event) = rx.recv().await {
285+
/// if let CommandEvent::Stdout(line) = event {
286+
/// let (decoded, _, _) = encoding.decode(&line);
287+
/// println!("got: {decoded}");
288+
/// }
289+
/// }
290+
/// });
291+
/// Ok(())
292+
/// });
264293
/// ```
265294
pub fn spawn(self) -> crate::Result<(Receiver<CommandEvent>, CommandChild)> {
266295
let raw = self.raw_out;

0 commit comments

Comments
 (0)