Get the tty device, get_tty
This commit is contained in:
parent
95bce6092a
commit
8572ee6eb8
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "termion"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
authors = ["Ticki <Ticki@users.noreply.github.com>"]
|
||||
description = "A bindless library for manipulating terminals."
|
||||
repository = "https://github.com/ticki/termion"
|
||||
|
|
|
@ -54,6 +54,7 @@ version of Termion.
|
|||
- Cursor movement.
|
||||
- Text formatting.
|
||||
- Console size.
|
||||
- TTY-only stream.
|
||||
- Control sequences.
|
||||
- Termios control.
|
||||
- Password input.
|
||||
|
|
|
@ -24,7 +24,7 @@ mod size;
|
|||
pub use size::terminal_size;
|
||||
|
||||
mod tty;
|
||||
pub use tty::is_tty;
|
||||
pub use tty::{is_tty, get_tty};
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
|
17
src/tty.rs
17
src/tty.rs
|
@ -1,3 +1,4 @@
|
|||
use std::{fs, io};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
/// Is this stream an TTY?
|
||||
|
@ -13,3 +14,19 @@ pub fn is_tty<T: AsRawFd>(stream: T) -> bool {
|
|||
pub fn is_tty<T: AsRawFd>(_stream: T) -> bool {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
/// Get the TTY device.
|
||||
///
|
||||
/// This allows for getting stdio representing _only_ the TTY, and not other streams.
|
||||
#[cfg(target_os = "redox")]
|
||||
pub fn get_tty() -> io::Result<fs::File> {
|
||||
fs::OpenOptions::new().read(true).write(true).open(env::var("TTY")?)
|
||||
}
|
||||
|
||||
/// Get the TTY device.
|
||||
///
|
||||
/// This allows for getting stdio representing _only_ the TTY, and not other streams.
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
pub fn get_tty() -> io::Result<fs::File> {
|
||||
fs::OpenOptions::new().read(true).write(true).open("/dev/tty")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue