summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPiotr Wach <pwach@bloomberg.net>2024-01-08 23:34:14 +0000
committerPiotr Wach <pwach@bloomberg.net>2024-01-08 23:34:14 +0000
commitc4efba87179636afeb26e472353a029a4030086c (patch)
treecfdfa14bb7914c50bd37aac44a34008167d60df1 /src
parentd903ea67a4f77c9483aed7bda1ef6694ee4465da (diff)
clippy
Diffstat (limited to 'src')
-rw-r--r--src/interactive/app/eventloop.rs19
-rw-r--r--src/interactive/app/terminal_app.rs49
-rw-r--r--src/interactive/app/tests/journeys_readonly.rs7
-rw-r--r--src/interactive/app/tests/journeys_with_writes.rs14
-rw-r--r--src/interactive/app/tests/utils.rs26
-rw-r--r--src/main.rs2
-rw-r--r--src/traverse.rs1
7 files changed, 63 insertions, 55 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index 2de51b6..ad326a0 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -10,7 +10,7 @@ use crossbeam::channel::Receiver;
use crosstermion::crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use crosstermion::input::Event;
use dua::{
- traverse::{EntryData, TraversalProcessingEvent, RunningTraversal, Traversal},
+ traverse::{EntryData, RunningTraversal, Traversal, TraversalProcessingEvent},
WalkOptions, WalkResult,
};
use std::path::PathBuf;
@@ -104,13 +104,9 @@ impl AppState {
self.refresh_screen(window, traversal, display, terminal)?;
loop {
- if let Some(result) = self.process_event(
- window,
- traversal,
- display,
- terminal,
- &events,
- )? {
+ if let Some(result) =
+ self.process_event(window, traversal, display, terminal, &events)?
+ {
return Ok(result);
}
}
@@ -161,9 +157,12 @@ impl AppState {
}
} else {
let Ok(event) = events.recv() else {
- return Ok(Some(ProcessingResult::ExitRequested(WalkResult { num_errors: 0 })));
+ return Ok(Some(ProcessingResult::ExitRequested(WalkResult {
+ num_errors: 0,
+ })));
};
- let result = self.process_terminal_event(window, traversal, display, terminal, event)?;
+ let result =
+ self.process_terminal_event(window, traversal, display, terminal, event)?;
if let Some(processing_result) = result {
return Ok(Some(processing_result));
}
diff --git a/src/interactive/app/terminal_app.rs b/src/interactive/app/terminal_app.rs
index 82d7199..ae1c130 100644
--- a/src/interactive/app/terminal_app.rs
+++ b/src/interactive/app/terminal_app.rs
@@ -103,29 +103,38 @@ impl TerminalApp {
ProcessingResult::ExitRequested(res) => Ok(res),
}
}
+}
- pub fn run_until_traversed<B>(
- &mut self,
- terminal: &mut Terminal<B>,
- events: Receiver<Event>,
- ) -> Result<WalkResult>
- where
- B: Backend
- {
- while self.state.running_traversal.is_some() {
- match self.state.process_event(
- &mut self.window,
- &mut self.traversal,
- &mut self.display,
- terminal,
- &events,
- )? {
- Some(ProcessingResult::ExitRequested(res)) => {
- return Ok(res);
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ use super::TerminalApp;
+
+ impl TerminalApp {
+ pub fn run_until_traversed<B>(
+ &mut self,
+ terminal: &mut Terminal<B>,
+ events: Receiver<Event>,
+ ) -> Result<WalkResult>
+ where
+ B: Backend,
+ {
+ while self.state.running_traversal.is_some() {
+ match self.state.process_event(
+ &mut self.window,
+ &mut self.traversal,
+ &mut self.display,
+ terminal,
+ &events,
+ )? {
+ Some(ProcessingResult::ExitRequested(res)) => {
+ return Ok(res);
+ }
+ _ => {}
}
- _ => {}
}
+ Ok(WalkResult { num_errors: 0 })
}
- Ok(WalkResult { num_errors: 0 })
}
}
diff --git a/src/interactive/app/tests/journeys_readonly.rs b/src/interactive/app/tests/journeys_readonly.rs
index 4821145..28e0529 100644
--- a/src/interactive/app/tests/journeys_readonly.rs
+++ b/src/interactive/app/tests/journeys_readonly.rs
@@ -29,7 +29,7 @@ fn simple_user_journey_read_only() -> Result<()> {
let short_root = "sample-01";
let (mut terminal, mut app) =
initialized_app_and_terminal_from_fixture(&[short_root, long_root])?;
-
+
// POST-INIT
// after initialization, we expect that...
{
@@ -300,10 +300,7 @@ fn simple_user_journey_read_only() -> Result<()> {
);
// when advancing the selection to the marker pane
- app.process_events(
- &mut terminal,
- into_keys(Some(KeyCode::Tab)),
- )?;
+ app.process_events(&mut terminal, into_keys(Some(KeyCode::Tab)))?;
{
assert_eq!(
Some(true),
diff --git a/src/interactive/app/tests/journeys_with_writes.rs b/src/interactive/app/tests/journeys_with_writes.rs
index 09ca1be..52431da 100644
--- a/src/interactive/app/tests/journeys_with_writes.rs
+++ b/src/interactive/app/tests/journeys_with_writes.rs
@@ -9,7 +9,7 @@ use pretty_assertions::assert_eq;
#[test]
#[cfg(not(target_os = "windows"))] // it stopped working here, don't know if it's truly broken or if it's the test. Let's wait for windows users to report.
fn basic_user_journey_with_deletion() -> Result<()> {
- use crate::interactive::app::tests::utils::{into_keys, into_events};
+ use crate::interactive::app::tests::utils::into_events;
let fixture = WritableFixture::from("sample-02");
let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
@@ -28,11 +28,13 @@ fn basic_user_journey_with_deletion() -> Result<()> {
// When selecting the marker window and pressing the combination to delete entries
app.process_events(
&mut terminal,
- into_events(vec![
- Event::Key(KeyCode::Tab.into()),
- Event::Key(KeyEvent::new(KeyCode::Char('r'), KeyModifiers::CONTROL)),
- ]
- .into_iter()),
+ into_events(
+ vec![
+ Event::Key(KeyCode::Tab.into()),
+ Event::Key(KeyEvent::new(KeyCode::Char('r'), KeyModifiers::CONTROL)),
+ ]
+ .into_iter(),
+ ),
)?;
assert!(
app.window.mark_pane.is_none(),
diff --git a/src/interactive/app/tests/utils.rs b/src/interactive/app/tests/utils.rs
index 4f8c6fd..8f7bf97 100644
--- a/src/interactive/app/tests/utils.rs
+++ b/src/interactive/app/tests/utils.rs
@@ -1,6 +1,6 @@
use anyhow::{Context, Error, Result};
-use crossbeam::channel::{Receiver, Sender};
-use crosstermion::{crossterm::{event::{KeyCode, KeyModifiers, KeyEvent}}, input::Event};
+use crossbeam::channel::Receiver;
+use crosstermion::{crossterm::event::KeyCode, input::Event};
use dua::{
traverse::{EntryData, Tree, TreeIndex},
ByteFormat, TraversalSorting, WalkOptions,
@@ -21,9 +21,7 @@ use tui_react::Terminal;
use crate::interactive::{app::tests::FIXTURE_PATH, terminal_app::TerminalApp};
-pub fn into_events<'a>(
- events: impl IntoIterator<Item = Event> + 'a,
-) -> Receiver<Event> {
+pub fn into_events<'a>(events: impl IntoIterator<Item = Event> + 'a) -> Receiver<Event> {
let (key_send, key_receive) = crossbeam::channel::unbounded();
for event in events {
_ = key_send.send(event);
@@ -31,15 +29,15 @@ pub fn into_events<'a>(
key_receive
}
-pub fn into_keys<'a>(
- codes: impl IntoIterator<Item = KeyCode> + 'a,
-) -> Receiver<Event> {
- into_events(codes
- .into_iter()
- .map(|code| crosstermion::input::Event::Key(code.into())))
+pub fn into_keys<'a>(codes: impl IntoIterator<Item = KeyCode> + 'a) -> Receiver<Event> {
+ into_events(
+ codes
+ .into_iter()
+ .map(|code| crosstermion::input::Event::Key(code.into())),
+ )
}
-pub fn into_codes<'a>(input: &'a str) -> Receiver<Event> {
+pub fn into_codes(input: &str) -> Receiver<Event> {
into_keys(input.chars().map(KeyCode::Char))
}
@@ -195,12 +193,12 @@ pub fn initialized_app_and_terminal_with_closure(
ignore_dirs: Default::default(),
};
- let (key_send, key_receive) = crossbeam::channel::bounded(0);
+ let (_key_send, key_receive) = crossbeam::channel::bounded(0);
let mut app = TerminalApp::initialize(&mut terminal, walk_options, ByteFormat::Metric)?;
let input_paths = fixture_paths.iter().map(|c| convert(c.as_ref())).collect();
app.traverse(input_paths)?;
- app.run_until_traversed(&mut terminal, key_receive);
+ app.run_until_traversed(&mut terminal, key_receive)?;
Ok((terminal, app))
}
diff --git a/src/main.rs b/src/main.rs
index 7e28c13..2743377 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,7 +7,9 @@ use simplelog::{Config, LevelFilter, WriteLogger};
use std::fs::OpenOptions;
use std::{fs, io, io::Write, path::PathBuf, process};
+#[cfg(feature = "tui-crossplatform")]
use crate::interactive::input::input_channel;
+#[cfg(feature = "tui-crossplatform")]
use crate::interactive::terminal_app::TerminalApp;
mod crossdev;
diff --git a/src/traverse.rs b/src/traverse.rs
index f221ace..3b6b291 100644
--- a/src/traverse.rs
+++ b/src/traverse.rs
@@ -125,6 +125,7 @@ pub fn pop_or_panic(v: &mut Vec<EntryInfo>) -> EntryInfo {
pub type TraversalEntry =
Result<jwalk::DirEntry<((), Option<Result<std::fs::Metadata, jwalk::Error>>)>, jwalk::Error>;
+#[allow(clippy::large_enum_variant)]
pub enum TraversalEvent {
Entry(TraversalEntry, Arc<PathBuf>, u64),
Finished(u64),