Skip to content

Commit

Permalink
Bump MSRV to 1.48.0 and vendor terminal-size (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 7, 2022
1 parent 9c724ae commit 7febd3c
Show file tree
Hide file tree
Showing 7 changed files with 462 additions and 133 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Expand Up @@ -6,17 +6,17 @@ on:
branches: [master]
jobs:
build-msrv:
name: Build on MSRV (1.40)
name: Build on MSRV (1.48)
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
rust: 1.40.0
rust: 1.48.0
- os: windows-latest
target: i686-pc-windows-msvc
rust: 1.40.0
rust: 1.48.0
runs-on: ${{ matrix.os }}
steps:
- name: Install rust
Expand All @@ -41,7 +41,7 @@ jobs:
include:
- os: macos-latest
target: x86_64-apple-darwin
rust: 1.51.0
rust: stable
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
rust: 1.51.0
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.51.0
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Checkout
Expand Down
14 changes: 10 additions & 4 deletions Cargo.toml
Expand Up @@ -13,21 +13,27 @@ readme = "README.md"

[features]
default = ["unicode-width", "ansi-parsing"]
windows-console-colors = ["ansi-parsing", "regex", "winapi-util"]
windows-console-colors = ["ansi-parsing", "regex"]
ansi-parsing = []

[dependencies]
libc = "0.2.30"
terminal_size = "0.1.14"
regex = { version = "1.4.2", optional = true, default-features = false, features = ["std"] }
unicode-width = { version = "0.1", optional = true }
lazy_static = "1.4.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase", "winuser", "consoleapi", "processenv", "wincon"] }
winapi-util = { version = "0.1.3", optional = true }
encode_unicode = "0.3"

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.42.0"
features = [
"Win32_Foundation",
"Win32_System_Console",
"Win32_Storage_FileSystem",
"Win32_UI_Input_KeyboardAndMouse",
]

[dev-dependencies]
proptest = "1.0.0"
regex = "1.4.2"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://github.com/console-rs/console/workflows/CI/badge.svg?branch=master)](https://github.com/console-rs/console/actions?query=workflow%3ACI)
[![Crates.io](https://img.shields.io/crates/d/console.svg)](https://crates.io/crates/console)
[![License](https://img.shields.io/github/license/console-rs/console)](https://github.com/console-rs/console/blob/master/LICENSE)
[![rustc 1.40.0](https://img.shields.io/badge/rust-1.40%2B-orange.svg)](https://img.shields.io/badge/rust-1.40%2B-orange.svg)
[![rustc 1.48.0](https://img.shields.io/badge/rust-1.48%2B-orange.svg)](https://img.shields.io/badge/rust-1.48%2B-orange.svg)
[![Documentation](https://docs.rs/console/badge.svg)](https://docs.rs/console)

**console** is a library for Rust that provides access to various terminal
Expand Down
7 changes: 3 additions & 4 deletions src/term.rs
Expand Up @@ -507,8 +507,6 @@ impl Term {
if self.is_msys_tty || !self.is_tty {
self.write_through_common(bytes)
} else {
use winapi_util::console::Console;

match self.inner.target {
TermTarget::Stdout => console_colors(self, Console::stdout()?, bytes),
TermTarget::Stderr => console_colors(self, Console::stderr()?, bytes),
Expand Down Expand Up @@ -578,8 +576,9 @@ impl AsRawFd for Term {
#[cfg(windows)]
impl AsRawHandle for Term {
fn as_raw_handle(&self) -> RawHandle {
use winapi::um::processenv::GetStdHandle;
use winapi::um::winbase::{STD_ERROR_HANDLE, STD_OUTPUT_HANDLE};
use windows_sys::Win32::System::Console::{
GetStdHandle, STD_ERROR_HANDLE, STD_OUTPUT_HANDLE,
};

unsafe {
GetStdHandle(match self.inner.target {
Expand Down
19 changes: 17 additions & 2 deletions src/unix_term.rs
Expand Up @@ -42,9 +42,24 @@ pub fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
}
}

#[inline]
pub fn terminal_size(out: &Term) -> Option<(u16, u16)> {
terminal_size::terminal_size_using_fd(out.as_raw_fd()).map(|x| ((x.1).0, (x.0).0))
unsafe {
if libc::isatty(libc::STDOUT_FILENO) != 1 {
return None;
}

let mut winsize: libc::winsize = std::mem::zeroed();

// FIXME: ".into()" used as a temporary fix for a libc bug
// https://github.com/rust-lang/libc/pull/704
#[allow(clippy::useless_conversion)]
libc::ioctl(out.as_raw_fd(), libc::TIOCGWINSZ.into(), &mut winsize);
if winsize.ws_row > 0 && winsize.ws_col > 0 {
Some((winsize.ws_row as u16, winsize.ws_col as u16))
} else {
None
}
}
}

pub fn read_secure() -> io::Result<String> {
Expand Down

0 comments on commit 7febd3c

Please sign in to comment.