From a7c6cf2f59381c4780d18dd0154b6b7371c350c6 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 29 Jan 2025 23:06:42 +0100 Subject: [PATCH] style(main): consistent brace omittal --- src/main.rs | 91 +++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/src/main.rs b/src/main.rs index 37d2f2d..0efd5a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ use rustyline::error::ReadlineError; use rustyline::DefaultEditor; use std::collections::{HashMap, VecDeque}; use std::env; -use std::env::{args}; +use std::env::args; use std::fs; use std::fs::File; use std::io::{BufRead, BufReader, Write}; @@ -469,7 +469,7 @@ async fn main() -> Result<()> { if tasks.custom_time.is_none() { tasks.move_up(); } } - Some('&') => { + Some('&') => match arg { None => tasks.undo(), Some(text) => { @@ -506,9 +506,8 @@ async fn main() -> Result<()> { } } } - } - Some('@') => { + Some('@') => match arg { None => { let today = Timestamp::now() - 80_000; @@ -538,10 +537,9 @@ async fn main() -> Result<()> { } } } - }; - } + } - Some('*') => { + Some('*') => match arg { None => match tasks.get_position() { None => { @@ -565,7 +563,6 @@ async fn main() -> Result<()> { } } } - } Some('|') => match arg { @@ -590,13 +587,12 @@ async fn main() -> Result<()> { } } - Some('?') => { + Some('?') => match arg { None => tasks.set_state_filter(StateFilter::Default), Some("?") => tasks.set_state_filter(StateFilter::All), Some(arg) => tasks.set_state_filter(StateFilter::State(arg.to_string())), } - } Some('!') => match tasks.get_position() { @@ -631,11 +627,10 @@ async fn main() -> Result<()> { } } - Some('#') => { + Some('#') => if !tasks.update_tags(arg_default.split_whitespace().map(Hashtag::from)) { continue; } - } Some('+') => match arg { @@ -681,7 +676,7 @@ async fn main() -> Result<()> { continue 'repl; } - Some(')') => { + Some(')') => match arg { None => tasks.move_to(None), Some(arg) => { @@ -693,7 +688,6 @@ async fn main() -> Result<()> { continue 'repl; } } - } Some('.') => { let (remaining, dots) = trim_start_count(&command, '.'); @@ -722,46 +716,47 @@ async fn main() -> Result<()> { } } - Some('/') => if arg.is_none() { - tasks.move_to(None); - } else { - let (remaining, dots) = trim_start_count(&command, '/'); - let pos = tasks.up_by(dots - 1); - - if remaining.is_empty() { - tasks.move_to(pos); - if dots > 1 { - info!("Moving up {} tasks", dots - 1) - } - } else if let Ok(depth) = remaining.parse::() { - if pos != tasks.get_position() { - tasks.move_to(pos); - } - tasks.set_search_depth(depth); + Some('/') => + if arg.is_none() { + tasks.move_to(None); } else { - // TODO regex match - let mut transform: Box String> = Box::new(|s: &str| s.to_string()); - if !remaining.chars().any(|c| c.is_ascii_uppercase()) { - // Smart-case - case-sensitive if any uppercase char is entered - transform = Box::new(|s| s.to_ascii_lowercase()); - } + let (remaining, dots) = trim_start_count(&command, '/'); + let pos = tasks.up_by(dots - 1); - let filtered = - tasks.get_filtered(pos, |t| { - transform(&t.get_title()).contains(&remaining) || - t.list_hashtags().any( - |tag| tag.contains(&remaining)) - }); - if filtered.len() == 1 { - tasks.move_to(filtered.into_iter().next()); - } else { + if remaining.is_empty() { tasks.move_to(pos); - if !tasks.set_view(filtered) { - continue 'repl; + if dots > 1 { + info!("Moving up {} tasks", dots - 1) + } + } else if let Ok(depth) = remaining.parse::() { + if pos != tasks.get_position() { + tasks.move_to(pos); + } + tasks.set_search_depth(depth); + } else { + // TODO regex match + let mut transform: Box String> = Box::new(|s: &str| s.to_string()); + if !remaining.chars().any(|c| c.is_ascii_uppercase()) { + // Smart-case - case-sensitive if any uppercase char is entered + transform = Box::new(|s| s.to_ascii_lowercase()); + } + + let filtered = + tasks.get_filtered(pos, |t| { + transform(&t.get_title()).contains(&remaining) || + t.list_hashtags().any( + |tag| tag.contains(&remaining)) + }); + if filtered.len() == 1 { + tasks.move_to(filtered.into_iter().next()); + } else { + tasks.move_to(pos); + if !tasks.set_view(filtered) { + continue 'repl; + } } } } - } _ => if Regex::new("^wss?://").unwrap().is_match(command.trim()) {