Introduced "fancy" alarm display.
This commit is contained in:
parent
ce7f5a43ea
commit
b746400e0a
3 changed files with 60 additions and 24 deletions
66
src/alarm.rs
66
src/alarm.rs
|
@ -224,7 +224,8 @@ impl AlarmRoster {
|
||||||
pub fn draw<W: Write>(
|
pub fn draw<W: Write>(
|
||||||
&self,
|
&self,
|
||||||
stdout: &mut RawTerminal<W>,
|
stdout: &mut RawTerminal<W>,
|
||||||
layout: &mut Layout
|
layout: &mut Layout,
|
||||||
|
config: &Config,
|
||||||
) -> Result<(), std::io::Error>
|
) -> Result<(), std::io::Error>
|
||||||
{
|
{
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
@ -242,26 +243,55 @@ impl AlarmRoster {
|
||||||
"{}{}[...]{}",
|
"{}{}[...]{}",
|
||||||
cursor::Goto(layout.roster.col, layout.roster.line),
|
cursor::Goto(layout.roster.col, layout.roster.line),
|
||||||
style::Faint,
|
style::Faint,
|
||||||
style::Reset)?;
|
style::Reset,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for alarm in &self.list[first..] {
|
for alarm in &self.list[first..] {
|
||||||
if alarm.exceeded {
|
match alarm.exceeded {
|
||||||
write!(stdout,
|
true if config.fancy => {
|
||||||
"{}{} {}{} {}!{}",
|
write!(stdout,
|
||||||
cursor::Goto(layout.roster.col, layout.roster.line + index),
|
"{}{}{}{} {} {}🭬{}{}",
|
||||||
color::Bg(COLOR[alarm.color_index]),
|
cursor::Goto(layout.roster.col, layout.roster.line + index),
|
||||||
color::Bg(color::Reset),
|
color::Fg(COLOR[alarm.color_index]),
|
||||||
style::Bold,
|
style::Bold,
|
||||||
&alarm.label,
|
style::Invert,
|
||||||
style::Reset)?;
|
&alarm.label,
|
||||||
} else {
|
style::NoInvert,
|
||||||
write!(stdout,
|
color::Fg(color::Reset),
|
||||||
"{}{} {} {}",
|
style::Reset,
|
||||||
cursor::Goto(layout.roster.col, layout.roster.line + index),
|
)?;
|
||||||
color::Bg(COLOR[alarm.color_index]),
|
},
|
||||||
color::Bg(color::Reset),
|
false if config.fancy => {
|
||||||
&alarm.label)?;
|
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;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ OPTIONS:
|
||||||
be replaced by the alarm time in (HH:)MM:SS format.
|
be replaced by the alarm time in (HH:)MM:SS format.
|
||||||
Occurrences of {l} by alarm label.
|
Occurrences of {l} by alarm label.
|
||||||
-p, --plain Use simpler block chars to draw the clock.
|
-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.
|
-q, --quit Quit program after last alarm.
|
||||||
|
|
||||||
SIGNALS: <SIGUSR1> Reset clock.
|
SIGNALS: <SIGUSR1> Reset clock.
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -157,7 +157,7 @@ pub fn run(
|
||||||
style::NoFaint)?;
|
style::NoFaint)?;
|
||||||
|
|
||||||
// Redraw list of alarms.
|
// Redraw list of alarms.
|
||||||
alarm_roster.draw(&mut stdout, &mut layout)?;
|
alarm_roster.draw(&mut stdout, &mut layout, &config)?;
|
||||||
|
|
||||||
// Redraw buffer.
|
// Redraw buffer.
|
||||||
buffer.draw(&mut stdout, &mut layout)?;
|
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,
|
write!(stdout,
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
clear::BeforeCursor,
|
clear::All,
|
||||||
cursor::Goto(1, 1),
|
cursor::Restore,
|
||||||
cursor::Show)?;
|
cursor::Show)?;
|
||||||
|
stdout.flush()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
quit: bool,
|
quit: bool,
|
||||||
|
fancy: bool,
|
||||||
font: &'static font::Font,
|
font: &'static font::Font,
|
||||||
command: Option<Vec<String>>,
|
command: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
@ -329,6 +331,7 @@ impl Config {
|
||||||
{
|
{
|
||||||
let mut config = Config {
|
let mut config = Config {
|
||||||
quit: false,
|
quit: false,
|
||||||
|
fancy: false,
|
||||||
font: &font::NORMAL,
|
font: &font::NORMAL,
|
||||||
command: None,
|
command: None,
|
||||||
};
|
};
|
||||||
|
@ -347,7 +350,10 @@ impl Config {
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
},
|
},
|
||||||
"-p" | "--plain" => config.font = &font::PLAIN,
|
"-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,
|
"-q" | "--quit" => config.quit = true,
|
||||||
"-e" | "--exec" => {
|
"-e" | "--exec" => {
|
||||||
if let Some(e) = iter.next() {
|
if let Some(e) = iter.next() {
|
||||||
|
|
Loading…
Reference in a new issue