Skip to content

Commit 69ee4e9

Browse files
committed
dyt-cli: support writing output directly to a file
The nvim integration can continue to use a terminal when the text is redirected to a file instead of falling back to an emulation with `jobstart()`.
1 parent 3d2d149 commit 69ee4e9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ dyt --record | wc -w
177177

178178
Copying to the clipboard can be suppressed with the `--no-clipboard` option.
179179

180+
Output may be redirected to a file with the `--output` flag.
181+
180182
### Smoke test
181183

182184
Verify your mic works without needing the daemon:

dyt-cli/src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use std::fs::File;
2+
use std::io::Write;
3+
use std::path::PathBuf;
4+
15
use dyt_cli::{capture, encode, transport};
26

37
use anyhow::Result;
@@ -17,6 +21,10 @@ struct Cli {
1721
/// Suppress copying text to the clipboard.
1822
#[arg(long)]
1923
no_clipboard: bool,
24+
25+
/// Write to an output file. Defaults to stdout.
26+
#[arg(long)]
27+
output: Option<PathBuf>,
2028
}
2129

2230
fn main() -> Result<()> {
@@ -43,8 +51,13 @@ fn main() -> Result<()> {
4351
eprintln!("Copied to clipboard.");
4452
}
4553

46-
// Also print to stdout for piping
47-
print!("{text}");
54+
if let Some(output) = cli.output {
55+
let mut fout = File::open(output)?;
56+
write!(fout, "{text}")?;
57+
} else {
58+
// Also print to stdout for piping
59+
print!("{text}");
60+
}
4861

4962
Ok(())
5063
}

0 commit comments

Comments
 (0)