aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/shared.rs
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-01-06 12:53:12 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-01-06 12:53:12 +0000
commita6ba792e89e1e2b7afca7025529c97266e903fd4 (patch)
tree3ca52274d672c3b5a26192d322c211768b986b8c /src/utils/shared.rs
parentfix(render): properly render plugin borders and content (diff)
downloadsl0ppij-a6ba792e89e1e2b7afca7025529c97266e903fd4.tar.gz
sl0ppij-a6ba792e89e1e2b7afca7025529c97266e903fd4.tar.xz
sl0ppij-a6ba792e89e1e2b7afca7025529c97266e903fd4.zip
Also borken
Diffstat (limited to 'src/utils/shared.rs')
-rw-r--r--src/utils/shared.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/shared.rs b/src/utils/shared.rs
new file mode 100644
index 00000000..3b8b5fbd
--- /dev/null
+++ b/src/utils/shared.rs
@@ -0,0 +1,17 @@
+use std::iter;
+
+use strip_ansi_escapes::strip;
+
+// FIXME: Should this be an extension trait? Or here at all?
+pub fn ansi_len(s: &str) -> usize {
+ strip(s.as_bytes()).unwrap().len()
+}
+
+pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String {
+ s.lines()
+ .map(|l| [l, &str::repeat(" ", dbg!(columns) - dbg!(ansi_len(l)))].concat())
+ .chain(iter::repeat(str::repeat(" ", columns)))
+ .take(rows)
+ .collect::<Vec<_>>()
+ .join("\n\r")
+}