From b7c067cb86c1b5a9a83dd8a83128310e6f84337b Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 24 Dec 2023 21:48:03 +0000 Subject: [PATCH] EditorHeaderSeparator, which is really easy --- src/text.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/text.rs b/src/text.rs index 386b917..e8970e8 100644 --- a/src/text.rs +++ b/src/text.rs @@ -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 { + Box::new(EditorHeaderSeparator{}) + } +} + +impl TextFragment for EditorHeaderSeparator { + fn render(&self, width: usize) -> Vec { + 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( + "---|", + "----", + ) + }); +} -- 2.30.2