Introduced "fancy" alarm display.

This commit is contained in:
shy 2021-04-13 11:37:01 +02:00
parent ce7f5a43ea
commit b746400e0a
3 changed files with 60 additions and 24 deletions

View file

@ -224,7 +224,8 @@ impl AlarmRoster {
pub fn draw<W: Write>(
&self,
stdout: &mut RawTerminal<W>,
layout: &mut Layout
layout: &mut Layout,
config: &Config,
) -> Result<(), std::io::Error>
{
let mut index = 0;
@ -242,26 +243,55 @@ impl AlarmRoster {
"{}{}[...]{}",
cursor::Goto(layout.roster.col, layout.roster.line),
style::Faint,
style::Reset)?;
style::Reset,
)?;
}
for alarm in &self.list[first..] {
if alarm.exceeded {
write!(stdout,
"{}{} {}{} {}!{}",
cursor::Goto(layout.roster.col, layout.roster.line + index),
color::Bg(COLOR[alarm.color_index]),
color::Bg(color::Reset),
style::Bold,
&alarm.label,
style::Reset)?;
} else {
write!(stdout,
"{}{} {} {}",
cursor::Goto(layout.roster.col, layout.roster.line + index),
color::Bg(COLOR[alarm.color_index]),
color::Bg(color::Reset),
&alarm.label)?;
match alarm.exceeded {
true if config.fancy => {
write!(stdout,
"{}{}{}{} {} {}🭬{}{}",
cursor::Goto(layout.roster.col, layout.roster.line + index),
color::Fg(COLOR[alarm.color_index]),
style::Bold,
style::Invert,
&alarm.label,
style::NoInvert,
color::Fg(color::Reset),
style::Reset,
)?;
},
false if config.fancy => {
write!(stdout,
"{}{}█🭬{}{}",
cursor::Goto(layout.roster.col, layout.roster.line + index),
color::Fg(COLOR[alarm.color_index]),
color::Fg(color::Reset),
&alarm.label,
)?;
},
true => {
write!(stdout,
"{}{}{}{} {} {}{}",
cursor::Goto(layout.roster.col, layout.roster.line + index),
color::Fg(COLOR[alarm.color_index]),
style::Bold,
style::Invert,
&alarm.label,
color::Fg(color::Reset),
style::Reset,
)?;
},
false => {
write!(stdout,
"{}{} {} {}",
cursor::Goto(layout.roster.col, layout.roster.line + index),
color::Bg(COLOR[alarm.color_index]),
color::Bg(color::Reset),
&alarm.label,
)?;
},
}
index += 1;
}

View file

@ -28,7 +28,7 @@ OPTIONS:
be replaced by the alarm time in (HH:)MM:SS format.
Occurrences of {l} by alarm label.
-p, --plain Use simpler block chars to draw the clock.
-f, --fancy Use fancy clock style.
-f, --fancy Make use of less common unicode characters.
-q, --quit Quit program after last alarm.
SIGNALS: <SIGUSR1> Reset clock.

View file

@ -157,7 +157,7 @@ pub fn run(
style::NoFaint)?;
// Redraw list of alarms.
alarm_roster.draw(&mut stdout, &mut layout)?;
alarm_roster.draw(&mut stdout, &mut layout, &config)?;
// Redraw buffer.
buffer.draw(&mut stdout, &mut layout)?;
@ -306,18 +306,20 @@ pub fn run(
}
}
// Main loop exited. Clear window and restore cursor.
// Main loop exited. Clear screen and restore cursor.
write!(stdout,
"{}{}{}",
clear::BeforeCursor,
cursor::Goto(1, 1),
clear::All,
cursor::Restore,
cursor::Show)?;
stdout.flush()?;
Ok(())
}
pub struct Config {
quit: bool,
fancy: bool,
font: &'static font::Font,
command: Option<Vec<String>>,
}
@ -329,6 +331,7 @@ impl Config {
{
let mut config = Config {
quit: false,
fancy: false,
font: &font::NORMAL,
command: None,
};
@ -347,7 +350,10 @@ impl Config {
process::exit(0);
},
"-p" | "--plain" => config.font = &font::PLAIN,
"-f" | "--fancy" => config.font = &font::CHROME,
"-f" | "--fancy" => {
config.fancy = true;
config.font = &font::CHROME;
},
"-q" | "--quit" => config.quit = true,
"-e" | "--exec" => {
if let Some(e) = iter.next() {