Skip to content

Commit 7febd3c

Browse files
authored
Bump MSRV to 1.48.0 and vendor terminal-size (#146)
1 parent 9c724ae commit 7febd3c

File tree

7 files changed

+462
-133
lines changed

7 files changed

+462
-133
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ on:
66
branches: [master]
77
jobs:
88
build-msrv:
9-
name: Build on MSRV (1.40)
9+
name: Build on MSRV (1.48)
1010
strategy:
1111
fail-fast: false
1212
matrix:
1313
include:
1414
- os: ubuntu-latest
1515
target: x86_64-unknown-linux-gnu
16-
rust: 1.40.0
16+
rust: 1.48.0
1717
- os: windows-latest
1818
target: i686-pc-windows-msvc
19-
rust: 1.40.0
19+
rust: 1.48.0
2020
runs-on: ${{ matrix.os }}
2121
steps:
2222
- name: Install rust
@@ -41,7 +41,7 @@ jobs:
4141
include:
4242
- os: macos-latest
4343
target: x86_64-apple-darwin
44-
rust: 1.51.0
44+
rust: stable
4545
- os: ubuntu-latest
4646
target: x86_64-unknown-linux-gnu
4747
rust: 1.51.0
@@ -92,7 +92,7 @@ jobs:
9292
uses: actions-rs/toolchain@v1
9393
with:
9494
profile: minimal
95-
toolchain: 1.51.0
95+
toolchain: stable
9696
target: ${{ matrix.target }}
9797
override: true
9898
- name: Checkout

Cargo.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ readme = "README.md"
1313

1414
[features]
1515
default = ["unicode-width", "ansi-parsing"]
16-
windows-console-colors = ["ansi-parsing", "regex", "winapi-util"]
16+
windows-console-colors = ["ansi-parsing", "regex"]
1717
ansi-parsing = []
1818

1919
[dependencies]
2020
libc = "0.2.30"
21-
terminal_size = "0.1.14"
2221
regex = { version = "1.4.2", optional = true, default-features = false, features = ["std"] }
2322
unicode-width = { version = "0.1", optional = true }
2423
lazy_static = "1.4.0"
2524

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

28+
[target.'cfg(windows)'.dependencies.windows-sys]
29+
version = "0.42.0"
30+
features = [
31+
"Win32_Foundation",
32+
"Win32_System_Console",
33+
"Win32_Storage_FileSystem",
34+
"Win32_UI_Input_KeyboardAndMouse",
35+
]
36+
3137
[dev-dependencies]
3238
proptest = "1.0.0"
3339
regex = "1.4.2"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://github.com/console-rs/console/workflows/CI/badge.svg?branch=master)](https://github.com/console-rs/console/actions?query=workflow%3ACI)
44
[![Crates.io](https://img.shields.io/crates/d/console.svg)](https://crates.io/crates/console)
55
[![License](https://img.shields.io/github/license/console-rs/console)](https://github.com/console-rs/console/blob/master/LICENSE)
6-
[![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)
6+
[![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)
77
[![Documentation](https://docs.rs/console/badge.svg)](https://docs.rs/console)
88

99
**console** is a library for Rust that provides access to various terminal

src/term.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,6 @@ impl Term {
507507
if self.is_msys_tty || !self.is_tty {
508508
self.write_through_common(bytes)
509509
} else {
510-
use winapi_util::console::Console;
511-
512510
match self.inner.target {
513511
TermTarget::Stdout => console_colors(self, Console::stdout()?, bytes),
514512
TermTarget::Stderr => console_colors(self, Console::stderr()?, bytes),
@@ -578,8 +576,9 @@ impl AsRawFd for Term {
578576
#[cfg(windows)]
579577
impl AsRawHandle for Term {
580578
fn as_raw_handle(&self) -> RawHandle {
581-
use winapi::um::processenv::GetStdHandle;
582-
use winapi::um::winbase::{STD_ERROR_HANDLE, STD_OUTPUT_HANDLE};
579+
use windows_sys::Win32::System::Console::{
580+
GetStdHandle, STD_ERROR_HANDLE, STD_OUTPUT_HANDLE,
581+
};
583582

584583
unsafe {
585584
GetStdHandle(match self.inner.target {

src/unix_term.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,24 @@ pub fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
4242
}
4343
}
4444

45-
#[inline]
4645
pub fn terminal_size(out: &Term) -> Option<(u16, u16)> {
47-
terminal_size::terminal_size_using_fd(out.as_raw_fd()).map(|x| ((x.1).0, (x.0).0))
46+
unsafe {
47+
if libc::isatty(libc::STDOUT_FILENO) != 1 {
48+
return None;
49+
}
50+
51+
let mut winsize: libc::winsize = std::mem::zeroed();
52+
53+
// FIXME: ".into()" used as a temporary fix for a libc bug
54+
// https://github.com/rust-lang/libc/pull/704
55+
#[allow(clippy::useless_conversion)]
56+
libc::ioctl(out.as_raw_fd(), libc::TIOCGWINSZ.into(), &mut winsize);
57+
if winsize.ws_row > 0 && winsize.ws_col > 0 {
58+
Some((winsize.ws_row as u16, winsize.ws_col as u16))
59+
} else {
60+
None
61+
}
62+
}
4863
}
4964

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

0 commit comments

Comments
 (0)