Skip to content

Commit 6fc3494

Browse files
authored
Merge pull request #229 from KP64/master
refactor: ➕ Added terminal_size dependency
2 parents 202fae1 + 67cde82 commit 6fc3494

File tree

8 files changed

+34
-92
lines changed

8 files changed

+34
-92
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ indextree = "4.6.0"
3939
lscolors = { version = "0.13.0", features = ["ansi_term"] }
4040
once_cell = "1.17.0"
4141
regex = "1.7.3"
42+
terminal_size = "0.2.6"
4243
thiserror = "1.0.40"
4344

4445
[target.'cfg(unix)'.dependencies]

src/context/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::disk_usage::{file_size::DiskUsage, units::PrefixKind};
2-
use crate::tty;
2+
33
use args::Reconciler;
44
use clap::{FromArgMatches, Parser};
55
use color::Coloring;
@@ -12,6 +12,7 @@ use regex::Regex;
1212
use std::{
1313
borrow::Borrow,
1414
convert::From,
15+
io::{stdin, stdout, IsTerminal},
1516
num::NonZeroUsize,
1617
path::{Path, PathBuf},
1718
thread::available_parallelism,
@@ -206,11 +207,11 @@ pub struct Context {
206207
/* INTERNAL USAGE BELOW */
207208
//////////////////////////
208209
/// Is stdin in a tty?
209-
#[clap(skip = tty::stdin_is_tty())]
210+
#[clap(skip = stdin().is_terminal())]
210211
pub stdin_is_tty: bool,
211212

212213
/// Is stdin in a tty?
213-
#[clap(skip = tty::stdout_is_tty())]
214+
#[clap(skip = stdout().is_terminal())]
214215
pub stdout_is_tty: bool,
215216

216217
/// Restricts column width of size not including units
@@ -465,7 +466,7 @@ impl Context {
465466
/// Setter for `window_width` which is set to the current terminal emulator's window width.
466467
#[inline]
467468
pub fn set_window_width(&mut self) {
468-
self.window_width = crate::tty::get_window_width(self.stdout_is_tty);
469+
self.window_width = crate::tty::get_window_width();
469470
}
470471

471472
/// Answers whether disk usage is asked to be reported in bytes.

src/progress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a> Indicator<'a> {
136136

137137
let int_handler = move || {
138138
let _ = mailbox.try_send(Message::Finish);
139-
tty::restore_tty();
139+
tty::restore();
140140
};
141141

142142
ctrlc::set_handler(int_handler).expect("Failed to set interrupt handler");

src/tty.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crossterm::{cursor, ExecutableCommand};
2+
use terminal_size::terminal_size;
3+
use std::io;
4+
5+
/// Restore terminal settings.
6+
pub fn restore() {
7+
io::stdout()
8+
.execute(cursor::Show)
9+
.expect("Failed to restore cursor");
10+
}
11+
12+
/// Attempts to get the current size of the tty's window. Returns `None` if stdout isn't tty or if
13+
/// failed to get width.
14+
pub fn get_window_width() -> Option<usize> {
15+
Some(usize::from(terminal_size()?.0 .0))
16+
}

src/tty/mod.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/tty/unix.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/tty/windows.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)