Use env for terminal size in redox

Undo color changes to test redox 256 color support

Get terminal size for Redox's kernel terminal

Use env for terminal size in redox
This commit is contained in:
Jeremy Soller 2016-03-17 11:27:03 -06:00 committed by Ticki
parent cd59514615
commit f5936c0035
3 changed files with 26 additions and 56 deletions

View File

@ -96,49 +96,32 @@ pub trait TermWrite {
/// Set foreground color. /// Set foreground color.
fn color(&mut self, color: Color) -> io::Result<usize> { fn color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val(); let ansi = color.to_ansi_val();
if ansi <= 7 { self.csi(&[
self.csi(&[ b'3',
b'3', b'8',
b'0' + ansi, b';',
b'm', b'5',
]) b';',
} else { b'0' + ansi / 100,
self.csi(&[ b'0' + ansi / 10 % 10,
b'3', b'0' + ansi % 10,
b'8', b'm',
b';', ])
b'5',
b';',
b'0' + ansi / 100,
b'0' + ansi / 10 % 10,
b'0' + ansi % 10,
b'm',
])
}
} }
/// Set background color. /// Set background color.
fn bg_color(&mut self, color: Color) -> io::Result<usize> { fn bg_color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val(); let ansi = color.to_ansi_val();
self.csi(&[
if ansi <= 7 { b'4',
self.csi(&[ b'8',
b'4', b';',
b'0' + ansi, b'5',
b'm', b';',
]) b'0' + ansi / 100,
} else { b'0' + ansi / 10 % 10,
self.csi(&[ b'0' + ansi % 10,
b'4', b'm',
b'8', ])
b';',
b'5',
b';',
b'0' + ansi / 100,
b'0' + ansi / 10 % 10,
b'0' + ansi % 10,
b'm',
])
}
} }
/// Set rendition mode (SGR). /// Set rendition mode (SGR).
fn style(&mut self, mode: Style) -> io::Result<usize> { fn style(&mut self, mode: Style) -> io::Result<usize> {

View File

@ -3,10 +3,6 @@
//! This crate is not stable, yet. However, if you do want stability, you should specify the //! This crate is not stable, yet. However, if you do want stability, you should specify the
//! revision (commit hash) in your `Cargo.toml`, this way builds are complete reproducible, and won't //! revision (commit hash) in your `Cargo.toml`, this way builds are complete reproducible, and won't
//! break. //! break.
#![cfg_attr(feature = "nightly",
feature(io))]
#![warn(missing_docs)] #![warn(missing_docs)]

View File

@ -48,21 +48,12 @@ pub fn terminal_size() -> io::Result<(usize, usize)> {
/// 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<(usize, usize)> { pub fn terminal_size() -> io::Result<(usize, usize)> {
/* use std::env;
fn get_int(s: &'static str) -> io::Result<usize> {
use std::env;
env::var(s).map_err(|e| match e { let width = env::var("COLUMNS").unwrap_or(String::new()).parse::<usize>().unwrap_or(0);
env::VarError::NotPresent => io::Error::new(io::ErrorKind::NotFound, e), let height = env::var("LINES").unwrap_or(String::new()).parse::<usize>().unwrap_or(0);
env::VarError::NotUnicode(u) => io::Error::new(io::ErrorKind::InvalidData, u),
}).and_then(|x| {
x.parse().map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
})
}
Ok((try!(get_int("COLUMNS")), try!(get_int("LINES")))) Ok((width, height))
*/
Ok((128,48))
} }
#[cfg(test)] #[cfg(test)]