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:
Timon 2019-04-17 16:24:58 +02:00 committed by GitHub
parent f468cf6a9a
commit b8d4255bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 52 additions and 25 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "crossterm"
version = "0.9.1"
version = "0.9.2"
authors = ["T. Post"]
description = "An crossplatform terminal library for manipulating terminals."
repository = "https://github.com/TimonPost/crossterm"
@ -34,9 +34,9 @@ members = [
[dependencies]
crossterm_screen = { 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_input = { optional = true, version = "0.3.1" }
crossterm_input = { optional = true, path = "./crossterm_input" }
crossterm_utils = { optional = false, version = "0.2.1" }
[lib]

View File

@ -70,6 +70,7 @@ pub fn pos() -> io::Result<(u16, u16)> {
// Expect `R`
let res = if c == 'R' {
// subtract one to get 0-based coords
Ok(((cols - 1) as u16, (rows - 1) as u16))
} else {
return Err(Error::new(ErrorKind::Other, "test"));

View File

@ -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
- Removed `TerminalInput::from_output()`

View File

@ -1,6 +1,6 @@
[package]
name = "crossterm_input"
version = "0.3.1"
version = "0.3.2"
authors = ["T. Post"]
description = "A cross-platform library for reading userinput."
repository = "https://github.com/TimonPost/crossterm"

View File

@ -113,11 +113,13 @@ impl Iterator for SyncReader {
// 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.
let mut buf = [0u8; 2];
let res = match source.read(&mut buf) {
Ok(0) => return None,
Ok(1) => match buf[0] {
b'\x1B' => return Some(InputEvent::Keyboard(KeyEvent::Esc)),
c => {
println!("size 1: {:?}", buf);
if let Ok(e) = parse_event(c, &mut source.bytes().flatten()) {
return Some(e);
} else {
@ -126,9 +128,10 @@ impl Iterator for SyncReader {
}
},
Ok(2) => {
println!("size 2: {:?}", buf);
let option_iter = &mut Some(buf[1]).into_iter();
let iter = option_iter.map(|c| Ok(c)).chain(source.bytes());
if let Ok(e) = parse_event(buf[0], &mut source.bytes().flatten()) {
let mut iter = option_iter.map(|c| Ok(c)).chain(source.bytes());
if let Ok(e) = parse_event(buf[0], &mut iter.flatten()) {
self.leftover = option_iter.next();
Some(e)
} else {

View File

@ -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
// mouse button is held down (ie. mouse drag)
let cxbs: Vec<u8> = event
.mouse_position
.x
let cxbs: Vec<u8> =
(event.mouse_position.x + 1) /* windows positions are 0 based and ansi codes 1. */
.to_string()
.chars()
.map(|d| d as u8)
.collect();
let cybs: Vec<u8> = event
.mouse_position
.y
let cybs: Vec<u8> =
(event.mouse_position.y + 1) /* windows positions are 0 based and ansi codes 1. */
.to_string()
.chars()
.map(|d| d as u8)

View File

@ -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
- Removed `Terminal:from_output()`

View File

@ -1,6 +1,6 @@
[package]
name = "crossterm_terminal"
version = "0.2.1"
version = "0.2.2"
authors = ["T. Post"]
description = "A cross-platform library for doing terminal related actions."
repository = "https://github.com/TimonPost/crossterm"

View File

@ -26,11 +26,11 @@ pub fn get_terminal_size() -> (u16, u16) {
ws_ypixel: 0,
};
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ, &us) };
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &us) };
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.
(us.cols, us.rows)
(us.cols - 1, us.rows - 1)
} else {
(0, 0)
}

View File

@ -165,7 +165,10 @@ impl Console {
}
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;
if !is_true(unsafe {

View File

@ -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.
- Major refactor and cleanup.

View File

@ -30,3 +30,4 @@ pub use self::crossterm_style::{
pub use self::crossterm_terminal::{terminal, ClearType, Terminal};
pub use self::crossterm::Crossterm;
pub use self::crossterm_utils::{ErrorKind, Result};