summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPiotr Wach <pwach@bloomberg.net>2024-01-07 09:44:10 +0000
committerPiotr Wach <pwach@bloomberg.net>2024-01-07 09:44:10 +0000
commit13c381bebc6a64e553ec11793ec8880f868e712c (patch)
tree23a8504e298dc8b0bb75926587b5d1a0a3ddf87e /src
parente53036ad84b71e1121588929fe4653a7ababbf67 (diff)
Clean-up init function
Diffstat (limited to 'src')
-rw-r--r--src/aggregate.rs8
-rw-r--r--src/interactive/app/app_state.rs2
-rw-r--r--src/interactive/app/eventloop.rs8
-rw-r--r--src/interactive/app/mod.rs4
-rw-r--r--src/interactive/app/terminal_app.rs26
-rw-r--r--src/interactive/app/tests/utils.rs18
-rw-r--r--src/interactive/widgets/main.rs3
-rw-r--r--src/main.rs57
8 files changed, 59 insertions, 67 deletions
diff --git a/src/aggregate.rs b/src/aggregate.rs
index d314571..163a7eb 100644
--- a/src/aggregate.rs
+++ b/src/aggregate.rs
@@ -1,4 +1,4 @@
-use crate::{crossdev, InodeFilter, Throttle, WalkOptions, WalkResult, ByteFormat};
+use crate::{crossdev, ByteFormat, InodeFilter, Throttle, WalkOptions, WalkResult};
use anyhow::Result;
use filesize::PathExt;
use owo_colors::{AnsiColors as Color, OwoColorize};
@@ -95,7 +95,7 @@ pub fn aggregate(
num_bytes,
num_errors,
path_color_of(&path),
- byte_format
+ byte_format,
)?;
}
total += num_bytes;
@@ -116,7 +116,7 @@ pub fn aggregate(
num_bytes,
num_errors,
path_color_of(&path),
- byte_format
+ byte_format,
)?;
}
}
@@ -129,7 +129,7 @@ pub fn aggregate(
total,
res.num_errors,
None,
- byte_format
+ byte_format,
)?;
}
Ok((res, stats))
diff --git a/src/interactive/app/app_state.rs b/src/interactive/app/app_state.rs
index 7983374..dd0f9a0 100644
--- a/src/interactive/app/app_state.rs
+++ b/src/interactive/app/app_state.rs
@@ -32,4 +32,4 @@ pub struct AppState {
pub enum ProcessingResult {
Finished(WalkResult),
ExitRequested(WalkResult),
-} \ No newline at end of file
+}
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index 98e13c2..df297e3 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -1,9 +1,10 @@
use crate::interactive::{
app::navigation::Navigation,
+ app_state::FocussedPane,
sorted_entries,
widgets::{glob_search, MainWindow, MainWindowProps},
ByteVisualization, CursorDirection, CursorMode, DisplayOptions, EntryDataBundle, MarkEntryMode,
- SortMode, app_state::FocussedPane,
+ SortMode,
};
use anyhow::Result;
use crossbeam::channel::Receiver;
@@ -17,8 +18,11 @@ use std::path::PathBuf;
use tui::backend::Backend;
use tui_react::Terminal;
-use super::{input::input_channel, app_state::{AppState, Cursor, ProcessingResult}};
use super::tree_view::TreeView;
+use super::{
+ app_state::{AppState, Cursor, ProcessingResult},
+ input::input_channel,
+};
impl AppState {
pub fn navigation_mut(&mut self) -> &mut Navigation {
diff --git a/src/interactive/app/mod.rs b/src/interactive/app/mod.rs
index 742127a..2dd74eb 100644
--- a/src/interactive/app/mod.rs
+++ b/src/interactive/app/mod.rs
@@ -1,12 +1,12 @@
+pub mod app_state;
mod bytevis;
mod common;
mod eventloop;
mod handlers;
pub mod input;
mod navigation;
-pub mod tree_view;
pub mod terminal_app;
-pub mod app_state;
+pub mod tree_view;
pub use bytevis::*;
pub use common::*;
diff --git a/src/interactive/app/terminal_app.rs b/src/interactive/app/terminal_app.rs
index 9d97ae7..0c96140 100644
--- a/src/interactive/app/terminal_app.rs
+++ b/src/interactive/app/terminal_app.rs
@@ -1,16 +1,21 @@
use std::path::PathBuf;
+use anyhow::Result;
use crossbeam::channel::Receiver;
use crosstermion::input::Event;
-use dua::{traverse::{Traversal, Tree, EntryData}, WalkResult, WalkOptions, ByteFormat};
+use dua::{
+ traverse::{EntryData, Traversal, Tree},
+ ByteFormat, WalkOptions, WalkResult,
+};
use tui::prelude::Backend;
use tui_react::Terminal;
-use anyhow::Result;
use crate::interactive::widgets::MainWindow;
-use super::{DisplayOptions, ByteVisualization, sorted_entries, refresh_key, app_state::{ProcessingResult, AppState}};
-
+use super::{
+ app_state::{AppState, ProcessingResult},
+ refresh_key, sorted_entries, ByteVisualization, DisplayOptions,
+};
/// State and methods representing the interactive disk usage analyser for the terminal
pub struct TerminalApp {
@@ -58,18 +63,13 @@ impl TerminalApp {
}
}
- pub fn initialize<B>(
- terminal: &mut Terminal<B>,
- byte_format: ByteFormat,
- input_paths: Vec<PathBuf>,
- keys_rx: Receiver<Event>,
- ) -> Result<Option<KeyboardInputAndApp>>
+ pub fn initialize<B>(terminal: &mut Terminal<B>, byte_format: ByteFormat) -> Result<TerminalApp>
where
B: Backend,
{
terminal.hide_cursor()?;
terminal.clear()?;
-
+
let mut display = DisplayOptions::new(byte_format);
let mut window = MainWindow::default();
@@ -133,7 +133,7 @@ impl TerminalApp {
// state.is_scanning = false;
// if !received_events {
- // }
+ // }
let traversal = {
let mut tree = Tree::new();
@@ -166,6 +166,6 @@ impl TerminalApp {
};
app.refresh_view(terminal);
- Ok(Some((keys_rx, app)))
+ Ok(app)
}
}
diff --git a/src/interactive/app/tests/utils.rs b/src/interactive/app/tests/utils.rs
index e5c432a..64d561c 100644
--- a/src/interactive/app/tests/utils.rs
+++ b/src/interactive/app/tests/utils.rs
@@ -175,19 +175,11 @@ pub fn initialized_app_and_terminal_with_closure(
let mut terminal = new_test_terminal()?;
std::env::set_current_dir(Path::new(env!("CARGO_MANIFEST_DIR")))?;
- let (_, keys_rx) = crossbeam::channel::unbounded();
- let input_paths = fixture_paths.iter().map(|c| convert(c.as_ref())).collect();
- let app = TerminalApp::initialize(
- &mut terminal,
- ByteFormat::Metric,
- input_paths,
- keys_rx,
- )?
- .map(|(_, app)| app);
- Ok((
- terminal,
- app.expect("app that didn't try to abort iteration"),
- ))
+ // let (_, keys_rx) = crossbeam::channel::unbounded();
+ // let input_paths = fixture_paths.iter().map(|c| convert(c.as_ref())).collect();
+ let app = TerminalApp::initialize(&mut terminal, ByteFormat::Metric)?;
+
+ Ok((terminal, app))
// WalkOptions {
// threads: 1,
diff --git a/src/interactive/widgets/main.rs b/src/interactive/widgets/main.rs
index 6a4bfb8..3df375a 100644
--- a/src/interactive/widgets/main.rs
+++ b/src/interactive/widgets/main.rs
@@ -1,9 +1,10 @@
use crate::interactive::{
+ app_state::{AppState, Cursor, FocussedPane},
widgets::{
Entries, EntriesProps, Footer, FooterProps, GlobPane, GlobPaneProps, Header, HelpPane,
HelpPaneProps, MarkPane, MarkPaneProps, COLOR_MARKED,
},
- DisplayOptions, app_state::{AppState, FocussedPane, Cursor},
+ DisplayOptions,
};
use std::borrow::Borrow;
use tui::backend::Backend;
diff --git a/src/main.rs b/src/main.rs
index 7694cf1..e579aad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -68,46 +68,41 @@ fn main() -> Result<()> {
)
.with_context(|| "Could not instantiate terminal")?;
+ // TODO: use
+ // extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?,
+
let keys_rx = input_channel();
- let res = TerminalApp::initialize(
- &mut terminal,
- byte_format,
- extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?,
- keys_rx,
- )?
- .map(|(keys_rx, mut app)| {
- let res = app.process_events(&mut terminal, keys_rx.into_iter());
-
- let res = res.map(|r| {
- (
- r,
- app.window
- .mark_pane
- .take()
- .map(|marked| marked.into_paths()),
- )
- });
- // Leak app memory to avoid having to wait for the hashmap to deallocate,
- // which causes a noticeable delay shortly before the the program exits anyway.
- std::mem::forget(app);
- res
+ let mut app = TerminalApp::initialize(&mut terminal, byte_format)?;
+
+ let res = app.process_events(&mut terminal, keys_rx.into_iter());
+
+ let res = res.map(|r| {
+ (
+ r,
+ app.window
+ .mark_pane
+ .take()
+ .map(|marked| marked.into_paths()),
+ )
});
+ // Leak app memory to avoid having to wait for the hashmap to deallocate,
+ // which causes a noticeable delay shortly before the the program exits anyway.
+ std::mem::forget(app);
drop(terminal);
io::stderr().flush().ok();
// Exit 'quickly' to avoid having to not have to deal with slightly different types in the other match branches
std::process::exit(
- res.transpose()?
- .map(|(walk_result, paths)| {
- if let Some(paths) = paths {
- for path in paths {
- println!("{}", path.display())
- }
+ res.map(|(walk_result, paths)| {
+ if let Some(paths) = paths {
+ for path in paths {
+ println!("{}", path.display())
}
- walk_result.to_exit_code()
- })
- .unwrap_or(0),
+ }
+ walk_result.to_exit_code()
+ })
+ .unwrap_or(0),
);
}
Some(Aggregate {