Start list without Ratatui

This commit is contained in:
mo8it
2024-08-24 00:14:12 +02:00
parent 47976caa69
commit 570bc9f32d
14 changed files with 303 additions and 500 deletions
+8 -6
View File
@@ -1,5 +1,5 @@
use anyhow::Result;
use ratatui::crossterm::{
use crossterm::{
style::{style, Stylize},
terminal,
};
@@ -76,7 +76,8 @@ impl<'a> WatchState<'a> {
self.done_status = DoneStatus::Pending;
}
self.render()
self.render()?;
Ok(())
}
pub fn handle_file_change(&mut self, exercise_ind: usize) -> Result<()> {
@@ -120,7 +121,7 @@ impl<'a> WatchState<'a> {
self.writer.flush()
}
pub fn render(&mut self) -> Result<()> {
pub fn render(&mut self) -> io::Result<()> {
// Prevent having the first line shifted if clearing wasn't successful.
self.writer.write_all(b"\n")?;
clear_terminal(&mut self.writer)?;
@@ -155,14 +156,15 @@ impl<'a> WatchState<'a> {
}
let line_width = terminal::size()?.0;
let progress_bar = progress_bar(
progress_bar(
&mut self.writer,
self.app_state.n_done(),
self.app_state.exercises().len() as u16,
line_width,
)?;
writeln!(
self.writer,
"{progress_bar}Current exercise: {}",
"\nCurrent exercise: {}",
self.app_state.current_exercise().terminal_link(),
)?;
@@ -171,7 +173,7 @@ impl<'a> WatchState<'a> {
Ok(())
}
pub fn show_hint(&mut self) -> Result<()> {
pub fn show_hint(&mut self) -> io::Result<()> {
self.show_hint = true;
self.render()
}
+2 -2
View File
@@ -1,4 +1,4 @@
use ratatui::crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
use std::sync::mpsc::Sender;
use super::WatchEvent;
@@ -78,7 +78,7 @@ pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
return;
}
}
Event::FocusGained | Event::FocusLost | Event::Mouse(_) | Event::Paste(_) => continue,
Event::FocusGained | Event::FocusLost | Event::Mouse(_) => continue,
}
};