mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-01-31 00:45:24 +01:00
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
This commit is contained in:
6
.changes/doc-to-Encoding-usage-in-shell.md
Normal file
6
.changes/doc-to-Encoding-usage-in-shell.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
shell: patch
|
||||
shell-js: patch
|
||||
---
|
||||
|
||||
Docs on example to Encoding usage in `Command::spawn`. No user facing changes.
|
||||
@@ -242,7 +242,9 @@ impl Command {
|
||||
/// .setup(|app| {
|
||||
/// let handle = app.handle().clone();
|
||||
/// tauri::async_runtime::spawn(async move {
|
||||
/// let (mut rx, mut child) = handle.shell().command("cargo")
|
||||
/// let (mut rx, mut child) = handle
|
||||
/// .shell()
|
||||
/// .command("cargo")
|
||||
/// .args(["tauri", "dev"])
|
||||
/// .spawn()
|
||||
/// .expect("Failed to spawn cargo");
|
||||
@@ -260,7 +262,34 @@ impl Command {
|
||||
/// }
|
||||
/// });
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// });
|
||||
/// ```
|
||||
///
|
||||
/// Depending on the command you spawn, it might output in a specific encoding, to parse the output lines in this case:
|
||||
///
|
||||
/// ```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("some-program")
|
||||
/// .arg("some-arg")
|
||||
/// .spawn()
|
||||
/// .expect("Failed to spawn some-program");
|
||||
///
|
||||
/// let encoding = Encoding::for_label(b"windows-1252").unwrap();
|
||||
/// while let Some(event) = rx.recv().await {
|
||||
/// if let CommandEvent::Stdout(line) = event {
|
||||
/// let (decoded, _, _) = encoding.decode(&line);
|
||||
/// println!("got: {decoded}");
|
||||
/// }
|
||||
/// }
|
||||
/// });
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
pub fn spawn(self) -> crate::Result<(Receiver<CommandEvent>, CommandChild)> {
|
||||
let raw = self.raw_out;
|
||||
|
||||
Reference in New Issue
Block a user