Fixed some Bugs. (#118)
- Terminal size Linux was not 0-based. - Windows mouse input event position was 0-based and should be 1-based - Result, ErrorKind are made re-exported - Fixed some special key combination detections for UNIX systems - Made FreeBSD compile.
This commit is contained in:
parent
f468cf6a9a
commit
b8d4255bac
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "crossterm"
|
name = "crossterm"
|
||||||
version = "0.9.1"
|
version = "0.9.2"
|
||||||
authors = ["T. Post"]
|
authors = ["T. Post"]
|
||||||
description = "An crossplatform terminal library for manipulating terminals."
|
description = "An crossplatform terminal library for manipulating terminals."
|
||||||
repository = "https://github.com/TimonPost/crossterm"
|
repository = "https://github.com/TimonPost/crossterm"
|
||||||
@ -34,9 +34,9 @@ members = [
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm_screen = { optional = true, version = "0.2.1" }
|
crossterm_screen = { optional = true, version = "0.2.1" }
|
||||||
crossterm_cursor = { optional = true, version = "0.2.1" }
|
crossterm_cursor = { optional = true, version = "0.2.1" }
|
||||||
crossterm_terminal = { optional = true, version = "0.2.1" }
|
crossterm_terminal = { optional = true, path = "./crossterm_terminal" }
|
||||||
crossterm_style = { optional = true, version = "0.3.1" }
|
crossterm_style = { optional = true, version = "0.3.1" }
|
||||||
crossterm_input = { optional = true, version = "0.3.1" }
|
crossterm_input = { optional = true, path = "./crossterm_input" }
|
||||||
crossterm_utils = { optional = false, version = "0.2.1" }
|
crossterm_utils = { optional = false, version = "0.2.1" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -70,6 +70,7 @@ pub fn pos() -> io::Result<(u16, u16)> {
|
|||||||
|
|
||||||
// Expect `R`
|
// Expect `R`
|
||||||
let res = if c == 'R' {
|
let res = if c == 'R' {
|
||||||
|
// subtract one to get 0-based coords
|
||||||
Ok(((cols - 1) as u16, (rows - 1) as u16))
|
Ok(((cols - 1) as u16, (rows - 1) as u16))
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::new(ErrorKind::Other, "test"));
|
return Err(Error::new(ErrorKind::Other, "test"));
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
# Changes crossterm_input 0.3.2
|
||||||
|
- Fixed some special key combination detections for UNIX systems
|
||||||
|
- Windows mouse input event position was 0-based and should be 1-based
|
||||||
|
|
||||||
|
# Changes crossterm_input 0.3.1
|
||||||
|
- Updated crossterm_utils
|
||||||
|
|
||||||
# Changes crossterm_input 0.3
|
# Changes crossterm_input 0.3
|
||||||
- Removed `TerminalInput::from_output()`
|
- Removed `TerminalInput::from_output()`
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "crossterm_input"
|
name = "crossterm_input"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
authors = ["T. Post"]
|
authors = ["T. Post"]
|
||||||
description = "A cross-platform library for reading userinput."
|
description = "A cross-platform library for reading userinput."
|
||||||
repository = "https://github.com/TimonPost/crossterm"
|
repository = "https://github.com/TimonPost/crossterm"
|
||||||
|
@ -113,11 +113,13 @@ impl Iterator for SyncReader {
|
|||||||
// an escape sequence, we will read multiple bytes (the first byte being ESC) but if this
|
// an escape sequence, we will read multiple bytes (the first byte being ESC) but if this
|
||||||
// is a single ESC keypress, we will only read a single byte.
|
// is a single ESC keypress, we will only read a single byte.
|
||||||
let mut buf = [0u8; 2];
|
let mut buf = [0u8; 2];
|
||||||
|
|
||||||
let res = match source.read(&mut buf) {
|
let res = match source.read(&mut buf) {
|
||||||
Ok(0) => return None,
|
Ok(0) => return None,
|
||||||
Ok(1) => match buf[0] {
|
Ok(1) => match buf[0] {
|
||||||
b'\x1B' => return Some(InputEvent::Keyboard(KeyEvent::Esc)),
|
b'\x1B' => return Some(InputEvent::Keyboard(KeyEvent::Esc)),
|
||||||
c => {
|
c => {
|
||||||
|
println!("size 1: {:?}", buf);
|
||||||
if let Ok(e) = parse_event(c, &mut source.bytes().flatten()) {
|
if let Ok(e) = parse_event(c, &mut source.bytes().flatten()) {
|
||||||
return Some(e);
|
return Some(e);
|
||||||
} else {
|
} else {
|
||||||
@ -126,9 +128,10 @@ impl Iterator for SyncReader {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(2) => {
|
Ok(2) => {
|
||||||
|
println!("size 2: {:?}", buf);
|
||||||
let option_iter = &mut Some(buf[1]).into_iter();
|
let option_iter = &mut Some(buf[1]).into_iter();
|
||||||
let iter = option_iter.map(|c| Ok(c)).chain(source.bytes());
|
let mut iter = option_iter.map(|c| Ok(c)).chain(source.bytes());
|
||||||
if let Ok(e) = parse_event(buf[0], &mut source.bytes().flatten()) {
|
if let Ok(e) = parse_event(buf[0], &mut iter.flatten()) {
|
||||||
self.leftover = option_iter.next();
|
self.leftover = option_iter.next();
|
||||||
Some(e)
|
Some(e)
|
||||||
} else {
|
} else {
|
||||||
|
@ -291,16 +291,14 @@ fn handle_mouse_event(event: &MouseEvent, seq: &mut Vec<u8>) {
|
|||||||
// mimicks the behavior; additionally, in xterm, mouse move is only handled when a
|
// mimicks the behavior; additionally, in xterm, mouse move is only handled when a
|
||||||
// mouse button is held down (ie. mouse drag)
|
// mouse button is held down (ie. mouse drag)
|
||||||
|
|
||||||
let cxbs: Vec<u8> = event
|
let cxbs: Vec<u8> =
|
||||||
.mouse_position
|
(event.mouse_position.x + 1) /* windows positions are 0 based and ansi codes 1. */
|
||||||
.x
|
|
||||||
.to_string()
|
.to_string()
|
||||||
.chars()
|
.chars()
|
||||||
.map(|d| d as u8)
|
.map(|d| d as u8)
|
||||||
.collect();
|
.collect();
|
||||||
let cybs: Vec<u8> = event
|
let cybs: Vec<u8> =
|
||||||
.mouse_position
|
(event.mouse_position.y + 1) /* windows positions are 0 based and ansi codes 1. */
|
||||||
.y
|
|
||||||
.to_string()
|
.to_string()
|
||||||
.chars()
|
.chars()
|
||||||
.map(|d| d as u8)
|
.map(|d| d as u8)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# Changes crossterm_style 0.2.2
|
||||||
|
- Terminal size Linux was not 0-based.
|
||||||
|
- Made FreeBSD compile
|
||||||
|
|
||||||
# Changes crossterm_style 0.2
|
# Changes crossterm_style 0.2
|
||||||
- Removed `Terminal:from_output()`
|
- Removed `Terminal:from_output()`
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "crossterm_terminal"
|
name = "crossterm_terminal"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
authors = ["T. Post"]
|
authors = ["T. Post"]
|
||||||
description = "A cross-platform library for doing terminal related actions."
|
description = "A cross-platform library for doing terminal related actions."
|
||||||
repository = "https://github.com/TimonPost/crossterm"
|
repository = "https://github.com/TimonPost/crossterm"
|
||||||
|
@ -26,11 +26,11 @@ pub fn get_terminal_size() -> (u16, u16) {
|
|||||||
ws_ypixel: 0,
|
ws_ypixel: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ, &us) };
|
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &us) };
|
||||||
|
|
||||||
if r == 0 {
|
if r == 0 {
|
||||||
// because crossterm works starts counting at 0 and unix terminal starts at cell 1 you have subtract one to get 0-based results.
|
// because crossterm works starts counting at 0 and unix terminal starts at cell 1 you have subtract one to get 0-based results.
|
||||||
(us.cols, us.rows)
|
(us.cols - 1, us.rows - 1)
|
||||||
} else {
|
} else {
|
||||||
(0, 0)
|
(0, 0)
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,10 @@ impl Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_console_input(&self) -> Result<(u32, Vec<InputRecord>)> {
|
pub fn read_console_input(&self) -> Result<(u32, Vec<InputRecord>)> {
|
||||||
let mut buf: [INPUT_RECORD; 0x1000] = unsafe { zeroed() };
|
// Large buffers can overflow max heap size (?) and lead to errno 8
|
||||||
|
// "Not enough storage is available to process this command."
|
||||||
|
// It can be reproduced at Windows 7 i686 with `0x1000` buffer size.
|
||||||
|
let mut buf: [INPUT_RECORD; 0x800] = unsafe { zeroed() };
|
||||||
let mut size = 0;
|
let mut size = 0;
|
||||||
|
|
||||||
if !is_true(unsafe {
|
if !is_true(unsafe {
|
||||||
|
@ -1,4 +1,14 @@
|
|||||||
## Changes crossterm 0.9.0
|
## Changes crossterm 0.9.2
|
||||||
|
- Terminal size linux was not 0-based
|
||||||
|
- Windows mouse input event position was 0-based ans should be 1-based
|
||||||
|
- Result, ErrorKind are made re-exported
|
||||||
|
- Fixed some special key combination detections for UNIX systems
|
||||||
|
- Made FreeBSD compile
|
||||||
|
|
||||||
|
## Changes crossterm 0.9.1
|
||||||
|
- Fixed libc compile error
|
||||||
|
|
||||||
|
## Changes crossterm 0.9.0 (yanked)
|
||||||
This release is all about moving to a stabilized API for 1.0.
|
This release is all about moving to a stabilized API for 1.0.
|
||||||
|
|
||||||
- Major refactor and cleanup.
|
- Major refactor and cleanup.
|
||||||
|
@ -30,3 +30,4 @@ pub use self::crossterm_style::{
|
|||||||
pub use self::crossterm_terminal::{terminal, ClearType, Terminal};
|
pub use self::crossterm_terminal::{terminal, ClearType, Terminal};
|
||||||
|
|
||||||
pub use self::crossterm::Crossterm;
|
pub use self::crossterm::Crossterm;
|
||||||
|
pub use self::crossterm_utils::{ErrorKind, Result};
|
||||||
|
Loading…
Reference in New Issue
Block a user