1b8a62b91Sopenharmony_ciuse crate::fd::AsFd; 2b8a62b91Sopenharmony_ciuse crate::process::Pid; 3b8a62b91Sopenharmony_ciuse crate::{backend, io}; 4b8a62b91Sopenharmony_ci 5b8a62b91Sopenharmony_cipub use backend::termios::types::{ 6b8a62b91Sopenharmony_ci Action, OptionalActions, QueueSelector, Speed, Tcflag, Termios, Winsize, 7b8a62b91Sopenharmony_ci}; 8b8a62b91Sopenharmony_ci 9b8a62b91Sopenharmony_ci/// `tcgetattr(fd)`—Get terminal attributes. 10b8a62b91Sopenharmony_ci/// 11b8a62b91Sopenharmony_ci/// Also known as the `TCGETS` operation with `ioctl`. 12b8a62b91Sopenharmony_ci/// 13b8a62b91Sopenharmony_ci/// # References 14b8a62b91Sopenharmony_ci/// - [POSIX `tcgetattr`] 15b8a62b91Sopenharmony_ci/// - [Linux `ioctl_tty`] 16b8a62b91Sopenharmony_ci/// - [Linux `termios`] 17b8a62b91Sopenharmony_ci/// 18b8a62b91Sopenharmony_ci/// [POSIX `tcgetattr`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetattr.html 19b8a62b91Sopenharmony_ci/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 20b8a62b91Sopenharmony_ci/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html 21b8a62b91Sopenharmony_ci#[cfg(not(any(windows, target_os = "wasi")))] 22b8a62b91Sopenharmony_ci#[inline] 23b8a62b91Sopenharmony_ci#[doc(alias = "TCGETS")] 24b8a62b91Sopenharmony_cipub fn tcgetattr<Fd: AsFd>(fd: Fd) -> io::Result<Termios> { 25b8a62b91Sopenharmony_ci backend::termios::syscalls::tcgetattr(fd.as_fd()) 26b8a62b91Sopenharmony_ci} 27b8a62b91Sopenharmony_ci 28b8a62b91Sopenharmony_ci/// `tcgetwinsize(fd)`—Get the current terminal window size. 29b8a62b91Sopenharmony_ci/// 30b8a62b91Sopenharmony_ci/// Also known as the `TIOCGWINSZ` operation with `ioctl`. 31b8a62b91Sopenharmony_ci/// 32b8a62b91Sopenharmony_ci/// # References 33b8a62b91Sopenharmony_ci/// - [Linux] 34b8a62b91Sopenharmony_ci/// 35b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 36b8a62b91Sopenharmony_ci#[cfg(not(any(windows, target_os = "wasi")))] 37b8a62b91Sopenharmony_ci#[inline] 38b8a62b91Sopenharmony_ci#[doc(alias = "TIOCGWINSZ")] 39b8a62b91Sopenharmony_cipub fn tcgetwinsize<Fd: AsFd>(fd: Fd) -> io::Result<Winsize> { 40b8a62b91Sopenharmony_ci backend::termios::syscalls::tcgetwinsize(fd.as_fd()) 41b8a62b91Sopenharmony_ci} 42b8a62b91Sopenharmony_ci 43b8a62b91Sopenharmony_ci/// `tcgetpgrp(fd)`—Get the terminal foreground process group. 44b8a62b91Sopenharmony_ci/// 45b8a62b91Sopenharmony_ci/// Also known as the `TIOCGPGRP` operation with `ioctl`. 46b8a62b91Sopenharmony_ci/// 47b8a62b91Sopenharmony_ci/// # References 48b8a62b91Sopenharmony_ci/// - [POSIX] 49b8a62b91Sopenharmony_ci/// - [Linux] 50b8a62b91Sopenharmony_ci/// 51b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetpgrp.html 52b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man3/tcgetpgrp.3.html 53b8a62b91Sopenharmony_ci#[cfg(not(any(windows, target_os = "wasi")))] 54b8a62b91Sopenharmony_ci#[inline] 55b8a62b91Sopenharmony_ci#[doc(alias = "TIOCGPGRP")] 56b8a62b91Sopenharmony_cipub fn tcgetpgrp<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { 57b8a62b91Sopenharmony_ci backend::termios::syscalls::tcgetpgrp(fd.as_fd()) 58b8a62b91Sopenharmony_ci} 59b8a62b91Sopenharmony_ci 60b8a62b91Sopenharmony_ci/// `tcsetpgrp(fd, pid)`—Set the terminal foreground process group. 61b8a62b91Sopenharmony_ci/// 62b8a62b91Sopenharmony_ci/// Also known as the `TIOCSPGRP` operation with `ioctl`. 63b8a62b91Sopenharmony_ci/// 64b8a62b91Sopenharmony_ci/// # References 65b8a62b91Sopenharmony_ci/// - [POSIX] 66b8a62b91Sopenharmony_ci/// - [Linux] 67b8a62b91Sopenharmony_ci/// 68b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetpgrp.html 69b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man3/tcsetpgrp.3.html 70b8a62b91Sopenharmony_ci#[cfg(not(any(windows, target_os = "wasi")))] 71b8a62b91Sopenharmony_ci#[inline] 72b8a62b91Sopenharmony_ci#[doc(alias = "TIOCSPGRP")] 73b8a62b91Sopenharmony_cipub fn tcsetpgrp<Fd: AsFd>(fd: Fd, pid: Pid) -> io::Result<()> { 74b8a62b91Sopenharmony_ci backend::termios::syscalls::tcsetpgrp(fd.as_fd(), pid) 75b8a62b91Sopenharmony_ci} 76b8a62b91Sopenharmony_ci 77b8a62b91Sopenharmony_ci/// `tcsetattr(fd)`—Set terminal attributes. 78b8a62b91Sopenharmony_ci/// 79b8a62b91Sopenharmony_ci/// Also known as the `TCSETS` operation with `ioctl`. 80b8a62b91Sopenharmony_ci/// 81b8a62b91Sopenharmony_ci/// # References 82b8a62b91Sopenharmony_ci/// - [POSIX `tcsetattr`] 83b8a62b91Sopenharmony_ci/// - [Linux `ioctl_tty`] 84b8a62b91Sopenharmony_ci/// - [Linux `termios`] 85b8a62b91Sopenharmony_ci/// 86b8a62b91Sopenharmony_ci/// [POSIX `tcsetattr`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetattr.html 87b8a62b91Sopenharmony_ci/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 88b8a62b91Sopenharmony_ci/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html 89b8a62b91Sopenharmony_ci#[inline] 90b8a62b91Sopenharmony_ci#[doc(alias = "TCSETS")] 91b8a62b91Sopenharmony_cipub fn tcsetattr<Fd: AsFd>( 92b8a62b91Sopenharmony_ci fd: Fd, 93b8a62b91Sopenharmony_ci optional_actions: OptionalActions, 94b8a62b91Sopenharmony_ci termios: &Termios, 95b8a62b91Sopenharmony_ci) -> io::Result<()> { 96b8a62b91Sopenharmony_ci backend::termios::syscalls::tcsetattr(fd.as_fd(), optional_actions, termios) 97b8a62b91Sopenharmony_ci} 98b8a62b91Sopenharmony_ci 99b8a62b91Sopenharmony_ci/// `tcsendbreak(fd, 0)`—Transmit zero-valued bits. 100b8a62b91Sopenharmony_ci/// 101b8a62b91Sopenharmony_ci/// Also known as the `TCSBRK` operation with `ioctl`, with a duration of 0. 102b8a62b91Sopenharmony_ci/// 103b8a62b91Sopenharmony_ci/// This function always uses an effective duration parameter of zero. For the 104b8a62b91Sopenharmony_ci/// equivalent of a `tcsendbreak` with a non-zero duration parameter, use 105b8a62b91Sopenharmony_ci/// `tcdrain`. 106b8a62b91Sopenharmony_ci/// 107b8a62b91Sopenharmony_ci/// # References 108b8a62b91Sopenharmony_ci/// - [POSIX `tcsendbreak`] 109b8a62b91Sopenharmony_ci/// - [Linux `ioctl_tty`] 110b8a62b91Sopenharmony_ci/// - [Linux `termios`] 111b8a62b91Sopenharmony_ci/// 112b8a62b91Sopenharmony_ci/// [POSIX `tcsendbreak`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsendbreak.html 113b8a62b91Sopenharmony_ci/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 114b8a62b91Sopenharmony_ci/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html 115b8a62b91Sopenharmony_ci#[inline] 116b8a62b91Sopenharmony_ci#[doc(alias = "TCSBRK")] 117b8a62b91Sopenharmony_cipub fn tcsendbreak<Fd: AsFd>(fd: Fd) -> io::Result<()> { 118b8a62b91Sopenharmony_ci backend::termios::syscalls::tcsendbreak(fd.as_fd()) 119b8a62b91Sopenharmony_ci} 120b8a62b91Sopenharmony_ci 121b8a62b91Sopenharmony_ci/// `tcdrain(fd, duration)`—Wait until all pending output has been written. 122b8a62b91Sopenharmony_ci/// 123b8a62b91Sopenharmony_ci/// # References 124b8a62b91Sopenharmony_ci/// - [POSIX `tcdrain`] 125b8a62b91Sopenharmony_ci/// - [Linux `ioctl_tty`] 126b8a62b91Sopenharmony_ci/// - [Linux `termios`] 127b8a62b91Sopenharmony_ci/// 128b8a62b91Sopenharmony_ci/// [POSIX `tcsetattr`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcdrain.html 129b8a62b91Sopenharmony_ci/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 130b8a62b91Sopenharmony_ci/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html 131b8a62b91Sopenharmony_ci#[inline] 132b8a62b91Sopenharmony_cipub fn tcdrain<Fd: AsFd>(fd: Fd) -> io::Result<()> { 133b8a62b91Sopenharmony_ci backend::termios::syscalls::tcdrain(fd.as_fd()) 134b8a62b91Sopenharmony_ci} 135b8a62b91Sopenharmony_ci 136b8a62b91Sopenharmony_ci/// `tcflush(fd, queue_selector)`—Wait until all pending output has been 137b8a62b91Sopenharmony_ci/// written. 138b8a62b91Sopenharmony_ci/// 139b8a62b91Sopenharmony_ci/// # References 140b8a62b91Sopenharmony_ci/// - [POSIX `tcflush`] 141b8a62b91Sopenharmony_ci/// - [Linux `ioctl_tty`] 142b8a62b91Sopenharmony_ci/// - [Linux `termios`] 143b8a62b91Sopenharmony_ci/// 144b8a62b91Sopenharmony_ci/// [POSIX `tcflush`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcflush.html 145b8a62b91Sopenharmony_ci/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 146b8a62b91Sopenharmony_ci/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html 147b8a62b91Sopenharmony_ci#[inline] 148b8a62b91Sopenharmony_ci#[doc(alias = "TCFLSH")] 149b8a62b91Sopenharmony_cipub fn tcflush<Fd: AsFd>(fd: Fd, queue_selector: QueueSelector) -> io::Result<()> { 150b8a62b91Sopenharmony_ci backend::termios::syscalls::tcflush(fd.as_fd(), queue_selector) 151b8a62b91Sopenharmony_ci} 152b8a62b91Sopenharmony_ci 153b8a62b91Sopenharmony_ci/// `tcflow(fd, action)`—Suspend or resume transmission or reception. 154b8a62b91Sopenharmony_ci/// 155b8a62b91Sopenharmony_ci/// # References 156b8a62b91Sopenharmony_ci/// - [POSIX `tcflow`] 157b8a62b91Sopenharmony_ci/// - [Linux `ioctl_tty`] 158b8a62b91Sopenharmony_ci/// - [Linux `termios`] 159b8a62b91Sopenharmony_ci/// 160b8a62b91Sopenharmony_ci/// [POSIX `tcflow`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcflow.html 161b8a62b91Sopenharmony_ci/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 162b8a62b91Sopenharmony_ci/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html 163b8a62b91Sopenharmony_ci#[inline] 164b8a62b91Sopenharmony_ci#[doc(alias = "TCXONC")] 165b8a62b91Sopenharmony_cipub fn tcflow<Fd: AsFd>(fd: Fd, action: Action) -> io::Result<()> { 166b8a62b91Sopenharmony_ci backend::termios::syscalls::tcflow(fd.as_fd(), action) 167b8a62b91Sopenharmony_ci} 168b8a62b91Sopenharmony_ci 169b8a62b91Sopenharmony_ci/// `tcgetsid(fd)`—Return the session ID of the current session with `fd` as 170b8a62b91Sopenharmony_ci/// its controlling terminal. 171b8a62b91Sopenharmony_ci/// 172b8a62b91Sopenharmony_ci/// # References 173b8a62b91Sopenharmony_ci/// - [POSIX] 174b8a62b91Sopenharmony_ci/// - [Linux] 175b8a62b91Sopenharmony_ci/// 176b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetsid.html 177b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man3/tcgetsid.3.html 178b8a62b91Sopenharmony_ci#[inline] 179b8a62b91Sopenharmony_ci#[doc(alias = "TIOCGSID")] 180b8a62b91Sopenharmony_cipub fn tcgetsid<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { 181b8a62b91Sopenharmony_ci backend::termios::syscalls::tcgetsid(fd.as_fd()) 182b8a62b91Sopenharmony_ci} 183b8a62b91Sopenharmony_ci 184b8a62b91Sopenharmony_ci/// `tcsetwinsize(fd)`—Set the current terminal window size. 185b8a62b91Sopenharmony_ci/// 186b8a62b91Sopenharmony_ci/// Also known as the `TIOCSWINSZ` operation with `ioctl`. 187b8a62b91Sopenharmony_ci/// 188b8a62b91Sopenharmony_ci/// # References 189b8a62b91Sopenharmony_ci/// - [Linux] 190b8a62b91Sopenharmony_ci/// 191b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html 192b8a62b91Sopenharmony_ci#[inline] 193b8a62b91Sopenharmony_ci#[doc(alias = "TIOCSWINSZ")] 194b8a62b91Sopenharmony_cipub fn tcsetwinsize<Fd: AsFd>(fd: Fd, winsize: Winsize) -> io::Result<()> { 195b8a62b91Sopenharmony_ci backend::termios::syscalls::tcsetwinsize(fd.as_fd(), winsize) 196b8a62b91Sopenharmony_ci} 197