summaryrefslogtreecommitdiff
path: root/src/watch.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-09-05 17:45:27 +0200
committermo8it <mo8it@proton.me>2024-09-05 17:45:27 +0200
commit9faa5d3aa48f7a94ed87e61ad6ea659579f1311a (patch)
treec841dada045258cfec968e664f848c879d1713b2 /src/watch.rs
parentbcc2a136c8b086a660b8e656c2cd9398f47435f4 (diff)
Avoid asking for terminal size on each rendering
Diffstat (limited to 'src/watch.rs')
-rw-r--r--src/watch.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/watch.rs b/src/watch.rs
index bca3832..900eba7 100644
--- a/src/watch.rs
+++ b/src/watch.rs
@@ -29,7 +29,7 @@ mod terminal_event;
enum WatchEvent {
Input(InputEvent),
FileChange { exercise_ind: usize },
- TerminalResize,
+ TerminalResize { width: u16 },
NotifyErr(notify::Error),
TerminalEventErr(io::Error),
}
@@ -72,7 +72,7 @@ fn run_watch(
None
};
- let mut watch_state = WatchState::new(app_state, manual_run);
+ let mut watch_state = WatchState::build(app_state, manual_run)?;
let mut stdout = io::stdout().lock();
watch_state.run_current_exercise(&mut stdout)?;
@@ -96,7 +96,9 @@ fn run_watch(
WatchEvent::FileChange { exercise_ind } => {
watch_state.handle_file_change(exercise_ind, &mut stdout)?;
}
- WatchEvent::TerminalResize => watch_state.render(&mut stdout)?,
+ WatchEvent::TerminalResize { width } => {
+ watch_state.update_term_width(width, &mut stdout)?;
+ }
WatchEvent::NotifyErr(e) => return Err(Error::from(e).context(NOTIFY_ERR)),
WatchEvent::TerminalEventErr(e) => {
return Err(Error::from(e).context("Terminal event listener failed"));