diff options
author | rabite <rabite@posteo.de> | 2019-01-21 17:47:58 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-01-21 17:47:58 +0100 |
commit | 8ad1b657ec3d20bab2199b33a22ff9a191dfe58d (patch) | |
tree | 9cf9d11a7f40060c0a5ceb8b72c9577f443b5614 /src/term.rs | |
parent | 724cc61680e14d45fb7c0e5ebac525b71e7a1381 (diff) |
got file sizes working in listview
Diffstat (limited to 'src/term.rs')
-rw-r--r-- | src/term.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/term.rs b/src/term.rs index c559ad8..022f16b 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,3 +1,5 @@ +use unicode_width::UnicodeWidthStr; + use std::io::{Stdout, Write}; use termion; use termion::screen::AlternateScreen; @@ -16,6 +18,10 @@ pub trait ScreenExt: Write { impl ScreenExt for AlternateScreen<Box<Stdout>> {} +pub fn size() -> (u16, u16) { + termion::terminal_size().unwrap() +} + pub fn xsize() -> usize { let (xsize, _) = termion::terminal_size().unwrap(); xsize as usize @@ -26,6 +32,17 @@ pub fn ysize() -> usize { ysize as usize } +pub fn sized_string(string: &str, xsize: u16) -> String { + let lenstr: String = string.chars().fold("".into(), |acc,ch| { + if acc.width() + 1 >= xsize as usize { acc } + else { acc + &ch.to_string() } + }); + lenstr +} + +// Do these as constants + + pub fn highlight_color() -> String { format!( "{}{}", @@ -42,6 +59,7 @@ pub fn normal_color() -> String { ) } + pub fn cursor_left(n: usize) -> String { format!("{}", termion::cursor::Left(n as u16)) } @@ -81,4 +99,3 @@ pub fn header_color() -> String { pub fn status_bg() -> String { format!("{}", termion::color::Bg(termion::color::LightBlue)) } - |