Slightly refactored clock drawing code.
This commit is contained in:
parent
85f7b7af03
commit
557358a4c0
2 changed files with 35 additions and 60 deletions
68
src/clock.rs
68
src/clock.rs
|
@ -82,6 +82,14 @@ impl Clock {
|
||||||
mut stdout: &mut RawTerminal<W>,
|
mut stdout: &mut RawTerminal<W>,
|
||||||
layout: &Layout,
|
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.
|
// Draw hours if necessary.
|
||||||
if layout.force_redraw || self.elapsed % 3600 == 0 {
|
if layout.force_redraw || self.elapsed % 3600 == 0 {
|
||||||
if self.elapsed >= 3600 {
|
if self.elapsed >= 3600 {
|
||||||
|
@ -139,6 +147,15 @@ impl Clock {
|
||||||
self.elapsed % 60,
|
self.elapsed % 60,
|
||||||
&layout.clock_sec,
|
&layout.clock_sec,
|
||||||
layout.plain);
|
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<W: Write>(
|
fn draw_digit_pair<W: Write>(
|
||||||
|
@ -148,41 +165,16 @@ impl Clock {
|
||||||
pos: &Position,
|
pos: &Position,
|
||||||
plain: bool,
|
plain: bool,
|
||||||
) {
|
) {
|
||||||
if self.paused {
|
let digits = if plain { DIGITS_PLAIN } else { DIGITS };
|
||||||
write!(stdout, "{}", style::Faint).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(c) = self.color_index {
|
|
||||||
write!(stdout, "{}", color::Fg(COLOR[c])).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
for l in 0..DIGIT_HEIGHT {
|
for l in 0..DIGIT_HEIGHT {
|
||||||
if plain {
|
|
||||||
write!(stdout,
|
write!(stdout,
|
||||||
"{}{} {}",
|
"{}{} {}",
|
||||||
cursor::Goto(pos.col, pos.line + l),
|
cursor::Goto(pos.col, pos.line + l),
|
||||||
// First digit.
|
// First digit.
|
||||||
DIGITS_PLAIN[(value / 10) as usize][l as usize],
|
digits[(value / 10) as usize][l as usize],
|
||||||
// Second digit.
|
// Second digit.
|
||||||
DIGITS_PLAIN[(value % 10) as usize][l as usize])
|
digits[(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))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,21 +187,6 @@ impl Clock {
|
||||||
) {
|
) {
|
||||||
let dot = if plain {'█'} else {'■'};
|
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,
|
write!(stdout,
|
||||||
"{}{}{}{}",
|
"{}{}{}{}",
|
||||||
cursor::Goto(pos.col, pos.line + 1),
|
cursor::Goto(pos.col, pos.line + 1),
|
||||||
|
@ -218,10 +195,5 @@ impl Clock {
|
||||||
dot)
|
dot)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.paused {
|
|
||||||
write!(stdout, "{}", style::NoFaint).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,10 @@ pub fn run(
|
||||||
true if layout.can_hold(MENUBAR_INS) => MENUBAR_INS,
|
true if layout.can_hold(MENUBAR_INS) => MENUBAR_INS,
|
||||||
false if layout.can_hold(MENUBAR) => MENUBAR,
|
false if layout.can_hold(MENUBAR) => MENUBAR,
|
||||||
false if layout.can_hold(MENUBAR_SHORT) => MENUBAR_SHORT,
|
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,
|
clear::AfterCursor,
|
||||||
style::NoFaint)?;
|
style::NoFaint)?;
|
||||||
|
|
Loading…
Reference in a new issue