Move signal handling to end of main loop.
This commit is contained in:
parent
5d6456b582
commit
b3acafc090
1 changed files with 31 additions and 30 deletions
61
src/lib.rs
61
src/lib.rs
|
@ -78,36 +78,6 @@ pub fn run(
|
||||||
|
|
||||||
// Main loop entry.
|
// Main loop entry.
|
||||||
'main: loop {
|
'main: loop {
|
||||||
// Process received signals.
|
|
||||||
for signal in signals.pending() {
|
|
||||||
match signal {
|
|
||||||
// Suspend execution on SIGTSTP.
|
|
||||||
SIGTSTP => suspend(&mut stdout)?,
|
|
||||||
// Continuing after SIGTSTP or SIGSTOP.
|
|
||||||
SIGCONT => {
|
|
||||||
restore_after_suspend(&mut stdout)?;
|
|
||||||
force_redraw = true;
|
|
||||||
}
|
|
||||||
SIGWINCH => layout.schedule_recalc(),
|
|
||||||
// Exit main loop on SIGTERM and SIGINT.
|
|
||||||
SIGTERM | SIGINT => break 'main,
|
|
||||||
// Reset clock on SIGUSR1.
|
|
||||||
SIGUSR1 => {
|
|
||||||
clock.reset();
|
|
||||||
alarm_roster.reset_all();
|
|
||||||
layout.schedule_recalc();
|
|
||||||
force_redraw = true;
|
|
||||||
}
|
|
||||||
// (Un-)Pause clock on SIGUSR2.
|
|
||||||
SIGUSR2 => {
|
|
||||||
clock.toggle();
|
|
||||||
force_redraw = true;
|
|
||||||
}
|
|
||||||
// We didn't register anything else.
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update elapsed time.
|
// Update elapsed time.
|
||||||
let elapsed = if clock.paused {
|
let elapsed = if clock.paused {
|
||||||
clock.elapsed
|
clock.elapsed
|
||||||
|
@ -340,6 +310,37 @@ pub fn run(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process received signals.
|
||||||
|
for signal in signals.pending() {
|
||||||
|
match signal {
|
||||||
|
// Suspend execution on SIGTSTP.
|
||||||
|
SIGTSTP => suspend(&mut stdout)?,
|
||||||
|
// Continuing after SIGTSTP or SIGSTOP.
|
||||||
|
SIGCONT => {
|
||||||
|
restore_after_suspend(&mut stdout)?;
|
||||||
|
force_redraw = true;
|
||||||
|
}
|
||||||
|
SIGWINCH => layout.schedule_recalc(),
|
||||||
|
// Exit main loop on SIGTERM and SIGINT.
|
||||||
|
SIGTERM | SIGINT => break 'main,
|
||||||
|
// Reset clock on SIGUSR1.
|
||||||
|
SIGUSR1 => {
|
||||||
|
clock.reset();
|
||||||
|
alarm_roster.reset_all();
|
||||||
|
layout.schedule_recalc();
|
||||||
|
force_redraw = true;
|
||||||
|
}
|
||||||
|
// (Un-)Pause clock on SIGUSR2.
|
||||||
|
SIGUSR2 => {
|
||||||
|
clock.toggle();
|
||||||
|
force_redraw = true;
|
||||||
|
}
|
||||||
|
// We didn't register anything else.
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main loop exited. Clear screen and restore cursor.
|
// Main loop exited. Clear screen and restore cursor.
|
||||||
|
|
Loading…
Reference in a new issue