diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-04-03 21:19:39 +0200 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-04-03 21:19:39 +0200 |
| commit | 4f5f189373603d29fc8b042b72aae375efbd0a1c (patch) | |
| tree | d63b769a0c218d4956316fd3128f96ed33c2d9cf /src/common/utils | |
| parent | Merge branch 'main' of https://github.com/zellij-org/zellij into config-file (diff) | |
| parent | Add Kyle to governance.md (diff) | |
| download | sl0ppij-4f5f189373603d29fc8b042b72aae375efbd0a1c.tar.gz sl0ppij-4f5f189373603d29fc8b042b72aae375efbd0a1c.tar.xz sl0ppij-4f5f189373603d29fc8b042b72aae375efbd0a1c.zip | |
Merge branch 'main' of https://github.com/zellij-org/zellij into config-file
Diffstat (limited to 'src/common/utils')
| -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<_>>() |
