Merge pull request #115 from redox-os/redox_termios
Implement size and is_tty with termios on Redox
This commit is contained in:
commit
994b0af79f
|
@ -11,3 +11,8 @@ exclude = ["target", "CHANGELOG.md", "image.png", "Cargo.lock"]
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "redox"))'.dependencies]
|
[target.'cfg(not(target_os = "redox"))'.dependencies]
|
||||||
libc = "0.2.8"
|
libc = "0.2.8"
|
||||||
|
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "redox")'.dependencies]
|
||||||
|
redox_syscall = "0.1"
|
||||||
|
redox_termios = "0.1"
|
||||||
|
|
|
@ -17,6 +17,12 @@ extern crate libc;
|
||||||
#[cfg(not(target_os = "redox"))]
|
#[cfg(not(target_os = "redox"))]
|
||||||
mod termios;
|
mod termios;
|
||||||
|
|
||||||
|
#[cfg(target_os = "redox")]
|
||||||
|
extern crate redox_termios;
|
||||||
|
|
||||||
|
#[cfg(target_os = "redox")]
|
||||||
|
extern crate syscall;
|
||||||
|
|
||||||
mod async;
|
mod async;
|
||||||
pub use async::{AsyncReader, async_stdin};
|
pub use async::{AsyncReader, async_stdin};
|
||||||
|
|
||||||
|
|
21
src/size.rs
21
src/size.rs
|
@ -57,16 +57,21 @@ pub fn terminal_size() -> io::Result<(u16, u16)> {
|
||||||
/// Get the size of the terminal.
|
/// Get the size of the terminal.
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
pub fn terminal_size() -> io::Result<(u16, u16)> {
|
pub fn terminal_size() -> io::Result<(u16, u16)> {
|
||||||
use std::env;
|
use redox_termios;
|
||||||
|
use syscall;
|
||||||
|
|
||||||
let width = try!(env::var("COLUMNS").map_err(|x| io::Error::new(io::ErrorKind::NotFound, x)))
|
if let Ok(fd) = syscall::dup(1, b"winsize") {
|
||||||
.parse()
|
let mut winsize = redox_termios::Winsize::default();
|
||||||
.unwrap_or(0);
|
let res = syscall::read(fd, &mut winsize);
|
||||||
let height = try!(env::var("LINES").map_err(|x| io::Error::new(io::ErrorKind::NotFound, x)))
|
let _ = syscall::close(fd);
|
||||||
.parse()
|
if let Ok(count) = res {
|
||||||
.unwrap_or(0);
|
if count == winsize.len() {
|
||||||
|
return Ok((winsize.ws_col, winsize.ws_row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok((width, height))
|
Err(io::Error::new(io::ErrorKind::Other, "Unable to get the terminal size."))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
11
src/tty.rs
11
src/tty.rs
|
@ -11,8 +11,15 @@ pub fn is_tty<T: AsRawFd>(stream: &T) -> bool {
|
||||||
|
|
||||||
/// This will panic.
|
/// This will panic.
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
pub fn is_tty<T: AsRawFd>(_stream: &T) -> bool {
|
pub fn is_tty<T: AsRawFd>(stream: &T) -> bool {
|
||||||
unimplemented!();
|
use syscall;
|
||||||
|
|
||||||
|
if let Ok(fd) = syscall::dup(stream.as_raw_fd(), b"termios") {
|
||||||
|
let _ = syscall::close(fd);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the TTY device.
|
/// Get the TTY device.
|
||||||
|
|
Loading…
Reference in New Issue