diff --git a/src/clock.rs b/src/clock.rs index 3489ca2..13e6cbb 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -82,6 +82,14 @@ impl Clock { mut stdout: &mut RawTerminal, layout: &Layout, ) { + // Setup style and color if appropriate. + if self.paused { + write!(stdout, "{}", style::Faint).unwrap(); + } + if let Some(c) = self.color_index { + write!(stdout, "{}", color::Fg(COLOR[c])).unwrap(); + } + // Draw hours if necessary. if layout.force_redraw || self.elapsed % 3600 == 0 { if self.elapsed >= 3600 { @@ -139,6 +147,15 @@ impl Clock { self.elapsed % 60, &layout.clock_sec, layout.plain); + + // Reset color and style. + if self.paused || self.color_index != None { + write!(stdout, + "{}{}", + style::NoFaint, + color::Fg(color::Reset)) + .unwrap(); + } } fn draw_digit_pair( @@ -148,41 +165,16 @@ impl Clock { pos: &Position, plain: bool, ) { - if self.paused { - write!(stdout, "{}", style::Faint).unwrap(); - } - - if let Some(c) = self.color_index { - write!(stdout, "{}", color::Fg(COLOR[c])).unwrap(); - } + let digits = if plain { DIGITS_PLAIN } else { DIGITS }; for l in 0..DIGIT_HEIGHT { - if plain { - write!(stdout, - "{}{} {}", - cursor::Goto(pos.col, pos.line + l), - // First digit. - DIGITS_PLAIN[(value / 10) as usize][l as usize], - // Second digit. - DIGITS_PLAIN[(value % 10) as usize][l as usize]) - .unwrap(); - } else { - write!(stdout, - "{}{} {}", - cursor::Goto(pos.col, pos.line + l), - // First digit. - DIGITS[(value / 10) as usize][l as usize], - // Second digit. - DIGITS[(value % 10) as usize][l as usize]) - .unwrap(); - } - } - - if self.paused || self.color_index != None { write!(stdout, - "{}{}", - style::NoFaint, - color::Fg(color::Reset)) + "{}{} {}", + cursor::Goto(pos.col, pos.line + l), + // First digit. + digits[(value / 10) as usize][l as usize], + // Second digit. + digits[(value % 10) as usize][l as usize]) .unwrap(); } } @@ -195,33 +187,13 @@ impl Clock { ) { let dot = if plain {'█'} else {'■'}; - if self.paused { - write!(stdout, "{}", style::Faint).unwrap(); - } - - if let Some(c) = self.color_index { - write!(stdout, - "{}{}{}{}{}{}", - cursor::Goto(pos.col, pos.line + 1), - color::Fg(COLOR[c]), - dot, - cursor::Goto(pos.col, pos.line + 3), - dot, - color::Fg(color::Reset)) - .unwrap(); - } else { - write!(stdout, - "{}{}{}{}", - cursor::Goto(pos.col, pos.line + 1), - dot, - cursor::Goto(pos.col, pos.line + 3), - dot) - .unwrap(); - } - - if self.paused { - write!(stdout, "{}", style::NoFaint).unwrap(); - } + write!(stdout, + "{}{}{}{}", + cursor::Goto(pos.col, pos.line + 1), + dot, + cursor::Goto(pos.col, pos.line + 3), + dot) + .unwrap(); } } diff --git a/src/lib.rs b/src/lib.rs index e684956..d0b69aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,7 +167,10 @@ pub fn run( true if layout.can_hold(MENUBAR_INS) => MENUBAR_INS, false if layout.can_hold(MENUBAR) => MENUBAR, false if layout.can_hold(MENUBAR_SHORT) => MENUBAR_SHORT, - _ => "", + // Clearing the screen from position 1, 1 seems to have + // unwanted side effects. We avoid this by writing a + // single space here. + _ => " ", }, clear::AfterCursor, style::NoFaint)?;