Fix Goto
This commit is contained in:
parent
eb1c1e5907
commit
5634d5d082
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "termion"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
authors = ["Ticki <Ticki@users.noreply.github.com>"]
|
||||
description = "A bindless library for manipulating terminals."
|
||||
repository = "https://github.com/ticki/termion"
|
||||
|
|
|
@ -23,7 +23,7 @@ impl fmt::Display for Goto {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
debug_assert!(self != &Goto(0, 0), "Goto is one-based.");
|
||||
|
||||
write!(f, csi!("{};{}H"), self.0, self.1)
|
||||
write!(f, csi!("{};{}H"), self.1, self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
src/event.rs
11
src/event.rs
|
@ -118,8 +118,8 @@ where I: Iterator<Item = Result<u8, Error>>
|
|||
// X10 emulation mouse encoding: ESC [ CB Cx Cy (6 characters only).
|
||||
let cb = iter.next().unwrap().unwrap() as i8 - 32;
|
||||
// (1, 1) are the coords for upper left.
|
||||
let cy = (iter.next().unwrap().unwrap() as u8).saturating_sub(32) as u16;
|
||||
let cx = (iter.next().unwrap().unwrap() as u8).saturating_sub(32) as u16;
|
||||
let cy = (iter.next().unwrap().unwrap() as u8).saturating_sub(32) as u16;
|
||||
Event::Mouse(match cb & 0b11 {
|
||||
0 => {
|
||||
if cb & 0x40 != 0 {
|
||||
|
@ -156,8 +156,8 @@ where I: Iterator<Item = Result<u8, Error>>
|
|||
let ref mut nums = str_buf.split(';');
|
||||
|
||||
let cb = nums.next().unwrap().parse::<u16>().unwrap();
|
||||
let cy = nums.next().unwrap().parse::<u16>().unwrap();
|
||||
let cx = nums.next().unwrap().parse::<u16>().unwrap();
|
||||
let cy = nums.next().unwrap().parse::<u16>().unwrap();
|
||||
|
||||
let button = match cb {
|
||||
0 => MouseButton::Left,
|
||||
|
@ -195,8 +195,8 @@ where I: Iterator<Item = Result<u8, Error>>
|
|||
let ref mut nums = str_buf.split(';');
|
||||
|
||||
let cb = nums.next().unwrap().parse::<u16>().unwrap();
|
||||
let cy = nums.next().unwrap().parse::<u16>().unwrap() - 1;
|
||||
let cx = nums.next().unwrap().parse::<u16>().unwrap() - 1;
|
||||
let cx = nums.next().unwrap().parse::<u16>().unwrap();
|
||||
let cy = nums.next().unwrap().parse::<u16>().unwrap();
|
||||
|
||||
let event = match cb {
|
||||
32 => MouseEvent::Press(MouseButton::Left, cx, cy),
|
||||
|
@ -259,8 +259,7 @@ where I: Iterator<Item = Result<u8, Error>>
|
|||
|
||||
/// Parse `c` as either a single byte ASCII char or a variable size UTF-8 char.
|
||||
fn parse_utf8_char<I>(c: u8, iter: &mut I) -> Result<char, Error>
|
||||
where I: Iterator<Item = Result<u8, Error>>
|
||||
{
|
||||
where I: Iterator<Item = Result<u8, Error>> {
|
||||
let error = Err(Error::new(ErrorKind::Other, "Input character is not valid UTF-8"));
|
||||
if c.is_ascii() {
|
||||
Ok(c as char)
|
||||
|
|
10
src/input.rs
10
src/input.rs
|
@ -176,11 +176,11 @@ mod test {
|
|||
assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Char('c')));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Backspace));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Left));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::WheelUp, 4, 2)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::Left, 4, 2)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::Left, 3, 1)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Release(4, 2)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Release(3, 1)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::WheelUp, 2, 4)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::Left, 2, 4)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::Left, 2, 4)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Release(2, 4)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Release(2, 4)));
|
||||
assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Char('b')));
|
||||
assert!(i.next().is_none());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue