Skip to content

Commit

Permalink
chore(clippy): apply fixes automatically
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Nov 20, 2024
1 parent 99d28fa commit a0e9105
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Application for RusticApp {
self.state.components_mut().after_config(&config)?;

// set all given environment variables
for (env, value) in config.global.env.iter() {
for (env, value) in &config.global.env {
env::set_var(env, value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl CopyCmd {

let mut table =
table_with_titles(["ID", "Time", "Host", "Label", "Tags", "Paths", "Status"]);
for CopySnapshot { relevant, sn } in snaps.iter() {
for CopySnapshot { relevant, sn } in &snaps {
let tags = sn.tags.formatln();
let paths = sn.paths.formatln();
let time = sn.time.format("%Y-%m-%d %H:%M:%S").to_string();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl AddCmd {

let pass = pass_opts
.evaluate_password()
.map_err(|err| err.into())
.map_err(Into::into)
.transpose()
.unwrap_or_else(|| -> Result<_> {
Ok(Password::new()
Expand Down
11 changes: 5 additions & 6 deletions src/commands/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ impl NodeLs for Node {
},
self.meta
.mode
.map(parse_permissions)
.unwrap_or_else(|| "?????????".to_string())
.map_or_else(|| "?????????".to_string(), parse_permissions)
)
}
fn link_str(&self) -> String {
Expand Down Expand Up @@ -201,10 +200,10 @@ pub fn print_node(node: &Node, path: &Path, numeric_uid_gid: bool) {
}
.unwrap_or_else(|| "?".to_string()),
node.meta.size,
node.meta
.mtime
.map(|t| t.format("%_d %b %Y %H:%M").to_string())
.unwrap_or_else(|| "?".to_string()),
node.meta.mtime.map_or_else(
|| "?".to_string(),
|t| t.format("%_d %b %Y %H:%M").to_string()
),
node.link_str(),
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ fn run_app<B: Backend, P: ProgressBars, S: IndexedFull>(
loop {
_ = terminal.write().unwrap().draw(|f| ui(f, &mut app))?;
let event = event::read()?;
use KeyCode::*;

if let Event::Key(KeyEvent {
code: Char('c'),
code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL,
kind: KeyEventKind::Press,
..
Expand Down
22 changes: 12 additions & 10 deletions src/commands/tui/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::path::{Path, PathBuf};

use anyhow::Result;
use crossterm::event::{Event, KeyCode, KeyEventKind};
use ratatui::{prelude::*, widgets::*};
use ratatui::{
prelude::*,
widgets::{Block, Borders, Paragraph},
};
use rustic_core::{
repofile::{Node, SnapshotFile, Tree},
vfs::OpenFile,
Expand Down Expand Up @@ -35,7 +38,7 @@ enum CurrentScreen<'a, P, S> {
const INFO_TEXT: &str =
"(Esc) quit | (Enter) enter dir | (Backspace) return to parent | (v) view | (r) restore | (?) show all commands";

const HELP_TEXT: &str = r#"
const HELP_TEXT: &str = r"
General Commands:
q,Esc : exit
Expand All @@ -46,7 +49,7 @@ General Commands:
n : toggle numeric IDs
? : show this help page
"#;
";

pub(crate) struct Snapshot<'a, P, S> {
current_screen: CurrentScreen<'a, P, S>,
Expand Down Expand Up @@ -105,11 +108,10 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
};
let name = node.name().to_string_lossy().to_string();
let size = node.meta.size.to_string();
let mtime = node
.meta
.mtime
.map(|t| format!("{}", t.format("%Y-%m-%d %H:%M:%S")))
.unwrap_or_else(|| "?".to_string());
let mtime = node.meta.mtime.map_or_else(
|| "?".to_string(),
|t| format!("{}", t.format("%Y-%m-%d %H:%M:%S")),
);
[name, size, node.mode_str(), user, group, mtime]
.into_iter()
.map(Text::from)
Expand Down Expand Up @@ -188,7 +190,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
}

pub fn input(&mut self, event: Event) -> Result<SnapshotResult> {
use KeyCode::*;
use KeyCode::{Backspace, Char, Enter, Esc, Left, Right};
match &mut self.current_screen {
CurrentScreen::Snapshot => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => match key.code {
Expand Down Expand Up @@ -271,7 +273,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
},
CurrentScreen::ShowHelp(_) => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => {
if matches!(key.code, Char('q') | Esc | Enter | Char(' ') | Char('?')) {
if matches!(key.code, Char('q' | ' ' | '?') | Esc | Enter) {
self.current_screen = CurrentScreen::Snapshot;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tui/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl TuiProgress {
};
let eta = match ratio {
r if r < 0.01 => " ETA: -".to_string(),
r if r > 0.999999 => String::new(),
r if r > 0.999_999 => String::new(),
r => {
format!(
" ETA: {}",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/tui/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) struct Restore<'a, P, S> {
impl<'a, P: ProgressBars, S: IndexedFull> Restore<'a, P, S> {
pub fn new(repo: &'a Repository<P, S>, node: Node, source: String, path: &str) -> Self {
let opts = RestoreOptions::default();
let title = format!("restore {} to:", source);
let title = format!("restore {source} to:");
let popup = popup_input(title, "enter restore destination", path, 1);
Self {
current_screen: CurrentScreen::GetDestination(popup),
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Restore<'a, P, S> {
}

pub fn input(&mut self, event: Event) -> Result<bool> {
use KeyCode::*;
use KeyCode::{Char, Enter, Esc};
match &mut self.current_screen {
CurrentScreen::GetDestination(prompt) => match prompt.input(event) {
TextInputResult::Cancel => return Ok(true),
Expand Down Expand Up @@ -139,7 +139,7 @@ Do you want to proceed (y/n)?
},
CurrentScreen::RestoreDone(_) => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => {
if matches!(key.code, Char('q') | Esc | Enter | Char(' ')) {
if matches!(key.code, Char('q' | ' ') | Esc | Enter) {
return Ok(true);
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/commands/tui/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use anyhow::Result;
use chrono::Local;
use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers};
use itertools::Itertools;
use ratatui::{prelude::*, widgets::*};
use ratatui::{
prelude::*,
widgets::{Block, Borders, Paragraph},
};
use rustic_core::{
repofile::{DeleteOption, SnapshotFile},
IndexedFull, ProgressBars, Repository, SnapshotGroup, SnapshotGroupCriterion, StringList,
Expand Down Expand Up @@ -74,7 +77,7 @@ enum SnapshotNode {
const INFO_TEXT: &str =
"(Esc) quit | (F5) reload snapshots | (Enter) show contents | (v) toggle view | (i) show snapshot | (?) show all commands";

const HELP_TEXT: &str = r#"General Commands:
const HELP_TEXT: &str = r"General Commands:
q, Esc : exit
F5 : re-read all snapshots from repository
Enter : show snapshot contents
Expand Down Expand Up @@ -105,7 +108,7 @@ const HELP_TEXT: &str = r#"General Commands:
r : remove tag(s) for snapshot(s)
p : set delete protection for snapshot(s)
Ctrl-p : remove delete protection for snapshot(s)
"#;
";

pub(crate) struct Snapshots<'a, P, S> {
current_screen: CurrentScreen<'a, P, S>,
Expand Down Expand Up @@ -362,11 +365,11 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
let paths = group
.paths
.as_ref()
.map_or_else(String::default, |p| p.formatln());
.map_or_else(String::default, StringList::formatln);
let tags = group
.tags
.as_ref()
.map_or_else(String::default, |t| t.formatln());
.map_or_else(String::default, StringList::formatln);
[
mark.to_string(),
format!("{collapse}{modified}{del}group"),
Expand Down Expand Up @@ -437,7 +440,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}

pub fn clear_marks(&mut self) {
for status in self.snaps_status.iter_mut() {
for status in &mut self.snaps_status {
status.marked = false;
}
self.update_table();
Expand Down Expand Up @@ -650,7 +653,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}

pub fn clear_to_forget(&mut self) {
for status in self.snaps_status.iter_mut() {
for status in &mut self.snaps_status {
status.to_forget = false;
}
self.update_table();
Expand Down Expand Up @@ -718,7 +721,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}

pub fn input(&mut self, event: Event) -> Result<bool> {
use KeyCode::*;
use KeyCode::{Char, Enter, Esc, Left, Right, F};
match &mut self.current_screen {
CurrentScreen::Snapshots => {
match event {
Expand Down Expand Up @@ -846,10 +849,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}
CurrentScreen::SnapshotDetails(_) | CurrentScreen::ShowHelp(_) => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => {
if matches!(
key.code,
Char('q') | Esc | Enter | Char(' ') | Char('i') | Char('?')
) {
if matches!(key.code, Char('q' | ' ' | 'i' | '?') | Esc | Enter) {
self.current_screen = CurrentScreen::Snapshots;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/commands/tui/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ pub use with_block::*;
use crossterm::event::Event;
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
use ratatui::prelude::*;
use ratatui::widgets::*;
use ratatui::widgets::{
Block, Clear, Gauge, Paragraph, Row, Scrollbar, ScrollbarOrientation, ScrollbarState, Table,
TableState,
};

pub trait ProcessEvent {
type Result;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tui/widgets/popup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{Clear, Constraint, Draw, Event, Frame, Layout, ProcessEvent, Rect, SizedWidget};

// Make a popup from a SizedWidget
pub struct PopUp<T>(pub T);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/tui/widgets/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{Draw, Event, Frame, KeyCode, KeyEventKind, ProcessEvent, Rect, SizedWidget};

pub struct Prompt<T>(pub T);

Expand Down Expand Up @@ -26,11 +26,11 @@ impl<T: Draw> Draw for Prompt<T> {
impl<T> ProcessEvent for Prompt<T> {
type Result = PromptResult;
fn input(&mut self, event: Event) -> PromptResult {
use KeyCode::*;
use KeyCode::{Char, Enter, Esc};
match event {
Event::Key(key) if key.kind == KeyEventKind::Press => match key.code {
Char('q') | Char('n') | Char('c') | Esc => PromptResult::Cancel,
Enter | Char('y') | Char('j') | Char(' ') => PromptResult::Ok,
Char('q' | 'n' | 'c') | Esc => PromptResult::Cancel,
Enter | Char('y' | 'j' | ' ') => PromptResult::Ok,
_ => PromptResult::None,
},
_ => PromptResult::None,
Expand Down
10 changes: 7 additions & 3 deletions src/commands/tui/widgets/select_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::*;
use super::{
layout, style, Color, Constraint, Draw, Event, Frame, KeyCode, KeyEventKind, Layout, Modifier,
ProcessEvent, Rect, Row, Scrollbar, ScrollbarOrientation, ScrollbarState, SizedWidget, Style,
Stylize, Table, TableState, Text,
};
use std::iter::once;
use style::palette::tailwind;

Expand Down Expand Up @@ -67,7 +71,7 @@ impl SelectTable {
row.iter()
.zip(widths.iter())
.map(|(r, w)| r.max(w))
.cloned()
.copied()
.collect()
})
.unwrap_or_default();
Expand Down Expand Up @@ -161,7 +165,7 @@ impl SelectTable {
impl ProcessEvent for SelectTable {
type Result = ();
fn input(&mut self, event: Event) {
use KeyCode::*;
use KeyCode::{Down, End, Home, PageDown, PageUp, Up};
match event {
Event::Key(key) if key.kind == KeyEventKind::Press => match key.code {
Down => self.next(),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tui/widgets/sized_gauge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{Color, Draw, Frame, Gauge, Rect, SizedWidget, Span, Style};

pub struct SizedGauge {
p: Gauge<'static>,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tui/widgets/sized_paragraph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{Draw, Frame, Paragraph, Rect, SizedWidget, Text};

pub struct SizedParagraph {
p: Paragraph<'static>,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/tui/widgets/sized_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{Constraint, Draw, Frame, Rect, Row, SizedWidget, Table, Text};

pub struct SizedTable {
table: Table<'static>,
Expand All @@ -20,14 +20,14 @@ impl SizedTable {
row.iter()
.zip(widths.iter())
.map(|(r, w)| r.max(w))
.cloned()
.copied()
.collect()
})
.unwrap_or_default();

let width = widths
.iter()
.cloned()
.copied()
.reduce(|width, w| width + w + 1) // +1 because of space between entries
.unwrap_or_default();

Expand Down
19 changes: 10 additions & 9 deletions src/commands/tui/widgets/text_input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{Draw, Event, Frame, KeyCode, KeyEvent, ProcessEvent, Rect, SizedWidget, Style};

use crossterm::event::KeyModifiers;
use tui_textarea::{CursorMove, TextArea};
Expand Down Expand Up @@ -53,14 +53,13 @@ impl ProcessEvent for TextInput {
let KeyEvent {
code, modifiers, ..
} = key;
use KeyCode::*;
if self.changeable {
match (code, modifiers) {
(Esc, _) => return TextInputResult::Cancel,
(Enter, _) if self.lines == 1 => {
(KeyCode::Esc, _) => return TextInputResult::Cancel,
(KeyCode::Enter, _) if self.lines == 1 => {
return TextInputResult::Input(self.textarea.lines().join("\n"));
}
(Char('s'), KeyModifiers::CONTROL) => {
(KeyCode::Char('s'), KeyModifiers::CONTROL) => {
return TextInputResult::Input(self.textarea.lines().join("\n"));
}
_ => {
Expand All @@ -69,14 +68,16 @@ impl ProcessEvent for TextInput {
}
} else {
match (code, modifiers) {
(Esc | Enter | Char('q') | Char('x'), _) => return TextInputResult::Cancel,
(Home, _) => {
(KeyCode::Esc | KeyCode::Enter | KeyCode::Char('q' | 'x'), _) => {
return TextInputResult::Cancel
}
(KeyCode::Home, _) => {
self.textarea.move_cursor(CursorMove::Top);
}
(End, _) => {
(KeyCode::End, _) => {
self.textarea.move_cursor(CursorMove::Bottom);
}
(PageDown | PageUp | Up | Down, _) => {
(KeyCode::PageDown | KeyCode::PageUp | KeyCode::Up | KeyCode::Down, _) => {
_ = self.textarea.input(key);
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tui/widgets/with_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{layout, Block, Draw, Event, Frame, ProcessEvent, Rect, SizedWidget};
use layout::Size;

pub struct WithBlock<T> {
Expand Down
Loading

0 comments on commit a0e9105

Please sign in to comment.