diff --git a/src/alarm.rs b/src/alarm.rs index 0f1b8ea..fb049e0 100644 --- a/src/alarm.rs +++ b/src/alarm.rs @@ -27,7 +27,9 @@ impl Countdown { } // Draw countdown. - pub fn draw(&self, stdout: &mut RawTerminal) { + pub fn draw(&self, stdout: &mut RawTerminal) + -> 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, 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. diff --git a/src/lib.rs b/src/lib.rs index a03f24e..f4bb08a 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)?; // 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.