Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bef597

Browse files
author
Sebastian Thiel
committed
refactor
1 parent 982446a commit 7bef597

9 files changed

Lines changed: 57 additions & 65 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ benchmark: target/release/dua
3939
tests: unit-tests journey-tests
4040

4141
unit-tests:
42-
cargo test --bin dua
42+
cargo test --all
4343

4444
continuous-unit-tests:
4545
watchexec $(MAKE) unit-tests

src/interactive/app/eventloop.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::interactive::{
22
sorted_entries,
3-
widgets::{ReactMainWindow, ReactMainWindowProps},
3+
widgets::{MainWindow, MainWindowProps},
44
ByteVisualization, CursorDirection, DisplayOptions, EntryDataBundle, SortMode,
55
};
66
use dua::{
@@ -40,13 +40,13 @@ pub struct TerminalApp {
4040
pub traversal: Traversal,
4141
pub display: DisplayOptions,
4242
pub state: AppState,
43-
pub window: ReactMainWindow,
43+
pub window: MainWindow,
4444
}
4545

4646
impl TerminalApp {
4747
pub fn draw_window<B>(
48-
window: &mut ReactMainWindow,
49-
props: ReactMainWindowProps,
48+
window: &mut MainWindow,
49+
props: MainWindowProps,
5050
terminal: &mut Terminal<B>,
5151
) -> Result<(), Error>
5252
where
@@ -61,7 +61,7 @@ impl TerminalApp {
6161
where
6262
B: Backend,
6363
{
64-
let props = ReactMainWindowProps {
64+
let props = MainWindowProps {
6565
traversal: &self.traversal,
6666
display: self.display,
6767
state: &self.state,
@@ -139,7 +139,7 @@ impl TerminalApp {
139139
terminal.clear()?;
140140
let mut display_options: DisplayOptions = options.clone().into();
141141
display_options.byte_vis = ByteVisualization::Bar;
142-
let mut window = ReactMainWindow::default();
142+
let mut window = MainWindow::default();
143143

144144
let traversal = Traversal::from_walk(options, input, move |traversal| {
145145
let state = AppState {
@@ -149,7 +149,7 @@ impl TerminalApp {
149149
entries: sorted_entries(&traversal.tree, traversal.root_index, Default::default()),
150150
..Default::default()
151151
};
152-
let props = ReactMainWindowProps {
152+
let props = MainWindowProps {
153153
traversal,
154154
display: display_options,
155155
state: &state,

src/interactive/app/handlers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::interactive::{
22
app::{FocussedPane, TerminalApp},
33
sorted_entries,
4-
widgets::ReactHelpPane,
4+
widgets::HelpPane,
55
};
66
use dua::path_of;
77
use itertools::Itertools;
@@ -28,7 +28,7 @@ impl TerminalApp {
2828
use FocussedPane::*;
2929
self.state.focussed = match self.state.focussed {
3030
Main => {
31-
self.window.help_pane = Some(ReactHelpPane::default());
31+
self.window.help_pane = Some(HelpPane::default());
3232
Help
3333
}
3434
Help => {

src/interactive/widgets/entries.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use tui::{
88
style::{Color, Style},
99
widgets::{Block, Borders, Text},
1010
};
11-
use tui_react::{fill_background_to_right, ReactList, ReactListProps};
11+
use tui_react::{fill_background_to_right, List, ListProps};
1212

13-
pub struct ReactEntriesProps<'a> {
13+
pub struct EntriesProps<'a> {
1414
pub tree: &'a Tree,
1515
pub root: TreeIndex,
1616
pub display: DisplayOptions,
@@ -21,18 +21,18 @@ pub struct ReactEntriesProps<'a> {
2121
}
2222

2323
#[derive(Default)]
24-
pub struct ReactEntries {
25-
pub list: ReactList,
24+
pub struct Entries {
25+
pub list: List,
2626
}
2727

28-
impl ReactEntries {
28+
impl Entries {
2929
pub fn render<'a>(
3030
&mut self,
31-
props: impl Borrow<ReactEntriesProps<'a>>,
31+
props: impl Borrow<EntriesProps<'a>>,
3232
area: Rect,
3333
buf: &mut Buffer,
3434
) {
35-
let ReactEntriesProps {
35+
let EntriesProps {
3636
tree,
3737
root,
3838
display,
@@ -70,7 +70,7 @@ impl ReactEntries {
7070
.unwrap_or(0)
7171
});
7272

73-
let props = ReactListProps {
73+
let props = ListProps {
7474
block: Some(block),
7575
entry_in_view,
7676
};

src/interactive/widgets/footer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ use tui::{
1010
};
1111
use tui_react::ToplevelComponent;
1212

13-
pub struct ReactFooter;
13+
pub struct Footer;
1414

15-
pub struct ReactFooterProps {
15+
pub struct FooterProps {
1616
pub total_bytes: Option<u64>,
1717
pub entries_traversed: u64,
1818
pub format: ByteFormat,
1919
pub message: Option<String>,
2020
}
2121

22-
impl ToplevelComponent for ReactFooter {
23-
type Props = ReactFooterProps;
22+
impl ToplevelComponent for Footer {
23+
type Props = FooterProps;
2424

2525
fn render(&mut self, props: impl Borrow<Self::Props>, area: Rect, buf: &mut Buffer) {
26-
let ReactFooterProps {
26+
let FooterProps {
2727
total_bytes,
2828
entries_traversed,
2929
format,

src/interactive/widgets/help.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use tui::{
1010
use tui_react::ToplevelComponent;
1111

1212
#[derive(Default, Clone)]
13-
pub struct ReactHelpPane {
13+
pub struct HelpPane {
1414
pub scroll: u16,
1515
}
1616

17-
pub struct ReactHelpPaneProps {
17+
pub struct HelpPaneProps {
1818
pub border_style: Style,
1919
}
2020

21-
impl ToplevelComponent for ReactHelpPane {
22-
type Props = ReactHelpPaneProps;
21+
impl ToplevelComponent for HelpPane {
22+
type Props = HelpPaneProps;
2323

2424
fn render(&mut self, props: impl Borrow<Self::Props>, area: Rect, buf: &mut Buffer) {
2525
let (texts, num_lines) = {
@@ -98,7 +98,7 @@ impl ToplevelComponent for ReactHelpPane {
9898
(lines.into_inner(), num_lines.get())
9999
};
100100

101-
let ReactHelpPaneProps { border_style } = props.borrow();
101+
let HelpPaneProps { border_style } = props.borrow();
102102

103103
let mut block = Block::default()
104104
.title("Help")

src/interactive/widgets/main.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use crate::interactive::{
2-
widgets::{
3-
Header, ReactEntries, ReactEntriesProps, ReactFooter, ReactFooterProps, ReactHelpPane,
4-
ReactHelpPaneProps,
5-
},
2+
widgets::{Entries, EntriesProps, Footer, FooterProps, Header, HelpPane, HelpPaneProps},
63
AppState, DisplayOptions, FocussedPane,
74
};
85
use dua::traverse::Traversal;
@@ -16,26 +13,26 @@ use tui::{
1613
};
1714
use tui_react::ToplevelComponent;
1815

19-
pub struct ReactMainWindowProps<'a> {
16+
pub struct MainWindowProps<'a> {
2017
pub traversal: &'a Traversal,
2118
pub display: DisplayOptions,
2219
pub state: &'a AppState,
2320
}
2421

2522
#[derive(Default)]
26-
pub struct ReactMainWindow {
27-
pub help_pane: Option<ReactHelpPane>,
28-
pub entries_pane: ReactEntries,
23+
pub struct MainWindow {
24+
pub help_pane: Option<HelpPane>,
25+
pub entries_pane: Entries,
2926
}
3027

31-
impl ReactMainWindow {
28+
impl MainWindow {
3229
pub fn render<'a>(
3330
&mut self,
34-
props: impl Borrow<ReactMainWindowProps<'a>>,
31+
props: impl Borrow<MainWindowProps<'a>>,
3532
area: Rect,
3633
buf: &mut Buffer,
3734
) {
38-
let ReactMainWindowProps {
35+
let MainWindowProps {
3936
traversal:
4037
Traversal {
4138
tree,
@@ -83,7 +80,7 @@ impl ReactMainWindow {
8380
};
8481

8582
Header.draw(header_area, buf);
86-
let props = ReactEntriesProps {
83+
let props = EntriesProps {
8784
tree: &tree,
8885
root: state.root,
8986
display: *display,
@@ -99,14 +96,14 @@ impl ReactMainWindow {
9996
self.entries_pane.render(props, entries_area, buf);
10097

10198
if let Some((help_area, pane)) = help_pane {
102-
let props = ReactHelpPaneProps {
99+
let props = HelpPaneProps {
103100
border_style: help_style,
104101
};
105102
pane.render(props, help_area, buf);
106103
}
107104

108-
ReactFooter.render(
109-
ReactFooterProps {
105+
Footer.render(
106+
FooterProps {
110107
total_bytes: *total_bytes,
111108
entries_traversed: *entries_traversed,
112109
format: display.byte_format,

tui-react/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ mod terminal;
44
pub use list::*;
55
pub use terminal::*;
66

7-
/// re-export our exact version, in case it matters to someone
8-
pub use tui;
7+
use std::iter::repeat;
8+
use tui::{self, buffer::Buffer, layout::Rect, style::Color};
99

10-
use tui::buffer::Buffer;
11-
use tui::layout::Rect;
12-
use tui::style::Color;
10+
pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
11+
match (s.len(), entire_width as usize) {
12+
(x, y) if x >= y => s,
13+
(x, y) => {
14+
s.extend(repeat(' ').take(y - x));
15+
s
16+
}
17+
}
18+
}
1319

1420
/// Helper method to quickly set the background of all cells inside the specified area.
1521
pub fn fill_background(area: Rect, buf: &mut Buffer, color: Color) {

tui-react/src/list.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
use std::iter::repeat;
21
use tui::{
32
buffer::Buffer,
43
layout::Rect,
54
widgets::{Block, Paragraph, Text, Widget},
65
};
76

8-
pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
9-
match (s.len(), entire_width as usize) {
10-
(x, y) if x >= y => s,
11-
(x, y) => {
12-
s.extend(repeat(' ').take(y - x));
13-
s
14-
}
15-
}
16-
}
17-
187
#[derive(Default)]
19-
pub struct ReactList {
8+
pub struct List {
209
/// The index at which the list last started. Used for scrolling
2110
offset: usize,
2211
}
2312

24-
impl ReactList {
13+
impl List {
2514
fn list_offset_for(&self, entry_in_view: Option<usize>, height: usize) -> usize {
2615
match entry_in_view {
2716
Some(pos) => match height as usize {
@@ -35,20 +24,20 @@ impl ReactList {
3524
}
3625

3726
#[derive(Default)]
38-
pub struct ReactListProps<'b> {
27+
pub struct ListProps<'b> {
3928
pub block: Option<Block<'b>>,
4029
pub entry_in_view: Option<usize>,
4130
}
4231

43-
impl ReactList {
32+
impl List {
4433
pub fn render<'a, 't>(
4534
&mut self,
46-
props: ReactListProps<'a>,
35+
props: ListProps<'a>,
4736
items: impl IntoIterator<Item = Vec<Text<'t>>>,
4837
area: Rect,
4938
buf: &mut Buffer,
5039
) {
51-
let ReactListProps {
40+
let ListProps {
5241
block,
5342
entry_in_view,
5443
} = props;

0 commit comments

Comments
 (0)