Skip to content

Commit

Permalink
Warn about stdin/stdout terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Apr 14, 2024
1 parent e9fec41 commit fe61271
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ name = "gifski"
required-features = ["binary"]

[dependencies]
clap = { version = "4.3.24", features = ["cargo"], optional = true }
imgref = "1.10.0"
clap = { version = "4.5.4", features = ["cargo"], optional = true }
imgref = "1.10.1"
gif = { version = "0.13.1", default-features = false, features = ["std", "raii_no_panic"] }
gif-dispose = "5.0.0-beta.2"
imagequant = "4.3.0"
Expand Down
13 changes: 12 additions & 1 deletion src/bin/gifski.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use clap::builder::NonEmptyStringValueParser;
use std::io::stdin;
use std::io::BufRead;
use std::io::BufReader;
use std::io::IsTerminal;
use std::io::Read;
use std::io::StdinLock;
use std::io::Stdout;
Expand Down Expand Up @@ -260,7 +261,11 @@ fn bin_main() -> BinResult<()> {
let decode_thread = thread::Builder::new().name("decode".into()).spawn_scoped(scope, move || {
let mut decoder = if let [path] = &frames[..] {
let mut src = if path.as_os_str() == "-" {
SrcPath::Stdin(BufReader::new(stdin().lock()))
let fd = stdin().lock();
if fd.is_terminal() {
eprintln!("warning: used '-' as the input path, but the stdin is a terminal, not a file.");
}
SrcPath::Stdin(BufReader::new(fd))
} else {
SrcPath::Path(path.to_path_buf())
};
Expand Down Expand Up @@ -303,6 +308,7 @@ fn bin_main() -> BinResult<()> {

let mut file_tmp;
let mut stdio_tmp;
let mut print_terminal_err = false;
let out: &mut dyn io::Write = match output_path {
DestPath::Path(p) => {
file_tmp = File::create(p)
Expand All @@ -311,6 +317,7 @@ fn bin_main() -> BinResult<()> {
},
DestPath::Stdout => {
stdio_tmp = io::stdout().lock();
print_terminal_err = stdio_tmp.is_terminal();
&mut stdio_tmp
},
};
Expand All @@ -333,6 +340,10 @@ fn bin_main() -> BinResult<()> {
&mut pb
};

if print_terminal_err {
eprintln!("warning: used '-' as the output path, but the stdout is a terminal, not a file");
std::thread::sleep(Duration::from_secs(3));
}
let write_result = writer.write(io::BufWriter::new(out), progress);
let thread_result = decode_thread.join().map_err(panic_err)?;
check_errors(write_result, thread_result)?;
Expand Down

0 comments on commit fe61271

Please sign in to comment.