From: Ian Jackson Date: Tue, 30 Mar 2021 09:30:59 +0000 (+0100) Subject: clock: Refactor Show X-Git-Tag: otter-0.5.0~375 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b2ddd5e4b16d497623813ffc9e3e4b84baa3565b;p=otter.git clock: Refactor Show Signed-off-by: Ian Jackson --- diff --git a/src/clock.rs b/src/clock.rs index f918a26d..667542a3 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -449,24 +449,29 @@ impl PieceTrait for Clock { const Y: &[f32] = &[ 7., 0. ]; struct Show { - text: &'static str, - background: &'static str, - sigil: &'static str, + text_override: Option<&'static str>, + background: &'static str, + sigil: &'static str, } impl URenderState { fn show(self) -> Show { use URS::*; - let (text, background, sigil) = match self { - Running => ("black", "yellow", "▶" /* > */ ), - ActiveHeld => ("black", "yellow", "‖" /* || */ ), - OtherFlag => ("black", "yellow", ":" ), - Inactive => ("black", "white", ":" ), - Stopped => ("black", "lightblue", "□" /* [] */ ), - Reset => ("black", "lightgreen", "○" /* O */ ), - Flag => ("white", "red", "⚑" /* F */ ), + let (text_override, background, sigil) = match self { + Running => (None, "yellow", "▶" /* > */ ), + ActiveHeld => (None, "yellow", "‖" /* || */ ), + OtherFlag => (None, "yellow", ":" ), + Inactive => (None, "white", ":" ), + Stopped => (None, "lightblue", "□" /* [] */ ), + Reset => (None, "lightgreen", "○" /* O */ ), + Flag => (Some("white"), "red", "⚑" /* F */ ), }; - Show { text, background, sigil } + Show { text_override, background, sigil } + } + } + impl Show { + fn text(&self) -> &'static str { + self.text_override.unwrap_or("black") } } @@ -504,12 +509,12 @@ impl PieceTrait for Clock { "##); hwrite!(f, r##" {}{}{}"##, - y, font, pointer, Html::lit(show.text), + y, font, pointer, Html::lit(show.text()), mins_pad, HtmlStr::from_html_str(&mins), Html::lit(show.sigil) )?; hwrite!(f, r##" {:02}"##, - y, font, pointer, Html::lit(show.text), + y, font, pointer, Html::lit(show.text()), secs )?; let nick_y = y - 0.5;