diff options
| author | Aram Drevekenin <aram@poor.dev> | 2021-04-01 17:38:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-01 17:38:13 +0200 |
| commit | 1739f370f98923d8955e1478bcda564220294829 (patch) | |
| tree | 1f8f4b2c7f5696787a5be65057ef04c1c5101436 /src/common/utils/shared.rs | |
| parent | Merge pull request #244 from a-kenji/main (diff) | |
| download | sl0ppij-1739f370f98923d8955e1478bcda564220294829.tar.gz sl0ppij-1739f370f98923d8955e1478bcda564220294829.tar.xz sl0ppij-1739f370f98923d8955e1478bcda564220294829.zip | |
* fix(ui): react to terminal window size changes (SIGWINCH) (#245)
* fix(ui): react to terminal window size changes (SIGWINCH)
* style(fmt): rustfmt
* style(format): remove some warnings
* style(fmt): rustfmt
Diffstat (limited to 'src/common/utils/shared.rs')
| -rw-r--r-- | src/common/utils/shared.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/common/utils/shared.rs b/src/common/utils/shared.rs index 9717837a..93892d4f 100644 --- a/src/common/utils/shared.rs +++ b/src/common/utils/shared.rs @@ -11,9 +11,18 @@ fn ansi_len(s: &str) -> usize { .count() } -pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String { +pub fn adjust_to_size(s: &str, rows: usize, columns: usize) -> String { s.lines() - .map(|l| [l, &str::repeat(" ", columns - ansi_len(l))].concat()) + .map(|l| { + let actual_len = ansi_len(l); + if actual_len > columns { + let mut line = String::from(l); + line.truncate(columns); + return line; + } else { + return [l, &str::repeat(" ", columns - ansi_len(l))].concat(); + } + }) .chain(iter::repeat(str::repeat(" ", columns))) .take(rows) .collect::<Vec<_>>() |
