aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/utils
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-04-03 21:19:39 +0200
committera-kenji <aks.kenji@protonmail.com>2021-04-03 21:19:39 +0200
commit4f5f189373603d29fc8b042b72aae375efbd0a1c (patch)
treed63b769a0c218d4956316fd3128f96ed33c2d9cf /src/common/utils
parentMerge branch 'main' of https://github.com/zellij-org/zellij into config-file (diff)
parentAdd Kyle to governance.md (diff)
downloadsl0ppij-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.rs13
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<_>>()