aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMroik <mroik@delayed.space>2025-10-08 02:49:57 +0200
committerMroik <mroik@delayed.space>2025-10-08 02:49:57 +0200
commit34650466d986b8f1077b8beffacb3ca210736942 (patch)
treedf9e1bdeadbd6bf7349d2b0ed15472fd7a0d1c73 /src
parentc31238e32953d7c0e81261f75f52ae5eb7e12174 (diff)
Update deps
Diffstat (limited to 'src')
-rw-r--r--src/app.rs64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/app.rs b/src/app.rs
index 88d50e4..45eca05 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -68,43 +68,14 @@ impl App<'_> {
}
}
- async fn format_quote(quote: &str, row_len: u16) -> Result<Vec<Vec<&str>>, WordTooLongError> {
- let max = if row_len - (MIN_MARGIN * 2) < MAX_QUOTE_LINE {
- row_len - (MIN_MARGIN * 2)
- } else {
- MAX_QUOTE_LINE
- };
- let mut counter = 0;
- let mut lines = Vec::new();
- let mut line = Vec::new();
- for w in quote.split_whitespace().filter(|s| !s.is_empty()) {
- let w_len = w.chars().count();
- if w_len > max as usize {
- return Err(WordTooLongError::new(w, max));
- }
-
- if w_len + counter > max as usize {
- lines.push(line);
- line = Vec::new();
- line.push(w);
- counter = w_len + 1;
- } else {
- line.push(w);
- counter += w_len + 1;
- }
- }
- lines.push(line);
- return Ok(lines);
- }
-
async fn run(&mut self) -> Result<(f64, f64, String), Box<dyn Error>> {
self.stdout
.execute(EnterAlternateScreen)?
.execute(SetCursorStyle::SteadyBar)?;
enable_raw_mode()?;
- let (input_ks_tx, input_ks_rx): (Sender<()>, Receiver<()>) = channel(1);
- let (tick_ks_tx, tick_ks_rx): (Sender<()>, Receiver<()>) = channel(1);
+ let (input_ks_tx, input_ks_rx) = channel(1);
+ let (tick_ks_tx, tick_ks_rx) = channel(1);
spawn(start_input_handler(self.event_tx.clone(), input_ks_rx));
spawn(start_tick_generator(self.event_tx.clone(), tick_ks_rx));
@@ -240,7 +211,7 @@ impl App<'_> {
self.running = false;
return Ok(());
}
- let lines = match App::format_quote(self.raw_quote, cols).await {
+ let lines = match format_quote(self.raw_quote, cols).await {
Ok(v) => v,
Err(e) => {
self.error = Some(TyperError::WordTooLongError(e));
@@ -391,3 +362,32 @@ async fn start_input_handler(ev: Sender<Event>, mut kill_switch: Receiver<()>) {
}
}
}
+
+async fn format_quote(quote: &str, row_len: u16) -> Result<Vec<Vec<&str>>, WordTooLongError> {
+ let max = if row_len - (MIN_MARGIN * 2) < MAX_QUOTE_LINE {
+ row_len - (MIN_MARGIN * 2)
+ } else {
+ MAX_QUOTE_LINE
+ };
+ let mut counter = 0;
+ let mut lines = Vec::new();
+ let mut line = Vec::new();
+ for w in quote.split_whitespace().filter(|s| !s.is_empty()) {
+ let w_len = w.chars().count();
+ if w_len > max as usize {
+ return Err(WordTooLongError::new(w, max));
+ }
+
+ if w_len + counter > max as usize {
+ lines.push(line);
+ line = Vec::new();
+ line.push(w);
+ counter = w_len + 1;
+ } else {
+ line.push(w);
+ counter += w_len + 1;
+ }
+ }
+ lines.push(line);
+ return Ok(lines);
+}
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj