Skip to content

Commit

Permalink
Refactor terminal_width package
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Apr 5, 2021
1 parent fe07f65 commit 16a8b27
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 104 deletions.
114 changes: 16 additions & 98 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ travis-ci = { repository = "denisidoro/navi", branch = "master" }
regex = "1.4.3"
clap = "3.0.0-beta.2"
termion = "1.5.6"
raw_tty = "0.1.0"
lazy_static = "1.4.0"
directories-next = "2.0.0"
terminal_size = "0.1.16"
Expand Down
5 changes: 2 additions & 3 deletions src/display/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use crate::display;
use crate::env_vars;
use crate::finder;
use crate::structures::item::Item;
use crate::terminal_width;
use crate::terminal::{self, color};
use std::cmp::max;
use std::collections::HashSet;
use std::env;
use std::iter;
use std::str::FromStr;
use termion::color;

// TODO: extract
pub fn parse_env_var<T: FromStr>(varname: &str) -> Option<T> {
Expand Down Expand Up @@ -146,7 +145,7 @@ fn limit_str(text: &str, length: usize) -> String {
}

fn get_widths() -> (usize, usize) {
let width = terminal_width::get();
let width = terminal::width();
let tag_width = max(4, width * *TAG_WIDTH_PERCENTAGE / 100);
let comment_width = max(4, width * *COMMENT_WIDTH_PERCENTAGE / 100);
(usize::from(tag_width), usize::from(comment_width))
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod hash;
mod parser;
mod shell;
mod structures;
mod terminal_width;
mod terminal;
mod tldr;
mod url;
mod welcome;
Expand Down
3 changes: 2 additions & 1 deletion src/terminal_width.rs → src/terminal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use terminal_size::{terminal_size, terminal_size_using_fd, Height, Width};
pub use termion::color;

const FALLBACK_WIDTH: u16 = 80;

Expand Down Expand Up @@ -57,7 +58,7 @@ fn width_with_fd() -> u16 {
}
}

pub fn get() -> u16 {
pub fn width() -> u16 {
let size = terminal_size();
if let Some((Width(w), Height(_))) = size {
w
Expand Down

0 comments on commit 16a8b27

Please sign in to comment.