commit
5f8ce31797
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
|
/// A terminal restorer, which keeps the previous state of the terminal, and restores it, when
|
||||||
/// dropped.
|
/// dropped.
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
pub struct RawTerminal<W> {
|
pub struct RawTerminal<W: Write> {
|
||||||
output: W,
|
output: W,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
impl<W: Write> Drop for RawTerminal<W> {
|
impl<W: Write> Drop for RawTerminal<W> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
use TermControl;
|
use control::TermWrite;
|
||||||
self.csi(b"R");
|
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
|
/// A terminal restorer, which keeps the previous state of the terminal, and restores it, when
|
||||||
/// dropped.
|
/// dropped.
|
||||||
#[cfg(not(target_os = "redox"))]
|
#[cfg(not(target_os = "redox"))]
|
||||||
pub struct RawTerminal<W> {
|
pub struct RawTerminal<W: Write> {
|
||||||
prev_ios: Termios,
|
prev_ios: Termios,
|
||||||
output: W,
|
output: W,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "redox"))]
|
#[cfg(not(target_os = "redox"))]
|
||||||
impl<W> Drop for RawTerminal<W> {
|
impl<W: Write> Drop for RawTerminal<W> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
use termios::set_terminal_attr;
|
use termios::set_terminal_attr;
|
||||||
set_terminal_attr(&mut self.prev_ios as *mut _);
|
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;
|
type Target = W;
|
||||||
|
|
||||||
fn deref(&self) -> &W {
|
fn deref(&self) -> &W {
|
||||||
&self.output
|
&self.output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<W> DerefMut for RawTerminal<W> {
|
impl<W: Write> DerefMut for RawTerminal<W> {
|
||||||
fn deref_mut(&mut self) -> &mut W {
|
fn deref_mut(&mut self) -> &mut W {
|
||||||
&mut self.output
|
&mut self.output
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ impl<W: Write> Write for RawTerminal<W> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Types which can be converted into "raw mode".
|
/// Types which can be converted into "raw mode".
|
||||||
pub trait IntoRawMode: Sized {
|
pub trait IntoRawMode: Write + Sized {
|
||||||
/// Switch to raw mode.
|
/// Switch to raw mode.
|
||||||
///
|
///
|
||||||
/// Raw mode means that stdin won't be printed (it will instead have to be written manually by the
|
/// 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")]
|
#[cfg(target_os = "redox")]
|
||||||
fn into_raw_mode(self) -> IoResult<RawTerminal<W>> {
|
fn into_raw_mode(mut self) -> IoResult<RawTerminal<W>> {
|
||||||
use TermControl;
|
use control::TermWrite;
|
||||||
|
|
||||||
self.csi("r").map(|_| RawTerminal {
|
self.csi(b"r").map(|_| RawTerminal {
|
||||||
output: self,
|
output: self,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,13 @@ struct TermSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since attributes on non-item statements is not stable yet, we use a function.
|
// Since attributes on non-item statements is not stable yet, we use a function.
|
||||||
|
#[cfg(not(target_os = "redox"))]
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
fn tiocgwinsz() -> u64 {
|
fn tiocgwinsz() -> u64 {
|
||||||
use termios::TIOCGWINSZ;
|
use termios::TIOCGWINSZ;
|
||||||
TIOCGWINSZ as u64
|
TIOCGWINSZ as u64
|
||||||
}
|
}
|
||||||
|
#[cfg(not(target_os = "redox"))]
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
fn tiocgwinsz() -> u32 {
|
fn tiocgwinsz() -> u32 {
|
||||||
use termios::TIOCGWINSZ;
|
use termios::TIOCGWINSZ;
|
||||||
|
@ -46,6 +48,7 @@ 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)> {
|
||||||
|
/*
|
||||||
fn get_int(s: &'static str) -> io::Result<usize> {
|
fn get_int(s: &'static str) -> io::Result<usize> {
|
||||||
use std::env;
|
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((try!(get_int("COLUMNS")), try!(get_int("LINES"))))
|
||||||
|
*/
|
||||||
|
Ok((128,48))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue