Propagate IO errors.
This commit is contained in:
parent
8112ecadb2
commit
b8b5f36ace
2 changed files with 15 additions and 14 deletions
25
src/alarm.rs
25
src/alarm.rs
|
@ -27,7 +27,9 @@ impl Countdown {
|
|||
}
|
||||
|
||||
// Draw countdown.
|
||||
pub fn draw<W: Write>(&self, stdout: &mut RawTerminal<W>) {
|
||||
pub fn draw<W: Write>(&self, stdout: &mut RawTerminal<W>)
|
||||
-> Result<(), std::io::Error>
|
||||
{
|
||||
if let Some(pos) = &self.position {
|
||||
if self.value < 3600 {
|
||||
// Show minutes and seconds.
|
||||
|
@ -35,12 +37,11 @@ impl Countdown {
|
|||
"{}(-{:02}:{:02})",
|
||||
cursor::Goto(pos.col, pos.line),
|
||||
(self.value / 60) % 60,
|
||||
self.value % 60)
|
||||
.unwrap();
|
||||
self.value % 60)?;
|
||||
if self.value == 3599 {
|
||||
// Write three additional spaces after switching from hour display to
|
||||
// minute display.
|
||||
write!(stdout, " ").unwrap();
|
||||
write!(stdout, " ")?;
|
||||
}
|
||||
} else {
|
||||
// Show hours, minutes and seconds.
|
||||
|
@ -49,10 +50,10 @@ impl Countdown {
|
|||
cursor::Goto(pos.col, pos.line),
|
||||
self.value / 3600,
|
||||
(self.value / 60) % 60,
|
||||
self.value % 60)
|
||||
.unwrap();
|
||||
self.value % 60)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,7 +225,8 @@ impl AlarmRoster {
|
|||
&self,
|
||||
stdout: &mut RawTerminal<W>,
|
||||
layout: &mut Layout
|
||||
) {
|
||||
) -> Result<(), std::io::Error>
|
||||
{
|
||||
let mut index = 0;
|
||||
|
||||
// Find first item to print in case we lack space to print them all.
|
||||
|
@ -240,7 +242,7 @@ impl AlarmRoster {
|
|||
"{}{}[...]{}",
|
||||
cursor::Goto(layout.roster.col, layout.roster.line),
|
||||
style::Faint,
|
||||
style::Reset).unwrap();
|
||||
style::Reset)?;
|
||||
}
|
||||
|
||||
for alarm in &self.list[first..] {
|
||||
|
@ -252,19 +254,18 @@ impl AlarmRoster {
|
|||
color::Bg(color::Reset),
|
||||
style::Bold,
|
||||
&alarm.label,
|
||||
style::Reset)
|
||||
.unwrap();
|
||||
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)
|
||||
.unwrap();
|
||||
&alarm.label)?;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Return width of roster.
|
||||
|
|
|
@ -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)?;
|
||||
|
||||
// Redraw buffer.
|
||||
buffer.draw(&mut stdout, &mut layout)?;
|
||||
|
@ -167,7 +167,7 @@ pub fn run(
|
|||
|
||||
// Display countdown.
|
||||
if countdown.value > 0 {
|
||||
countdown.draw(&mut stdout);
|
||||
countdown.draw(&mut stdout)?;
|
||||
}
|
||||
|
||||
// Check any spawned child process.
|
||||
|
|
Loading…
Reference in a new issue