Propagate IO errors.

This commit is contained in:
shy 2021-04-12 20:15:40 +02:00
parent 8112ecadb2
commit b8b5f36ace
2 changed files with 15 additions and 14 deletions

View file

@ -27,7 +27,9 @@ impl Countdown {
} }
// Draw 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 let Some(pos) = &self.position {
if self.value < 3600 { if self.value < 3600 {
// Show minutes and seconds. // Show minutes and seconds.
@ -35,12 +37,11 @@ impl Countdown {
"{}(-{:02}:{:02})", "{}(-{:02}:{:02})",
cursor::Goto(pos.col, pos.line), cursor::Goto(pos.col, pos.line),
(self.value / 60) % 60, (self.value / 60) % 60,
self.value % 60) self.value % 60)?;
.unwrap();
if self.value == 3599 { if self.value == 3599 {
// Write three additional spaces after switching from hour display to // Write three additional spaces after switching from hour display to
// minute display. // minute display.
write!(stdout, " ").unwrap(); write!(stdout, " ")?;
} }
} else { } else {
// Show hours, minutes and seconds. // Show hours, minutes and seconds.
@ -49,10 +50,10 @@ impl Countdown {
cursor::Goto(pos.col, pos.line), cursor::Goto(pos.col, pos.line),
self.value / 3600, self.value / 3600,
(self.value / 60) % 60, (self.value / 60) % 60,
self.value % 60) self.value % 60)?;
.unwrap();
} }
} }
Ok(())
} }
} }
@ -224,7 +225,8 @@ impl AlarmRoster {
&self, &self,
stdout: &mut RawTerminal<W>, stdout: &mut RawTerminal<W>,
layout: &mut Layout layout: &mut Layout
) { ) -> Result<(), std::io::Error>
{
let mut index = 0; let mut index = 0;
// Find first item to print in case we lack space to print them all. // 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), cursor::Goto(layout.roster.col, layout.roster.line),
style::Faint, style::Faint,
style::Reset).unwrap(); style::Reset)?;
} }
for alarm in &self.list[first..] { for alarm in &self.list[first..] {
@ -252,19 +254,18 @@ impl AlarmRoster {
color::Bg(color::Reset), color::Bg(color::Reset),
style::Bold, style::Bold,
&alarm.label, &alarm.label,
style::Reset) style::Reset)?;
.unwrap();
} else { } else {
write!(stdout, write!(stdout,
"{}{} {} {}", "{}{} {} {}",
cursor::Goto(layout.roster.col, layout.roster.line + index), cursor::Goto(layout.roster.col, layout.roster.line + index),
color::Bg(COLOR[alarm.color_index]), color::Bg(COLOR[alarm.color_index]),
color::Bg(color::Reset), color::Bg(color::Reset),
&alarm.label) &alarm.label)?;
.unwrap();
} }
index += 1; index += 1;
} }
Ok(())
} }
// Return width of roster. // Return width of roster.

View file

@ -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)?;
// Redraw buffer. // Redraw buffer.
buffer.draw(&mut stdout, &mut layout)?; buffer.draw(&mut stdout, &mut layout)?;
@ -167,7 +167,7 @@ pub fn run(
// Display countdown. // Display countdown.
if countdown.value > 0 { if countdown.value > 0 {
countdown.draw(&mut stdout); countdown.draw(&mut stdout)?;
} }
// Check any spawned child process. // Check any spawned child process.