Skip to content

Commit 9a50fd2

Browse files
authored
0.23 (#627)
1 parent 979245d commit 9a50fd2

File tree

6 files changed

+55
-44
lines changed

6 files changed

+55
-44
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Version 0.23
2+
- Update dependencies.
3+
- Add 0 check for all cursor functions to prevent undefined behaviour.
4+
- Add CSIu key parsing for unix.
5+
- Improve control character window key parsing supporting (e.g. CTRL [ and ])
6+
- Update library to 2021 edition.
7+
18
# Version 0.22.1
29
- Update yanked version crossterm-winapi and move to crossterm-winapi 0.9.0.
310
- Changed panic to error when calling disable-mouse capture without setting it first.

Cargo.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crossterm"
3-
version = "0.22.1"
3+
version = "0.23.0"
44
authors = ["T. Post"]
55
description = "A crossplatform terminal library for manipulating terminals."
66
repository = "https://github.com/crossterm-rs/crossterm"
@@ -9,7 +9,7 @@ license = "MIT"
99
keywords = ["event", "color", "cli", "input", "terminal"]
1010
exclude = ["target", "Cargo.lock"]
1111
readme = "README.md"
12-
edition = "2018"
12+
edition = "2021"
1313
categories = ["command-line-interface", "command-line-utilities"]
1414

1515
[lib]
@@ -34,7 +34,7 @@ event-stream = ["futures-core"]
3434
#
3535
[dependencies]
3636
bitflags = "1.3"
37-
parking_lot = "0.11"
37+
parking_lot = "0.12"
3838

3939
# optional deps only added when requested
4040
futures-core = { version = "0.3", optional = true, default-features = false }
@@ -45,7 +45,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
4545
#
4646
[target.'cfg(windows)'.dependencies.winapi]
4747
version = "0.3.9"
48-
features = ["winuser"]
48+
features = ["winuser", "winerror"]
4949

5050
[target.'cfg(windows)'.dependencies]
5151
crossterm_winapi = "0.9"
@@ -56,18 +56,18 @@ crossterm_winapi = "0.9"
5656
[target.'cfg(unix)'.dependencies]
5757
libc = "0.2"
5858
mio = { version="0.7", features=["os-poll"] }
59-
signal-hook = { version = "0.3.8" }
59+
signal-hook = { version = "0.3.13" }
6060
signal-hook-mio = { version = "0.2.1", features = ["support-v0_7"] }
6161

6262
#
6363
# Dev dependencies (examples, ...)
6464
#
6565
[dev-dependencies]
66-
tokio = { version = "1.5", features = ["full"] }
66+
tokio = { version = "1.16", features = ["full"] }
6767
futures = "0.3"
6868
futures-timer = "3.0"
69-
async-std = "1.9"
70-
serde_json = "1.0.45"
69+
async-std = "1.10"
70+
serde_json = "1.0"
7171

7272
#
7373
# Examples

src/cursor.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ pub struct MoveToColumn(pub u16);
134134

135135
impl Command for MoveToColumn {
136136
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
137-
write!(f, csi!("{}G"), self.0)
137+
if self.0 != 0 {
138+
write!(f, csi!("{}G"), self.0)?;
139+
}
140+
Ok(())
138141
}
139142

140143
#[cfg(windows)]
@@ -153,7 +156,10 @@ pub struct MoveToRow(pub u16);
153156

154157
impl Command for MoveToRow {
155158
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
156-
write!(f, csi!("{}d"), self.0)
159+
if self.0 != 0 {
160+
write!(f, csi!("{}d"), self.0)?
161+
}
162+
Ok(())
157163
}
158164

159165
#[cfg(windows)]

src/event/sys/unix/parse.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -264,23 +264,25 @@ pub(crate) fn parse_csi_u_encoded_key_code(buffer: &[u8]) -> Result<Option<Inter
264264
let keycode = {
265265
if let Some(c) = char::from_u32(codepoint) {
266266
match c {
267-
'\x1B' => KeyCode::Esc.into(),
268-
'\r' => KeyCode::Enter.into(),
267+
'\x1B' => KeyCode::Esc,
268+
'\r' => KeyCode::Enter,
269269
// Issue #371: \n = 0xA, which is also the keycode for Ctrl+J. The only reason we get
270270
// newlines as input is because the terminal converts \r into \n for us. When we
271271
// enter raw mode, we disable that, so \n no longer has any meaning - it's better to
272272
// use Ctrl+J. Waiting to handle it here means it gets picked up later
273-
'\n' if !crate::terminal::sys::is_raw_mode_enabled() => KeyCode::Enter.into(),
274-
'\t' => if modifiers.contains(KeyModifiers::SHIFT) {
275-
KeyCode::BackTab.into()
276-
} else {
277-
KeyCode::Tab.into()
278-
},
279-
'\x7F' => KeyCode::Backspace.into(),
280-
_ => KeyCode::Char(c).into(),
273+
'\n' if !crate::terminal::sys::is_raw_mode_enabled() => KeyCode::Enter,
274+
'\t' => {
275+
if modifiers.contains(KeyModifiers::SHIFT) {
276+
KeyCode::BackTab
277+
} else {
278+
KeyCode::Tab
279+
}
280+
}
281+
'\x7F' => KeyCode::Backspace,
282+
_ => KeyCode::Char(c),
281283
}
282284
} else {
283-
return Err(could_not_parse_event_error())
285+
return Err(could_not_parse_event_error());
284286
}
285287
};
286288

src/macros.rs

+15-19
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,18 @@ macro_rules! csi {
3030
/// use std::io::{Write, stdout};
3131
/// use crossterm::{queue, style::Print};
3232
///
33-
/// fn main() {
34-
/// let mut stdout = stdout();
33+
/// let mut stdout = stdout();
3534
///
36-
/// // `Print` will executed executed when `flush` is called.
37-
/// queue!(stdout, Print("foo".to_string()));
35+
/// // `Print` will executed executed when `flush` is called.
36+
/// queue!(stdout, Print("foo".to_string()));
3837
///
39-
/// // some other code (no execution happening here) ...
38+
/// // some other code (no execution happening here) ...
4039
///
41-
/// // when calling `flush` on `stdout`, all commands will be written to the stdout and therefore executed.
42-
/// stdout.flush();
40+
/// // when calling `flush` on `stdout`, all commands will be written to the stdout and therefore executed.
41+
/// stdout.flush();
4342
///
44-
/// // ==== Output ====
45-
/// // foo
46-
/// }
43+
/// // ==== Output ====
44+
/// // foo
4745
/// ```
4846
///
4947
/// Have a look over at the [Command API](./#command-api) for more details.
@@ -86,17 +84,15 @@ macro_rules! queue {
8684
/// use std::io::{Write, stdout};
8785
/// use crossterm::{execute, style::Print};
8886
///
89-
/// fn main() {
90-
/// // will be executed directly
91-
/// execute!(stdout(), Print("sum:\n".to_string()));
87+
/// // will be executed directly
88+
/// execute!(stdout(), Print("sum:\n".to_string()));
9289
///
93-
/// // will be executed directly
94-
/// execute!(stdout(), Print("1 + 1= ".to_string()), Print((1+1).to_string()));
90+
/// // will be executed directly
91+
/// execute!(stdout(), Print("1 + 1= ".to_string()), Print((1+1).to_string()));
9592
///
96-
/// // ==== Output ====
97-
/// // sum:
98-
/// // 1 + 1 = 2
99-
/// }
93+
/// // ==== Output ====
94+
/// // sum:
95+
/// // 1 + 1 = 2
10096
/// ```
10197
///
10298
/// Have a look over at the [Command API](./#command-api) for more details.

src/terminal.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ mod tests {
414414
#[test]
415415
fn test_raw_mode() {
416416
// check we start from normal mode (may fail on some test harnesses)
417-
assert_eq!(is_raw_mode_enabled().unwrap(), false);
417+
assert!(!is_raw_mode_enabled().unwrap());
418418

419419
// enable the raw mode
420420
if enable_raw_mode().is_err() {
@@ -425,18 +425,18 @@ mod tests {
425425

426426
// check it worked (on unix it doesn't really check the underlying
427427
// tty but rather check that the code is consistent)
428-
assert_eq!(is_raw_mode_enabled().unwrap(), true);
428+
assert!(is_raw_mode_enabled().unwrap());
429429

430430
// enable it again, this should not change anything
431431
enable_raw_mode().unwrap();
432432

433433
// check we're still in raw mode
434-
assert_eq!(is_raw_mode_enabled().unwrap(), true);
434+
assert!(is_raw_mode_enabled().unwrap());
435435

436436
// now let's disable it
437437
disable_raw_mode().unwrap();
438438

439439
// check we're back to normal mode
440-
assert_eq!(is_raw_mode_enabled().unwrap(), false);
440+
assert!(!is_raw_mode_enabled().unwrap());
441441
}
442442
}

0 commit comments

Comments
 (0)