Merge branch 'master' of github.com:Ticki/libterm

This commit is contained in:
ticki 2016-08-27 11:31:07 +02:00
commit ffd4953022
3 changed files with 8 additions and 9 deletions

View File

@ -153,7 +153,7 @@ where I: Iterator<Item = Result<u8, Error>>
c = iter.next().unwrap().unwrap(); c = iter.next().unwrap().unwrap();
} }
let str_buf = String::from_utf8(buf).unwrap(); let str_buf = String::from_utf8(buf).unwrap();
let ref mut nums = str_buf.split(';'); let nums = &mut str_buf.split(';');
let cb = nums.next().unwrap().parse::<u16>().unwrap(); let cb = nums.next().unwrap().parse::<u16>().unwrap();
let cx = nums.next().unwrap().parse::<u16>().unwrap(); let cx = nums.next().unwrap().parse::<u16>().unwrap();
@ -192,7 +192,7 @@ where I: Iterator<Item = Result<u8, Error>>
// ESC [ Cb ; Cx ; Cy ; M // ESC [ Cb ; Cx ; Cy ; M
b'M' => { b'M' => {
let str_buf = String::from_utf8(buf).unwrap(); let str_buf = String::from_utf8(buf).unwrap();
let ref mut nums = str_buf.split(';'); let nums = &mut str_buf.split(';');
let cb = nums.next().unwrap().parse::<u16>().unwrap(); let cb = nums.next().unwrap().parse::<u16>().unwrap();
let cx = nums.next().unwrap().parse::<u16>().unwrap(); let cx = nums.next().unwrap().parse::<u16>().unwrap();
@ -203,7 +203,7 @@ where I: Iterator<Item = Result<u8, Error>>
33 => MouseEvent::Press(MouseButton::Middle, cx, cy), 33 => MouseEvent::Press(MouseButton::Middle, cx, cy),
34 => MouseEvent::Press(MouseButton::Right, cx, cy), 34 => MouseEvent::Press(MouseButton::Right, cx, cy),
35 => MouseEvent::Release(cx, cy), 35 => MouseEvent::Release(cx, cy),
96 => MouseEvent::Press(MouseButton::WheelUp, cx, cy), 96 |
97 => MouseEvent::Press(MouseButton::WheelUp, cx, cy), 97 => MouseEvent::Press(MouseButton::WheelUp, cx, cy),
_ => return error, _ => return error,
}; };
@ -264,14 +264,13 @@ fn parse_utf8_char<I>(c: u8, iter: &mut I) -> Result<char, Error>
if c.is_ascii() { if c.is_ascii() {
Ok(c as char) Ok(c as char)
} else { } else {
let ref mut bytes = Vec::new(); let bytes = &mut Vec::new();
bytes.push(c); bytes.push(c);
loop { loop {
bytes.push(iter.next().unwrap().unwrap()); bytes.push(iter.next().unwrap().unwrap());
match str::from_utf8(bytes) { if let Ok(st) = str::from_utf8(bytes) {
Ok(st) => return Ok(st.chars().next().unwrap()), return Ok(st.chars().next().unwrap())
Err(_) => {},
} }
if bytes.len() >= 4 { return error; } if bytes.len() >= 4 { return error; }
} }

View File

@ -35,7 +35,7 @@ impl<I: Iterator<Item = Result<u8, io::Error>>> Iterator for Events<I> {
type Item = Result<Event, io::Error>; type Item = Result<Event, io::Error>;
fn next(&mut self) -> Option<Result<Event, io::Error>> { fn next(&mut self) -> Option<Result<Event, io::Error>> {
let ref mut iter = self.bytes; let iter = &mut self.bytes;
match iter.next() { match iter.next() {
Some(item) => Some(parse_event(item, iter).or(Ok(Event::Unsupported))), Some(item) => Some(parse_event(item, iter).or(Ok(Event::Unsupported))),
None => None, None => None,

View File

@ -75,7 +75,7 @@ impl<W: Write> IntoRawMode for W {
use termios::{cfmakeraw, get_terminal_attr, set_terminal_attr}; use termios::{cfmakeraw, get_terminal_attr, set_terminal_attr};
let (mut ios, exit) = get_terminal_attr(); let (mut ios, exit) = get_terminal_attr();
let prev_ios = ios.clone(); let prev_ios = ios;
if exit != 0 { if exit != 0 {
return Err(io::Error::new(io::ErrorKind::Other, "Unable to get Termios attribute.")); return Err(io::Error::new(io::ErrorKind::Other, "Unable to get Termios attribute."));
} }