|
7 | 7 |
|
8 | 8 | use clap::{Arg, ArgAction, Command}; |
9 | 9 | use std::io::{IsTerminal, Write}; |
10 | | -use uucore::display::OsWrite; |
11 | 10 | use uucore::error::{UResult, set_exit_code}; |
12 | 11 | use uucore::format_usage; |
13 | 12 |
|
@@ -38,18 +37,27 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { |
38 | 37 | } |
39 | 38 |
|
40 | 39 | let mut stdout = std::io::stdout(); |
41 | | - |
| 40 | + #[cfg(unix)] |
42 | 41 | let name = rustix::termios::ttyname(std::io::stdin(), Vec::with_capacity(8)); |
43 | | - |
| 42 | + #[cfg(unix)] |
44 | 43 | let write_result = if let Ok(name) = name { |
45 | 44 | use std::os::unix::ffi::OsStrExt; |
| 45 | + use uucore::display::OsWrite; |
46 | 46 | let os_name = std::ffi::OsStr::from_bytes(name.as_bytes()); |
47 | 47 | stdout.write_all_os(os_name) |
48 | 48 | } else { |
49 | 49 | set_exit_code(1); |
50 | 50 | writeln!(stdout, "{}", translate!("tty-not-a-tty")) |
51 | 51 | }; |
52 | 52 |
|
| 53 | + #[cfg(target_os = "windows")] |
| 54 | + let write_result = if std::io::stdin().is_terminal() { |
| 55 | + writeln!(stdout, r"\\.\CON") |
| 56 | + } else { |
| 57 | + set_exit_code(1); |
| 58 | + writeln!(stdout, "{}", translate!("tty-not-a-tty")) |
| 59 | + }; |
| 60 | + |
53 | 61 | if write_result.is_err() || stdout.flush().is_err() { |
54 | 62 | // Don't return to prevent a panic later when another flush is attempted |
55 | 63 | // because the `uucore_procs::main` macro inserts a flush after execution for every utility. |
|
0 commit comments