1 //! A command which prints out information about the standard input,
2 //! output, and error streams provided to it.
4 #![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
9 use rustix
::io
::{self, stderr, stdin, stdout}
;
10 #[cfg(feature = "termios")]
12 use rustix
::termios
::isatty
;
13 #[cfg(all(not(windows), feature = "termios", feature = "procfs"))]
14 use rustix
::termios
::ttyname
;
17 fn main() -> io
::Result
<()> {
18 let (stdin
, stdout
, stderr
) = unsafe { (stdin(), stdout(), stderr()) }
;
33 fn show
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<()> {
35 println
!(" - ready: {:?}", rustix
::io
::ioctl_fionread(fd
)?
);
37 #[cfg(feature = "termios")]
39 #[cfg(feature = "procfs")]
40 println
!(" - ttyname: {}", ttyname(fd
, Vec
::new())?
.to_string_lossy());
41 println
!(" - process group: {:?}", rustix
::termios
::tcgetpgrp(fd
)?
);
42 println
!(" - winsize: {:?}", rustix
::termios
::tcgetwinsize(fd
)?
);
45 use rustix
::termios
::*;
46 let term
= tcgetattr(fd
)?
;
48 if let Some(speed
) = speed_value(cfgetispeed(&term
)) {
49 println
!(" - ispeed: {}", speed
);
51 if let Some(speed
) = speed_value(cfgetospeed(&term
)) {
52 println
!(" - ospeed: {}", speed
);
55 print
!(" - in flags:");
56 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
57 if (term
.c_iflag
& IGNBRK
) != 0 {
60 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
61 if (term
.c_iflag
& BRKINT
) != 0 {
64 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
65 if (term
.c_iflag
& IGNPAR
) != 0 {
68 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
69 if (term
.c_iflag
& PARMRK
) != 0 {
72 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
73 if (term
.c_iflag
& INPCK
) != 0 {
76 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
77 if (term
.c_iflag
& ISTRIP
) != 0 {
80 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
81 if (term
.c_iflag
& INLCR
) != 0 {
84 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
85 if (term
.c_iflag
& IGNCR
) != 0 {
88 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
89 if (term
.c_iflag
& ICRNL
) != 0 {
96 any(target_os
= "haiku", target_os
= "illumos", target_os
= "solaris"),
99 if (term
.c_iflag
& IUCLC
) != 0 {
102 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
103 if (term
.c_iflag
& IXON
) != 0 {
106 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
107 if (term
.c_iflag
& IXANY
) != 0 {
110 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
111 if (term
.c_iflag
& IXOFF
) != 0 {
114 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
115 if (term
.c_iflag
& IMAXBEL
) != 0 {
119 target_os
= "dragonfly",
120 target_os
= "freebsd",
121 target_os
= "illumos",
124 target_os
= "netbsd",
125 target_os
= "openbsd",
128 if (term
.c_iflag
& IUTF8
) != 0 {
133 print
!(" - out flags:");
134 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
135 if (term
.c_oflag
& OPOST
) != 0 {
139 target_os
= "dragonfly",
140 target_os
= "freebsd",
143 target_os
= "netbsd",
146 if (term
.c_oflag
& OLCUC
) != 0 {
149 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
150 if (term
.c_oflag
& ONLCR
) != 0 {
153 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
154 if (term
.c_oflag
& OCRNL
) != 0 {
157 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
158 if (term
.c_oflag
& ONOCR
) != 0 {
161 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
162 if (term
.c_oflag
& ONLRET
) != 0 {
166 target_os
= "dragonfly",
167 target_os
= "freebsd",
170 target_os
= "netbsd",
171 target_os
= "openbsd",
173 if (term
.c_oflag
& OFILL
) != 0 {
177 target_os
= "dragonfly",
178 target_os
= "freebsd",
181 target_os
= "netbsd",
182 target_os
= "openbsd",
184 if (term
.c_oflag
& OFDEL
) != 0 {
188 target_os
= "dragonfly",
189 target_os
= "freebsd",
190 target_os
= "illumos",
193 target_os
= "netbsd",
194 target_os
= "openbsd",
197 if (term
.c_oflag
& NLDLY
) != 0 {
201 target_os
= "dragonfly",
202 target_os
= "freebsd",
203 target_os
= "illumos",
206 target_os
= "netbsd",
207 target_os
= "openbsd",
210 if (term
.c_oflag
& CRDLY
) != 0 {
216 target_os
= "netbsd",
217 target_os
= "openbsd",
218 target_os
= "illumos",
221 if (term
.c_oflag
& TABDLY
) != 0 {
225 target_os
= "dragonfly",
226 target_os
= "freebsd",
227 target_os
= "illumos",
230 target_os
= "netbsd",
231 target_os
= "openbsd",
234 if (term
.c_oflag
& BSDLY
) != 0 {
238 all(libc
, target_env
= "musl"),
239 target_os
= "dragonfly",
240 target_os
= "freebsd",
241 target_os
= "illumos",
244 target_os
= "netbsd",
245 target_os
= "openbsd",
248 if (term
.c_oflag
& VTDLY
) != 0 {
252 all(libc
, target_env
= "musl"),
253 target_os
= "dragonfly",
254 target_os
= "freebsd",
255 target_os
= "illumos",
258 target_os
= "netbsd",
259 target_os
= "openbsd",
262 if (term
.c_oflag
& FFDLY
) != 0 {
267 print
!(" - control flags:");
269 target_os
= "dragonfly",
270 target_os
= "freebsd",
273 target_os
= "netbsd",
274 target_os
= "openbsd",
277 if (term
.c_cflag
& CBAUD
) != 0 {
281 target_os
= "dragonfly",
282 target_os
= "freebsd",
283 target_os
= "illumos",
286 target_os
= "netbsd",
287 target_os
= "openbsd",
290 if (term
.c_cflag
& CBAUDEX
) != 0 {
293 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
294 if (term
.c_cflag
& CSIZE
) != 0 {
297 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
298 if (term
.c_cflag
& CSTOPB
) != 0 {
301 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
302 if (term
.c_cflag
& CREAD
) != 0 {
305 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
306 if (term
.c_cflag
& PARENB
) != 0 {
309 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
310 if (term
.c_cflag
& PARODD
) != 0 {
313 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
314 if (term
.c_cflag
& HUPCL
) != 0 {
317 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
318 if (term
.c_cflag
& CLOCAL
) != 0 {
322 target_os
= "dragonfly",
323 target_os
= "freebsd",
326 target_os
= "netbsd",
327 target_os
= "openbsd",
330 if (term
.c_cflag
& CIBAUD
) != 0 {
334 target_os
= "dragonfly",
335 target_os
= "freebsd",
336 target_os
= "illumos",
339 target_os
= "netbsd",
340 target_os
= "openbsd",
343 if (term
.c_cflag
& CMSPAR
) != 0 {
346 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
347 if (term
.c_cflag
& CRTSCTS
) != 0 {
352 print
!(" - local flags:");
353 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
354 if (term
.c_lflag
& ISIG
) != 0 {
357 if (term
.c_lflag
& ICANON
) != 0 {
360 #[cfg(any(linux_raw, all(libc, any(target_arch = "s390x", target_os = "haiku"))))]
361 if (term
.c_lflag
& XCASE
) != 0 {
364 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
365 if (term
.c_lflag
& ECHO
) != 0 {
368 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
369 if (term
.c_lflag
& ECHOE
) != 0 {
372 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
373 if (term
.c_lflag
& ECHOK
) != 0 {
376 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
377 if (term
.c_lflag
& ECHONL
) != 0 {
380 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
381 if (term
.c_lflag
& ECHOCTL
) != 0 {
384 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
385 if (term
.c_lflag
& ECHOPRT
) != 0 {
388 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
389 if (term
.c_lflag
& ECHOKE
) != 0 {
392 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
393 if (term
.c_lflag
& FLUSHO
) != 0 {
396 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
397 if (term
.c_lflag
& NOFLSH
) != 0 {
400 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
401 if (term
.c_lflag
& TOSTOP
) != 0 {
404 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
405 if (term
.c_lflag
& PENDIN
) != 0 {
408 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
409 if (term
.c_lflag
& IEXTEN
) != 0 {
415 " - keys: INTR={} QUIT={} ERASE={} KILL={} EOF={} TIME={} MIN={} ",
416 key(term
.c_cc
[VINTR
]),
417 key(term
.c_cc
[VQUIT
]),
418 key(term
.c_cc
[VERASE
]),
419 key(term
.c_cc
[VKILL
]),
420 key(term
.c_cc
[VEOF
]),
425 " START={} STOP={} SUSP={} EOL={} REPRINT={} DISCARD={}",
426 key(term
.c_cc
[VSTART
]),
427 key(term
.c_cc
[VSTOP
]),
428 key(term
.c_cc
[VSUSP
]),
429 key(term
.c_cc
[VEOL
]),
430 key(term
.c_cc
[VREPRINT
]),
431 key(term
.c_cc
[VDISCARD
])
434 " WERASE={} LNEXT={} EOL2={}",
435 key(term
.c_cc
[VWERASE
]),
436 key(term
.c_cc
[VLNEXT
]),
437 key(term
.c_cc
[VEOL2
])
441 println
!(" - is not a tty");
448 #[cfg(feature = "termios")]
450 fn key(b
: u8) -> String
{
454 format
!("^{}", (b
+ 0x40) as char)
455 } else if b
== 0x7f {
458 format
!("{}", b
as char)