From a088fb39422100c13d825e2220acb3282d8bd5e0 Mon Sep 17 00:00:00 2001 From: Mroik Date: Wed, 29 Jan 2025 20:45:40 +0100 Subject: Move error logic into its own crate --- src/app.rs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index f92cc67..efb232e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,6 @@ use std::{ collections::HashSet, error::Error, - fmt::Display, io::{stdout, Stdout, Write}, time::Duration, }; @@ -22,6 +21,7 @@ use tokio::{ }; use crate::{ + error::WordTooLongError, event::{handle_input, Event}, state::State, }; @@ -31,28 +31,6 @@ const MIN_TERM_COL: u16 = 65; const MIN_TERM_ROW: u16 = 15; const MAX_QUOTE_LINE: u16 = 80; -#[derive(Debug)] -struct WordTooLongError { - word: String, -} - -impl WordTooLongError { - fn new(word: impl Into) -> WordTooLongError { - WordTooLongError { word: word.into() } - } -} - -impl Display for WordTooLongError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!( - "The word \"{}\" is too long for the current terminal size", - self.word - )) - } -} - -impl Error for WordTooLongError {} - trait Substringable<'a> { fn substring(&'a self, start: usize, end: usize) -> Option<&'a str>; } @@ -74,7 +52,6 @@ pub struct App<'a> { pub event_tx: Sender, event_rx: Receiver, running: bool, - raw_quote: &'a str, quote: Vec<&'a str>, state: State, should_render: bool, @@ -85,12 +62,10 @@ pub struct App<'a> { } impl App<'_> { - // TODO Format quote pub fn new(quote: &str) -> App { let (event_tx, event_rx): (Sender, Receiver) = channel(10); App { stdout: stdout(), - raw_quote: quote, quote: quote.split_whitespace().filter(|s| !s.is_empty()).collect(), event_rx, event_tx, @@ -217,7 +192,6 @@ impl App<'_> { return a.join(" "); } - // TODO Reformat quote on ForceRender async fn process(&mut self) -> Result<(), Box> { let event = self.event_rx.recv().await.unwrap(); match event { @@ -286,6 +260,7 @@ impl App<'_> { } } + // TODO Reformat quote async fn render(&mut self) -> Result<(), Box> { if !self.should_render { return Ok(()); -- cgit v1.3