Merge branch 'master' of github.com:Ticki/libterm
This commit is contained in:
commit
12e08141c4
|
@ -29,7 +29,7 @@ fn main() {
|
|||
Key::Down => println!("↓"),
|
||||
Key::Backspace => println!("×"),
|
||||
Key::Invalid => println!("???"),
|
||||
Key::Error => println!("ERROR"),
|
||||
Key::Error(_) => println!("ERROR"),
|
||||
_ => {},
|
||||
}
|
||||
stdout.flush().unwrap();
|
||||
|
|
|
@ -11,7 +11,7 @@ pub trait TermWrite {
|
|||
fn csi(&mut self, b: &[u8]) -> io::Result<usize>;
|
||||
/// Print OSC (operating system command) followed by a byte string.
|
||||
fn osc(&mut self, b: &[u8]) -> io::Result<usize>;
|
||||
/// Print OSC (device control string) followed by a byte string.
|
||||
/// Print DSC (device control string) followed by a byte string.
|
||||
fn dsc(&mut self, b: &[u8]) -> io::Result<usize>;
|
||||
|
||||
|
||||
|
|
20
src/raw.rs
20
src/raw.rs
|
@ -4,14 +4,14 @@ use std::ops::{Deref, DerefMut};
|
|||
/// A terminal restorer, which keeps the previous state of the terminal, and restores it, when
|
||||
/// dropped.
|
||||
#[cfg(target_os = "redox")]
|
||||
pub struct RawTerminal<W> {
|
||||
pub struct RawTerminal<W: Write> {
|
||||
output: W,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
impl<W: Write> Drop for RawTerminal<W> {
|
||||
fn drop(&mut self) {
|
||||
use TermControl;
|
||||
use control::TermWrite;
|
||||
self.csi(b"R");
|
||||
}
|
||||
}
|
||||
|
@ -21,27 +21,27 @@ use termios::Termios;
|
|||
/// A terminal restorer, which keeps the previous state of the terminal, and restores it, when
|
||||
/// dropped.
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
pub struct RawTerminal<W> {
|
||||
pub struct RawTerminal<W: Write> {
|
||||
prev_ios: Termios,
|
||||
output: W,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
impl<W> Drop for RawTerminal<W> {
|
||||
impl<W: Write> Drop for RawTerminal<W> {
|
||||
fn drop(&mut self) {
|
||||
use termios::set_terminal_attr;
|
||||
set_terminal_attr(&mut self.prev_ios as *mut _);
|
||||
}
|
||||
}
|
||||
|
||||
impl<W> Deref for RawTerminal<W> {
|
||||
impl<W: Write> Deref for RawTerminal<W> {
|
||||
type Target = W;
|
||||
|
||||
fn deref(&self) -> &W {
|
||||
&self.output
|
||||
}
|
||||
}
|
||||
impl<W> DerefMut for RawTerminal<W> {
|
||||
impl<W: Write> DerefMut for RawTerminal<W> {
|
||||
fn deref_mut(&mut self) -> &mut W {
|
||||
&mut self.output
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ impl<W: Write> Write for RawTerminal<W> {
|
|||
}
|
||||
|
||||
/// Types which can be converted into "raw mode".
|
||||
pub trait IntoRawMode: Sized {
|
||||
pub trait IntoRawMode: Write + Sized {
|
||||
/// Switch to raw mode.
|
||||
///
|
||||
/// Raw mode means that stdin won't be printed (it will instead have to be written manually by the
|
||||
|
@ -92,10 +92,10 @@ impl<W: Write> IntoRawMode for W {
|
|||
}
|
||||
}
|
||||
#[cfg(target_os = "redox")]
|
||||
fn into_raw_mode(self) -> IoResult<RawTerminal<W>> {
|
||||
use TermControl;
|
||||
fn into_raw_mode(mut self) -> IoResult<RawTerminal<W>> {
|
||||
use control::TermWrite;
|
||||
|
||||
self.csi("r").map(|_| RawTerminal {
|
||||
self.csi(b"r").map(|_| RawTerminal {
|
||||
output: self,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,11 +13,13 @@ struct TermSize {
|
|||
}
|
||||
|
||||
// Since attributes on non-item statements is not stable yet, we use a function.
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
fn tiocgwinsz() -> u64 {
|
||||
use termios::TIOCGWINSZ;
|
||||
TIOCGWINSZ as u64
|
||||
}
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
fn tiocgwinsz() -> u32 {
|
||||
use termios::TIOCGWINSZ;
|
||||
|
@ -46,6 +48,7 @@ pub fn terminal_size() -> io::Result<(usize, usize)> {
|
|||
/// Get the size of the terminal.
|
||||
#[cfg(target_os = "redox")]
|
||||
pub fn terminal_size() -> io::Result<(usize, usize)> {
|
||||
/*
|
||||
fn get_int(s: &'static str) -> io::Result<usize> {
|
||||
use std::env;
|
||||
|
||||
|
@ -58,6 +61,8 @@ pub fn terminal_size() -> io::Result<(usize, usize)> {
|
|||
}
|
||||
|
||||
Ok((try!(get_int("COLUMNS")), try!(get_int("LINES"))))
|
||||
*/
|
||||
Ok((128,48))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in New Issue