Get the tty device, get_tty
This commit is contained in:
parent
95bce6092a
commit
8572ee6eb8
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "termion"
|
name = "termion"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
authors = ["Ticki <Ticki@users.noreply.github.com>"]
|
authors = ["Ticki <Ticki@users.noreply.github.com>"]
|
||||||
description = "A bindless library for manipulating terminals."
|
description = "A bindless library for manipulating terminals."
|
||||||
repository = "https://github.com/ticki/termion"
|
repository = "https://github.com/ticki/termion"
|
||||||
|
|
|
@ -54,6 +54,7 @@ version of Termion.
|
||||||
- Cursor movement.
|
- Cursor movement.
|
||||||
- Text formatting.
|
- Text formatting.
|
||||||
- Console size.
|
- Console size.
|
||||||
|
- TTY-only stream.
|
||||||
- Control sequences.
|
- Control sequences.
|
||||||
- Termios control.
|
- Termios control.
|
||||||
- Password input.
|
- Password input.
|
||||||
|
|
|
@ -24,7 +24,7 @@ mod size;
|
||||||
pub use size::terminal_size;
|
pub use size::terminal_size;
|
||||||
|
|
||||||
mod tty;
|
mod tty;
|
||||||
pub use tty::is_tty;
|
pub use tty::{is_tty, get_tty};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
17
src/tty.rs
17
src/tty.rs
|
@ -1,3 +1,4 @@
|
||||||
|
use std::{fs, io};
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
|
|
||||||
/// Is this stream an TTY?
|
/// 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 {
|
pub fn is_tty<T: AsRawFd>(_stream: T) -> bool {
|
||||||
unimplemented!();
|
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