From 43ecff5a013a314dfe77ce0c3dc21777caf71a07 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Sun, 18 Jun 2017 18:32:11 -0700 Subject: [PATCH] Redox OS support --- Cargo.toml | 3 +++ src/tty/mod.rs | 5 +++++ src/tty/redox.rs | 13 +++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 src/tty/redox.rs diff --git a/Cargo.toml b/Cargo.toml index 1f189dfb..6c388767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,8 @@ time = "0.1.35" winapi = "0.2" kernel32-sys = "0.2" +[target.'cfg(target_os = "redox")'.dependencies] +termion = "1.4" + [dev-dependencies] rand = "0.3.14" diff --git a/src/tty/mod.rs b/src/tty/mod.rs index 65470201..db9dfa55 100644 --- a/src/tty/mod.rs +++ b/src/tty/mod.rs @@ -21,3 +21,8 @@ pub use self::unix::*; mod windows; #[cfg(windows)] pub use self::windows::*; + +#[cfg(target_os = "redox")] +mod redox; +#[cfg(target_os = "redox")] +pub use self::redox::*; diff --git a/src/tty/redox.rs b/src/tty/redox.rs new file mode 100644 index 00000000..2f9bd8c2 --- /dev/null +++ b/src/tty/redox.rs @@ -0,0 +1,13 @@ +extern crate termion; +use super::{Width, Height}; + +pub fn terminal_size() -> Option<(Width, Height)> { + match termion::terminal_size() { + Ok((cols, rows)) => Some((Width(cols), Height(rows))), + Err(..) => None + } +} + +pub fn move_cursor_up(n: usize) -> String { + format!("{}", termion::cursor::Up(n as u16)) +}