diff options
author | Piotr Wach <pwach@bloomberg.net> | 2024-01-07 09:44:10 +0000 |
---|---|---|
committer | Piotr Wach <pwach@bloomberg.net> | 2024-01-07 09:44:10 +0000 |
commit | 13c381bebc6a64e553ec11793ec8880f868e712c (patch) | |
tree | 23a8504e298dc8b0bb75926587b5d1a0a3ddf87e /src/interactive | |
parent | e53036ad84b71e1121588929fe4653a7ababbf67 (diff) |
Clean-up init function
Diffstat (limited to 'src/interactive')
-rw-r--r-- | src/interactive/app/app_state.rs | 2 | ||||
-rw-r--r-- | src/interactive/app/eventloop.rs | 8 | ||||
-rw-r--r-- | src/interactive/app/mod.rs | 4 | ||||
-rw-r--r-- | src/interactive/app/terminal_app.rs | 26 | ||||
-rw-r--r-- | src/interactive/app/tests/utils.rs | 18 | ||||
-rw-r--r-- | src/interactive/widgets/main.rs | 3 |
6 files changed, 29 insertions, 32 deletions
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; |