Get the tty device, get_tty

This commit is contained in:
ticki 2016-07-29 19:49:29 +02:00
parent 95bce6092a
commit 8572ee6eb8
4 changed files with 20 additions and 2 deletions

View File

@ -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"

View File

@ -54,6 +54,7 @@ version of Termion.
- Cursor movement.
- Text formatting.
- Console size.
- TTY-only stream.
- Control sequences.
- Termios control.
- Password input.

View File

@ -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;

View File

@ -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")
}