chiark / gitweb /
EditorHeaderSeparator, which is really easy
authorSimon Tatham <anakin@pobox.com>
Sun, 24 Dec 2023 21:48:03 +0000 (21:48 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 24 Dec 2023 21:48:03 +0000 (21:48 +0000)
src/text.rs

index 386b91751f9ff66e6a08775c07a9f585a99a6f92..e8970e8ac49de90fc8296ef9958c975391b5c595 100644 (file)
@@ -1,4 +1,5 @@
 use chrono::{DateTime,Utc,Local};
+use core::cmp::max;
 
 use super::coloured_string::ColouredString;
 
@@ -76,6 +77,25 @@ impl TextFragment for SeparatorLine {
     }
 }
 
+pub struct EditorHeaderSeparator {}
+
+impl EditorHeaderSeparator {
+    pub fn newbox() -> Box<dyn TextFragment> {
+        Box::new(EditorHeaderSeparator{})
+    }
+}
+
+impl TextFragment for EditorHeaderSeparator {
+    fn render(&self, width: usize) -> Vec<ColouredString> {
+        vec! {
+            ColouredString::uniform(
+                &((&"-".repeat(max(0, width - 2))).to_string() + "|"),
+                '-',
+            ).split(width).next().unwrap().to_owned(),
+        }
+    }
+}
+
 #[test]
 fn blank() {
     assert_eq!(BlankLine::newbox().render(40), vec! {
@@ -95,3 +115,13 @@ fn separator() {
                 )
         });
 }
+
+#[test]
+fn editorsep() {
+    assert_eq!(EditorHeaderSeparator::newbox().render(5), vec! {
+            ColouredString::general(
+                "---|",
+                "----",
+                )
+        });
+}