summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-06 08:08:15 +0530
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-06 08:08:15 +0530
commit7bef5974e86de825dcb0b3507df16a80b6986d88 (patch)
tree965fa139b9b56d0adba0a21cf180741c01ea3bea
parent982446ad0ef9a475274c9a0f05a32147fcafd061 (diff)
refactor
-rw-r--r--Makefile2
-rw-r--r--src/interactive/app/eventloop.rs14
-rw-r--r--src/interactive/app/handlers.rs4
-rw-r--r--src/interactive/widgets/entries.rs16
-rw-r--r--src/interactive/widgets/footer.rs10
-rw-r--r--src/interactive/widgets/help.rs10
-rw-r--r--src/interactive/widgets/main.rs27
-rw-r--r--tui-react/src/lib.rs16
-rw-r--r--tui-react/src/list.rs23
9 files changed, 57 insertions, 65 deletions
diff --git a/Makefile b/Makefile
index 68d5824..0df7a87 100644
--- a/Makefile
+++ b/Makefile
@@ -39,7 +39,7 @@ benchmark: target/release/dua
tests: unit-tests journey-tests
unit-tests:
- cargo test --bin dua
+ cargo test --all
continuous-unit-tests:
watchexec $(MAKE) unit-tests
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index d15eabb..5d02a1f 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -1,6 +1,6 @@
use crate::interactive::{
sorted_entries,
- widgets::{ReactMainWindow, ReactMainWindowProps},
+ widgets::{MainWindow, MainWindowProps},
ByteVisualization, CursorDirection, DisplayOptions, EntryDataBundle, SortMode,
};
use dua::{
@@ -40,13 +40,13 @@ pub struct TerminalApp {
pub traversal: Traversal,
pub display: DisplayOptions,
pub state: AppState,
- pub window: ReactMainWindow,
+ pub window: MainWindow,
}
impl TerminalApp {
pub fn draw_window<B>(
- window: &mut ReactMainWindow,
- props: ReactMainWindowProps,
+ window: &mut MainWindow,
+ props: MainWindowProps,
terminal: &mut Terminal<B>,
) -> Result<(), Error>
where
@@ -61,7 +61,7 @@ impl TerminalApp {
where
B: Backend,
{
- let props = ReactMainWindowProps {
+ let props = MainWindowProps {
traversal: &self.traversal,
display: self.display,
state: &self.state,
@@ -139,7 +139,7 @@ impl TerminalApp {
terminal.clear()?;
let mut display_options: DisplayOptions = options.clone().into();
display_options.byte_vis = ByteVisualization::Bar;
- let mut window = ReactMainWindow::default();
+ let mut window = MainWindow::default();
let traversal = Traversal::from_walk(options, input, move |traversal| {
let state = AppState {
@@ -149,7 +149,7 @@ impl TerminalApp {
entries: sorted_entries(&traversal.tree, traversal.root_index, Default::default()),
..Default::default()
};
- let props = ReactMainWindowProps {
+ let props = MainWindowProps {
traversal,
display: display_options,
state: &state,
diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs
index b9f2c13..2971e4a 100644
--- a/src/interactive/app/handlers.rs
+++ b/src/interactive/app/handlers.rs
@@ -1,7 +1,7 @@
use crate::interactive::{
app::{FocussedPane, TerminalApp},
sorted_entries,
- widgets::ReactHelpPane,
+ widgets::HelpPane,
};
use dua::path_of;
use itertools::Itertools;
@@ -28,7 +28,7 @@ impl TerminalApp {
use FocussedPane::*;
self.state.focussed = match self.state.focussed {
Main => {
- self.window.help_pane = Some(ReactHelpPane::default());
+ self.window.help_pane = Some(HelpPane::default());
Help
}
Help => {
diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs
index 0fe0bf0..8a740e3 100644
--- a/src/interactive/widgets/entries.rs
+++ b/src/interactive/widgets/entries.rs
@@ -8,9 +8,9 @@ use tui::{
style::{Color, Style},
widgets::{Block, Borders, Text},
};
-use tui_react::{fill_background_to_right, ReactList, ReactListProps};
+use tui_react::{fill_background_to_right, List, ListProps};
-pub struct ReactEntriesProps<'a> {
+pub struct EntriesProps<'a> {
pub tree: &'a Tree,
pub root: TreeIndex,
pub display: DisplayOptions,
@@ -21,18 +21,18 @@ pub struct ReactEntriesProps<'a> {
}
#[derive(Default)]
-pub struct ReactEntries {
- pub list: ReactList,
+pub struct Entries {
+ pub list: List,
}
-impl ReactEntries {
+impl Entries {
pub fn render<'a>(
&mut self,
- props: impl Borrow<ReactEntriesProps<'a>>,
+ props: impl Borrow<EntriesProps<'a>>,
area: Rect,
buf: &mut Buffer,
) {
- let ReactEntriesProps {
+ let EntriesProps {
tree,
root,
display,
@@ -70,7 +70,7 @@ impl ReactEntries {
.unwrap_or(0)
});
- let props = ReactListProps {
+ let props = ListProps {
block: Some(block),
entry_in_view,
};
diff --git a/src/interactive/widgets/footer.rs b/src/interactive/widgets/footer.rs
index 048ae69..d598abd 100644
--- a/src/interactive/widgets/footer.rs
+++ b/src/interactive/widgets/footer.rs
@@ -10,20 +10,20 @@ use tui::{
};
use tui_react::ToplevelComponent;
-pub struct ReactFooter;
+pub struct Footer;
-pub struct ReactFooterProps {
+pub struct FooterProps {
pub total_bytes: Option<u64>,
pub entries_traversed: u64,
pub format: ByteFormat,
pub message: Option<String>,
}
-impl ToplevelComponent for ReactFooter {
- type Props = ReactFooterProps;
+impl ToplevelComponent for Footer {
+ type Props = FooterProps;
fn render(&mut self, props: impl Borrow<Self::Props>, area: Rect, buf: &mut Buffer) {
- let ReactFooterProps {
+ let FooterProps {
total_bytes,
entries_traversed,
format,
diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs
index 66fc500..aad6f93 100644
--- a/src/interactive/widgets/help.rs
+++ b/src/interactive/widgets/help.rs
@@ -10,16 +10,16 @@ use tui::{
use tui_react::ToplevelComponent;
#[derive(Default, Clone)]
-pub struct ReactHelpPane {
+pub struct HelpPane {
pub scroll: u16,
}
-pub struct ReactHelpPaneProps {
+pub struct HelpPaneProps {
pub border_style: Style,
}
-impl ToplevelComponent for ReactHelpPane {
- type Props = ReactHelpPaneProps;
+impl ToplevelComponent for HelpPane {
+ type Props = HelpPaneProps;
fn render(&mut self, props: impl Borrow<Self::Props>, area: Rect, buf: &mut Buffer) {
let (texts, num_lines) = {
@@ -98,7 +98,7 @@ impl ToplevelComponent for ReactHelpPane {
(lines.into_inner(), num_lines.get())
};
- let ReactHelpPaneProps { border_style } = props.borrow();
+ let HelpPaneProps { border_style } = props.borrow();
let mut block = Block::default()
.title("Help")
diff --git a/src/interactive/widgets/main.rs b/src/interactive/widgets/main.rs
index ddb28bc..ee4e7ef 100644
--- a/src/interactive/widgets/main.rs
+++ b/src/interactive/widgets/main.rs
@@ -1,8 +1,5 @@
use crate::interactive::{
- widgets::{
- Header, ReactEntries, ReactEntriesProps, ReactFooter, ReactFooterProps, ReactHelpPane,
- ReactHelpPaneProps,
- },
+ widgets::{Entries, EntriesProps, Footer, FooterProps, Header, HelpPane, HelpPaneProps},
AppState, DisplayOptions, FocussedPane,
};
use dua::traverse::Traversal;
@@ -16,26 +13,26 @@ use tui::{
};
use tui_react::ToplevelComponent;
-pub struct ReactMainWindowProps<'a> {
+pub struct MainWindowProps<'a> {
pub traversal: &'a Traversal,
pub display: DisplayOptions,
pub state: &'a AppState,
}
#[derive(Default)]
-pub struct ReactMainWindow {
- pub help_pane: Option<ReactHelpPane>,
- pub entries_pane: ReactEntries,
+pub struct MainWindow {
+ pub help_pane: Option<HelpPane>,
+ pub entries_pane: Entries,
}
-impl ReactMainWindow {
+impl MainWindow {
pub fn render<'a>(
&mut self,
- props: impl Borrow<ReactMainWindowProps<'a>>,
+ props: impl Borrow<MainWindowProps<'a>>,
area: Rect,
buf: &mut Buffer,
) {
- let ReactMainWindowProps {
+ let MainWindowProps {
traversal:
Traversal {
tree,
@@ -83,7 +80,7 @@ impl ReactMainWindow {
};
Header.draw(header_area, buf);
- let props = ReactEntriesProps {
+ let props = EntriesProps {
tree: &tree,
root: state.root,
display: *display,
@@ -99,14 +96,14 @@ impl ReactMainWindow {
self.entries_pane.render(props, entries_area, buf);
if let Some((help_area, pane)) = help_pane {
- let props = ReactHelpPaneProps {
+ let props = HelpPaneProps {
border_style: help_style,
};
pane.render(props, help_area, buf);
}
- ReactFooter.render(
- ReactFooterProps {
+ Footer.render(
+ FooterProps {
total_bytes: *total_bytes,
entries_traversed: *entries_traversed,
format: display.byte_format,
diff --git a/tui-react/src/lib.rs b/tui-react/src/lib.rs
index af8f6ac..e44e39f 100644
--- a/tui-react/src/lib.rs
+++ b/tui-react/src/lib.rs
@@ -4,12 +4,18 @@ mod terminal;
pub use list::*;
pub use terminal::*;
-/// re-export our exact version, in case it matters to someone
-pub use tui;
+use std::iter::repeat;
+use tui::{self, buffer::Buffer, layout::Rect, style::Color};
-use tui::buffer::Buffer;
-use tui::layout::Rect;
-use tui::style::Color;
+pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
+ match (s.len(), entire_width as usize) {
+ (x, y) if x >= y => s,
+ (x, y) => {
+ s.extend(repeat(' ').take(y - x));
+ s
+ }
+ }
+}
/// Helper method to quickly set the background of all cells inside the specified area.
pub fn fill_background(area: Rect, buf: &mut Buffer, color: Color) {
diff --git a/tui-react/src/list.rs b/tui-react/src/list.rs
index d9510ff..45976dd 100644
--- a/tui-react/src/list.rs
+++ b/tui-react/src/list.rs
@@ -1,27 +1,16 @@
-use std::iter::repeat;
use tui::{
buffer::Buffer,
layout::Rect,
widgets::{Block, Paragraph, Text, Widget},
};
-pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
- match (s.len(), entire_width as usize) {
- (x, y) if x >= y => s,
- (x, y) => {
- s.extend(repeat(' ').take(y - x));
- s
- }
- }
-}
-
#[derive(Default)]
-pub struct ReactList {
+pub struct List {
/// The index at which the list last started. Used for scrolling
offset: usize,
}
-impl ReactList {
+impl List {
fn list_offset_for(&self, entry_in_view: Option<usize>, height: usize) -> usize {
match entry_in_view {
Some(pos) => match height as usize {
@@ -35,20 +24,20 @@ impl ReactList {
}
#[derive(Default)]
-pub struct ReactListProps<'b> {
+pub struct ListProps<'b> {
pub block: Option<Block<'b>>,
pub entry_in_view: Option<usize>,
}
-impl ReactList {
+impl List {
pub fn render<'a, 't>(
&mut self,
- props: ReactListProps<'a>,
+ props: ListProps<'a>,
items: impl IntoIterator<Item = Vec<Text<'t>>>,
area: Rect,
buf: &mut Buffer,
) {
- let ReactListProps {
+ let ListProps {
block,
entry_in_view,
} = props;