diff options
author | rabite <rabite@posteo.de> | 2019-02-01 01:37:16 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-02-01 01:37:16 +0100 |
commit | 1e6719fe3368068217968fe0b637604668cb7764 (patch) | |
tree | 31e57e54794db716079bbaff2df9bc6177b942b9 /src/term.rs | |
parent | b7bbcff2840f5b0b0b46f9188ae45be0075f9864 (diff) |
improved string handling
Diffstat (limited to 'src/term.rs')
-rw-r--r-- | src/term.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/term.rs b/src/term.rs index 7ec366c..ed8380b 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,5 +1,3 @@ -use unicode_width::UnicodeWidthStr; - use std::io::{Stdout, Write}; use termion; use termion::screen::AlternateScreen; @@ -29,14 +27,14 @@ pub fn ysize() -> 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 { + string.chars().fold("".to_string(), |acc, ch| { + let width: usize = unicode_width::UnicodeWidthStr::width_cjk(acc.as_str()); + if width + 1 >= xsize as usize { acc } else { acc + &ch.to_string() } - }); - lenstr + }) } // Do these as constants |