mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
fix: fail --tty when /dev/tty cannot be opened; satisfy clippy
Return an error if --tty is set but /dev/tty is unavailable (e.g. macOS permissions). Add unit tests for terminal_io. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
961ac03ad2
commit
ba7fff0570
1 changed files with 22 additions and 2 deletions
|
|
@ -24,8 +24,10 @@ impl TerminalWriter {
|
|||
{
|
||||
let use_tty = force_tty || !io::stdout().is_terminal();
|
||||
if use_tty {
|
||||
if let Ok(file) = std::fs::File::open("/dev/tty") {
|
||||
return Ok(Self::Tty(file));
|
||||
match std::fs::File::open("/dev/tty") {
|
||||
Ok(file) => return Ok(Self::Tty(file)),
|
||||
Err(err) if force_tty => return Err(err),
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -102,3 +104,21 @@ pub fn execute<C: Command>(cmd: C) -> io::Result<()> {
|
|||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn open_stdout_when_not_forcing_tty() {
|
||||
let writer = TerminalWriter::open(false).unwrap();
|
||||
assert!(matches!(writer, TerminalWriter::Stdout(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(unix))]
|
||||
fn open_tty_errors_on_non_unix() {
|
||||
let err = TerminalWriter::open(true).unwrap_err();
|
||||
assert_eq!(err.kind(), io::ErrorKind::Unsupported);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue