Commit 8572ee6e authored by ticki's avatar ticki

Get the tty device, get_tty

parent 95bce609
[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;
......
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")
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment