diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-04-13 16:17:40 +0100 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-04-13 16:17:40 +0100 |
| commit | 0e73227fe2418c3a4945f493afbc64ab66dcb763 (patch) | |
| tree | e46256e314b2a70a5dc8f7281519695bf2a5ffad /src/common/utils | |
| parent | docs(build): documented the new build system (diff) | |
| parent | fix(performance): remove unnecessary allocations from pty (#264) (diff) | |
| download | sl0ppij-0e73227fe2418c3a4945f493afbc64ab66dcb763.tar.gz sl0ppij-0e73227fe2418c3a4945f493afbc64ab66dcb763.tar.xz sl0ppij-0e73227fe2418c3a4945f493afbc64ab66dcb763.zip | |
merge(main): update branch with changes from main
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<_>>() |
