Skip to content

Commit

Permalink
Merge pull request #229 from KP64/master
Browse files Browse the repository at this point in the history
refactor: ➕ Added terminal_size dependency
  • Loading branch information
solidiquis authored Jul 14, 2023
2 parents 202fae1 + 67cde82 commit 6fc3494
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 92 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ indextree = "4.6.0"
lscolors = { version = "0.13.0", features = ["ansi_term"] }
once_cell = "1.17.0"
regex = "1.7.3"
terminal_size = "0.2.6"
thiserror = "1.0.40"

[target.'cfg(unix)'.dependencies]
Expand Down
9 changes: 5 additions & 4 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::disk_usage::{file_size::DiskUsage, units::PrefixKind};
use crate::tty;

use args::Reconciler;
use clap::{FromArgMatches, Parser};
use color::Coloring;
Expand All @@ -12,6 +12,7 @@ use regex::Regex;
use std::{
borrow::Borrow,
convert::From,
io::{stdin, stdout, IsTerminal},
num::NonZeroUsize,
path::{Path, PathBuf},
thread::available_parallelism,
Expand Down Expand Up @@ -206,11 +207,11 @@ pub struct Context {
/* INTERNAL USAGE BELOW */
//////////////////////////
/// Is stdin in a tty?
#[clap(skip = tty::stdin_is_tty())]
#[clap(skip = stdin().is_terminal())]
pub stdin_is_tty: bool,

/// Is stdin in a tty?
#[clap(skip = tty::stdout_is_tty())]
#[clap(skip = stdout().is_terminal())]
pub stdout_is_tty: bool,

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

/// Answers whether disk usage is asked to be reported in bytes.
Expand Down
2 changes: 1 addition & 1 deletion src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a> Indicator<'a> {

let int_handler = move || {
let _ = mailbox.try_send(Message::Finish);
tty::restore_tty();
tty::restore();
};

ctrlc::set_handler(int_handler).expect("Failed to set interrupt handler");
Expand Down
16 changes: 16 additions & 0 deletions src/tty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crossterm::{cursor, ExecutableCommand};
use terminal_size::terminal_size;
use std::io;

/// Restore terminal settings.
pub fn restore() {
io::stdout()
.execute(cursor::Show)
.expect("Failed to restore cursor");
}

/// Attempts to get the current size of the tty's window. Returns `None` if stdout isn't tty or if
/// failed to get width.
pub fn get_window_width() -> Option<usize> {
Some(usize::from(terminal_size()?.0 .0))
}
41 changes: 0 additions & 41 deletions src/tty/mod.rs

This file was deleted.

14 changes: 0 additions & 14 deletions src/tty/unix.rs

This file was deleted.

32 changes: 0 additions & 32 deletions src/tty/windows.rs

This file was deleted.

0 comments on commit 6fc3494

Please sign in to comment.