Skip to content

Commit 321b826

Browse files
committed
fix codestyle
1 parent 75c11f5 commit 321b826

File tree

4 files changed

+30
-45
lines changed

4 files changed

+30
-45
lines changed

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod tui;
55
use crate::man_db::ManDb;
66
use anyhow::Result;
77
use clap::{Parser, Subcommand};
8-
use tokio;
98

109
/// CLI for browsing man pages and tldr cheatsheets
1110
#[derive(Parser)]
@@ -35,7 +34,7 @@ fn main() -> Result<()> {
3534
match cli.command {
3635
Some(Commands::Getmans { prefix }) => {
3736
for word in man_db.commands_starting_with(&prefix) {
38-
println!("{}", word);
37+
println!("{word}");
3938
}
4039
}
4140
Some(Commands::Getman { command }) => {
@@ -52,7 +51,7 @@ fn main() -> Result<()> {
5251

5352
#[cfg(test)]
5453
mod cli_tests {
55-
use super::*;
54+
5655
use std::process::Command;
5756

5857
#[test]

src/man_db.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,9 @@ impl ManDb {
194194
#[cfg(test)]
195195
mod man_db_tests {
196196
use super::*;
197-
use std::collections::HashMap;
197+
198198
use tokio::runtime::Runtime;
199199

200-
const MOCK_MAN_OUTPUT: &str = "
201-
ls (1) - list directory contents
202-
git (1) - the stupid content tracker
203-
printf (3) - formatted output conversion
204-
printf (1) - format and print data
205-
docker-compose (1) - define and run multi-container applications
206-
";
207200
#[test]
208201
fn test_cache_behavior() {
209202
let rt = Runtime::new().unwrap();

src/trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Trie {
3939
pub fn insert(&mut self, word: &str) {
4040
let mut node = &mut self.root;
4141
for c in word.chars() {
42-
node = node.children.entry(c).or_insert_with(TrieNode::new);
42+
node = node.children.entry(c).or_default();
4343
}
4444
node.is_word = true;
4545
}

src/tui.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,39 +122,33 @@ pub async fn run_tui(man_db: ManDb) -> Result<()> {
122122
terminal.draw(|f| render_ui(f, &mut app))?;
123123

124124
if event::poll(Duration::from_millis(16))? {
125-
match event::read()? {
126-
Event::Key(key) => {
127-
if key.kind != KeyEventKind::Press {
128-
continue;
129-
}
125+
if let Event::Key(key) = event::read()? {
126+
if key.kind != KeyEventKind::Press {
127+
continue;
128+
}
130129

131-
// Handle Ctrl combinations first
132-
match key {
133-
KeyEvent {
134-
code: KeyCode::Char('c'),
135-
modifiers: KeyModifiers::CONTROL,
136-
..
137-
} => break,
138-
_ => {}
130+
// Handle Ctrl combinations first
131+
if let KeyEvent {
132+
code: KeyCode::Char('c'),
133+
modifiers: KeyModifiers::CONTROL,
134+
..
135+
} = key { break }
136+
137+
match key.code {
138+
KeyCode::Char('q') => break,
139+
KeyCode::Tab => toggle_focus(&mut app),
140+
KeyCode::Esc => app.focus = Focus::CommandList,
141+
KeyCode::Char('/') if matches!(app.focus, Focus::ManPage) => {
142+
app.focus = Focus::Search;
143+
app.search.query.clear();
139144
}
140-
141-
match key.code {
142-
KeyCode::Char('q') => break,
143-
KeyCode::Tab => toggle_focus(&mut app),
144-
KeyCode::Esc => app.focus = Focus::CommandList,
145-
KeyCode::Char('/') if matches!(app.focus, Focus::ManPage) => {
146-
app.focus = Focus::Search;
147-
app.search.query.clear();
148-
}
149-
KeyCode::Char('t') if matches!(app.focus, Focus::ManPage) => {
150-
toggle_page_source(&mut app);
151-
app.pending_man_load = true;
152-
app.last_input_time = Instant::now();
153-
}
154-
_ => handle_key(&mut app, key).await,
145+
KeyCode::Char('t') if matches!(app.focus, Focus::ManPage) => {
146+
toggle_page_source(&mut app);
147+
app.pending_man_load = true;
148+
app.last_input_time = Instant::now();
155149
}
150+
_ => handle_key(&mut app, key).await,
156151
}
157-
_ => {}
158152
}
159153
}
160154

@@ -418,11 +412,10 @@ fn render_status_bar<B: tui::backend::Backend>(f: &mut tui::Frame<B>, app: &AppS
418412
};
419413

420414
let status = if app.loading {
421-
format!("Loading {}...", source_label)
415+
format!("Loading {source_label}...")
422416
} else {
423417
let x = &*format!(
424-
"RTFM // {} PAGE [Tab:Switch /:Search n/N:Next/Prev t:Toggle]",
425-
source_label
418+
"RTFM // {source_label} PAGE [Tab:Switch /:Search n/N:Next/Prev t:Toggle]"
426419
);
427420
match app.focus {
428421
Focus::CommandList => "RTFM // COMMAND LIST [Tab:Switch]",
@@ -510,7 +503,7 @@ fn render_command_list_items<B: tui::backend::Backend>(
510503
.iter()
511504
.map(|cmd| {
512505
let prefix = { " " };
513-
ListItem::new(format!("{}{}", prefix, cmd))
506+
ListItem::new(format!("{prefix}{cmd}"))
514507
})
515508
.collect();
516509

0 commit comments

Comments
 (0)