From: Simon Tatham Date: Sun, 24 Dec 2023 21:48:03 +0000 (+0000) Subject: EditorHeaderSeparator, which is really easy X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=b7c067cb86c1b5a9a83dd8a83128310e6f84337b;p=mastodonochrome.git EditorHeaderSeparator, which is really easy --- 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( + "---|", + "----", + ) + }); +}