From b746400e0aafeb1651ce63c205839e49672e8a81 Mon Sep 17 00:00:00 2001 From: shy Date: Tue, 13 Apr 2021 11:37:01 +0200 Subject: [PATCH] Introduced "fancy" alarm display. --- src/alarm.rs | 66 +++++++++++++++++++++++++++++++++++++-------------- src/consts.rs | 2 +- src/lib.rs | 16 +++++++++---- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/alarm.rs b/src/alarm.rs index cc6aa02..9de034f 100644 --- a/src/alarm.rs +++ b/src/alarm.rs @@ -224,7 +224,8 @@ impl AlarmRoster { pub fn draw( &self, stdout: &mut RawTerminal, - 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; } diff --git a/src/consts.rs b/src/consts.rs index b1df914..461d5a6 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -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: Reset clock. diff --git a/src/lib.rs b/src/lib.rs index bab5b6f..e2d7ce7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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>, } @@ -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() {