Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: console-rs/console
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.15.6
Choose a base ref
...
head repository: console-rs/console
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.15.7
Choose a head ref
  • 6 commits
  • 3 files changed
  • 2 contributors

Commits on May 21, 2023

  1. Raise libc minimums to 0.2.99

    Fixes #170
    mitsuhiko committed May 21, 2023
    Copy the full SHA
    b5c80cc View commit details
  2. Don't touch output config attributes in read_single_key() (#165)

    Raw mode also disables output processing, breaking terminal writes from separate threads.
    goodartistscopy authored May 21, 2023
    Copy the full SHA
    bda931c View commit details
  3. Update changelog entries

    mitsuhiko committed May 21, 2023
    Copy the full SHA
    55e4762 View commit details
  4. Copy the full SHA
    85c4de4 View commit details
  5. Mention changelog entry

    mitsuhiko committed May 21, 2023
    Copy the full SHA
    03aefb9 View commit details
  6. 0.15.7

    mitsuhiko committed May 21, 2023
    Copy the full SHA
    842b376 View commit details
Showing with 36 additions and 24 deletions.
  1. +9 −0 CHANGELOG.md
  2. +2 −2 Cargo.toml
  3. +25 −22 src/unix_term.rs
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.15.7

### Enhancements

* Set an appropriate lower version of libc for macos changes.
* Improved behavior of `read_single_key` so it does not disturb other
threads quite as much. (#165)
* More reliably reset raw mode in terminal. (#171)

## 0.15.6

### Enhancements
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "console"
description = "A terminal and console abstraction for Rust"
version = "0.15.6"
version = "0.15.7"
keywords = ["cli", "terminal", "colors", "console", "ansi"]
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
license = "MIT"
@@ -18,7 +18,7 @@ windows-console-colors = ["ansi-parsing"]
ansi-parsing = []

[dependencies]
libc = "0.2.30"
libc = "0.2.99"
unicode-width = { version = "0.1", optional = true }
lazy_static = "1.4.0"

47 changes: 25 additions & 22 deletions src/unix_term.rs
Original file line number Diff line number Diff line change
@@ -202,27 +202,8 @@ fn read_bytes(fd: i32, buf: &mut [u8], count: u8) -> io::Result<u8> {
}
}

pub fn read_single_key() -> io::Result<Key> {
let tty_f;
let fd = unsafe {
if libc::isatty(libc::STDIN_FILENO) == 1 {
libc::STDIN_FILENO
} else {
tty_f = fs::OpenOptions::new()
.read(true)
.write(true)
.open("/dev/tty")?;
tty_f.as_raw_fd()
}
};
let mut termios = core::mem::MaybeUninit::uninit();
c_result(|| unsafe { libc::tcgetattr(fd, termios.as_mut_ptr()) })?;
let mut termios = unsafe { termios.assume_init() };
let original = termios;
unsafe { libc::cfmakeraw(&mut termios) };
c_result(|| unsafe { libc::tcsetattr(fd, libc::TCSADRAIN, &termios) })?;

let rv: io::Result<Key> = loop {
fn read_single_key_impl(fd: i32) -> Result<Key, io::Error> {
loop {
match read_single_char(fd)? {
Some('\x1b') => {
// Escape was read, keep reading in case we find a familiar key
@@ -311,8 +292,30 @@ pub fn read_single_key() -> io::Result<Key> {
}
}
}
};
}
}

pub fn read_single_key() -> io::Result<Key> {
let tty_f;
let fd = unsafe {
if libc::isatty(libc::STDIN_FILENO) == 1 {
libc::STDIN_FILENO
} else {
tty_f = fs::OpenOptions::new()
.read(true)
.write(true)
.open("/dev/tty")?;
tty_f.as_raw_fd()
}
};
let mut termios = core::mem::MaybeUninit::uninit();
c_result(|| unsafe { libc::tcgetattr(fd, termios.as_mut_ptr()) })?;
let mut termios = unsafe { termios.assume_init() };
let original = termios;
unsafe { libc::cfmakeraw(&mut termios) };
termios.c_oflag = original.c_oflag;
c_result(|| unsafe { libc::tcsetattr(fd, libc::TCSADRAIN, &termios) })?;
let rv: io::Result<Key> = read_single_key_impl(fd);
c_result(|| unsafe { libc::tcsetattr(fd, libc::TCSADRAIN, &original) })?;

// if the user hit ^C we want to signal SIGINT to outselves.