diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-02-09 22:19:34 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-02-09 22:19:34 +0000 |
| commit | 979197085617a84992b38c7fd02098965e2479d5 (patch) | |
| tree | 4136a1d4f39254e72379d1204b62ce6b1e54d144 /src/common/utils/shared.rs | |
| parent | Work towards a functional build (diff) | |
| download | sl0ppij-979197085617a84992b38c7fd02098965e2479d5.tar.gz sl0ppij-979197085617a84992b38c7fd02098965e2479d5.tar.xz sl0ppij-979197085617a84992b38c7fd02098965e2479d5.zip | |
Well, it turns out that I spent 4 hours on something impossible...
Diffstat (limited to 'src/common/utils/shared.rs')
| -rw-r--r-- | src/common/utils/shared.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/utils/shared.rs b/src/common/utils/shared.rs new file mode 100644 index 00000000..1d8ca5c3 --- /dev/null +++ b/src/common/utils/shared.rs @@ -0,0 +1,19 @@ +use std::{iter, str::from_utf8}; + +use strip_ansi_escapes::strip; + +pub fn ansi_len(s: &str) -> usize { + from_utf8(&strip(s.as_bytes()).unwrap()) + .unwrap() + .chars() + .count() +} + +pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String { + s.lines() + .map(|l| [l, &str::repeat(" ", columns - ansi_len(l))].concat()) + .chain(iter::repeat(str::repeat(" ", columns))) + .take(rows) + .collect::<Vec<_>>() + .join("\n\r") +} |
