From f77e41d526a64af26508d590a4a08426290aa7e5 Mon Sep 17 00:00:00 2001 From: Mroik Date: Mon, 16 Feb 2026 05:55:55 +0100 Subject: Add permanent quote file support Quote file can be placed under `$HOME/.config/marika-finger-blaster/quotes.json` --- src/app.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index d5edae0..6a0044b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,10 +1,10 @@ use std::{ collections::HashSet, - error::Error, io::{Stdout, Write, stdout}, time::Duration, }; +use anyhow::Result; use crossterm::{ ExecutableCommand, QueueableCommand, cursor::{MoveDown, MoveTo, MoveToColumn, RestorePosition, SavePosition, SetCursorStyle}, @@ -21,6 +21,7 @@ use tokio::{ }; use crate::{ + config::Quote, error::{TerminalTooSmallError, TyperError, WordTooLongError}, input::{Event, handle_input}, state::State, @@ -49,8 +50,9 @@ pub struct App<'a> { } impl App<'_> { - pub fn new(quote: &str) -> App<'_> { + pub fn new(quote: &Quote) -> App<'_> { let (event_tx, event_rx): (Sender, Receiver) = channel(10); + let quote = quote.text.as_str(); App { stdout: stdout(), quote: quote.split_whitespace().filter(|s| !s.is_empty()).collect(), @@ -68,7 +70,7 @@ impl App<'_> { } } - async fn run(&mut self) -> Result<(f64, f64, String), Box> { + async fn run(&mut self) -> Result<(f64, f64, String)> { self.stdout .execute(EnterAlternateScreen)? .execute(SetCursorStyle::SteadyBar)?; @@ -99,7 +101,7 @@ impl App<'_> { return Ok((wpm, accuracy, history)); } - pub async fn start(&mut self) -> Result<(), Box> { + pub async fn start(&mut self) -> Result<()> { let (wpm, accuracy, history) = self.run().await?; if self.completed { println!( @@ -144,7 +146,7 @@ impl App<'_> { return a.join(" "); } - async fn process(&mut self) -> Result<(), Box> { + async fn process(&mut self) -> Result<()> { let event = self.event_rx.recv().await.unwrap(); match event { Event::Terminate => self.running = false, @@ -160,7 +162,7 @@ impl App<'_> { return Ok(()); } - async fn handle_keypress(&mut self, k: char) -> Result<(), Box> { + async fn handle_keypress(&mut self, k: char) -> Result<()> { self.state.buffer.push(k); let buffer_length = self.state.buffer.chars().count(); let current_word = self.quote[self.state.current]; @@ -195,7 +197,7 @@ impl App<'_> { } } - async fn render(&mut self) -> Result<(), Box> { + async fn render(&mut self) -> Result<()> { if !self.should_render { return Ok(()); } -- cgit v1.3