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