Skip to content

Commit a2fe4d3

Browse files
authored
feat[cli]: add scroll for tree encoding view (#5497)
1 parent 3572526 commit a2fe4d3

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

vortex-tui/src/browse/app.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ pub struct AppState<'a> {
189189
pub layouts_list_state: ListState,
190190
pub segment_grid_state: SegmentGridState<'a>,
191191
pub frame_size: Size,
192+
193+
/// Scroll offset for the encoding tree display in FlatLayout view
194+
pub tree_scroll_offset: u16,
192195
}
193196

194197
impl AppState<'_> {
@@ -214,5 +217,6 @@ pub async fn create_file_app<'a>(path: impl AsRef<Path>) -> VortexResult<AppStat
214217
layouts_list_state: ListState::default().with_selected(Some(0)),
215218
segment_grid_state: SegmentGridState::default(),
216219
frame_size: Size::new(0, 0),
220+
tree_scroll_offset: 0,
217221
})
218222
}

vortex-tui/src/browse/mod.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use ratatui::DefaultTerminal;
99
use ratatui::widgets::ListState;
1010
use ui::render_app;
1111
use vortex::error::{VortexExpect, VortexResult};
12+
use vortex::layout::layouts::flat::FlatVTable;
1213

1314
mod app;
1415
mod ui;
@@ -58,24 +59,48 @@ fn handle_normal_mode(app: &mut AppState, event: Event) -> HandleResult {
5859
// We send the key-up to the list state if we're looking at
5960
// the Layouts tab.
6061
match app.current_tab {
61-
Tab::Layout => app.layouts_list_state.select_previous(),
62+
Tab::Layout => {
63+
if app.cursor.layout().is::<FlatVTable>() {
64+
app.tree_scroll_offset = app.tree_scroll_offset.saturating_sub(1);
65+
} else {
66+
app.layouts_list_state.select_previous();
67+
}
68+
}
6269
Tab::Segments => app.segment_grid_state.scroll_up(10),
6370
}
6471
}
6572
(KeyCode::Down | KeyCode::Char('j'), _)
6673
| (KeyCode::Char('n'), KeyModifiers::CONTROL) => match app.current_tab {
67-
Tab::Layout => app.layouts_list_state.select_next(),
74+
Tab::Layout => {
75+
if app.cursor.layout().is::<FlatVTable>() {
76+
app.tree_scroll_offset = app.tree_scroll_offset.saturating_add(1);
77+
} else {
78+
app.layouts_list_state.select_next();
79+
}
80+
}
6881
Tab::Segments => app.segment_grid_state.scroll_down(10),
6982
},
7083
(KeyCode::PageUp, _) | (KeyCode::Char('v'), KeyModifiers::ALT) => {
7184
match app.current_tab {
72-
Tab::Layout => app.layouts_list_state.scroll_up_by(10),
85+
Tab::Layout => {
86+
if app.cursor.layout().is::<FlatVTable>() {
87+
app.tree_scroll_offset = app.tree_scroll_offset.saturating_sub(10);
88+
} else {
89+
app.layouts_list_state.scroll_up_by(10);
90+
}
91+
}
7392
Tab::Segments => app.segment_grid_state.scroll_up(100),
7493
}
7594
}
7695
(KeyCode::PageDown, _) | (KeyCode::Char('v'), KeyModifiers::CONTROL) => {
7796
match app.current_tab {
78-
Tab::Layout => app.layouts_list_state.scroll_down_by(10),
97+
Tab::Layout => {
98+
if app.cursor.layout().is::<FlatVTable>() {
99+
app.tree_scroll_offset = app.tree_scroll_offset.saturating_add(10);
100+
} else {
101+
app.layouts_list_state.scroll_down_by(10);
102+
}
103+
}
79104
Tab::Segments => app.segment_grid_state.scroll_down(100),
80105
}
81106
}
@@ -93,8 +118,9 @@ fn handle_normal_mode(app: &mut AppState, event: Event) -> HandleResult {
93118
let selected = app.layouts_list_state.selected().unwrap_or_default();
94119
app.cursor = app.cursor.child(selected);
95120

96-
// Reset the list scroll state.
121+
// Reset the list scroll state and tree scroll offset.
97122
app.layouts_list_state = ListState::default().with_selected(Some(0));
123+
app.tree_scroll_offset = 0;
98124
}
99125
}
100126
(KeyCode::Left | KeyCode::Char('h'), _)
@@ -103,8 +129,9 @@ fn handle_normal_mode(app: &mut AppState, event: Event) -> HandleResult {
103129
Tab::Layout => {
104130
// Ascend back up to the Parent node
105131
app.cursor = app.cursor.parent();
106-
// Reset the list scroll state.
132+
// Reset the list scroll state and tree scroll offset.
107133
app.layouts_list_state = ListState::default().with_selected(Some(0));
134+
app.tree_scroll_offset = 0;
108135
}
109136
Tab::Segments => app.segment_grid_state.scroll_left(20),
110137
}
@@ -192,8 +219,9 @@ fn handle_search_mode(app: &mut AppState, event: Event) -> HandleResult {
192219
}
193220
};
194221

195-
// Reset the list scroll state.
222+
// Reset the list scroll state and tree scroll offset.
196223
app.layouts_list_state = ListState::default().with_selected(Some(0));
224+
app.tree_scroll_offset = 0;
197225

198226
app.clear_search();
199227
// Return to normal mode.

vortex-tui/src/browse/ui/layouts.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ fn render_array(app: &AppState<'_>, area: Rect, buf: &mut Buffer, is_stats_table
191191
.constraints(vec![Constraint::Percentage(70), Constraint::Percentage(30)])
192192
.split(widget_area);
193193
let table = Table::new(rows, [Constraint::Min(6), Constraint::Min(6)]).header(header);
194-
// Tree-display the active array
195-
let tree = Paragraph::new(array.display_tree().to_string()).wrap(Wrap { trim: false });
194+
// Tree-display the active array with scroll support
195+
let tree = Paragraph::new(array.display_tree().to_string())
196+
.wrap(Wrap { trim: false })
197+
.scroll((app.tree_scroll_offset, 0));
196198

197199
let stats_container = Block::new()
198200
.title("Statistics")
@@ -282,7 +284,6 @@ fn render_child_list_items(
282284
container.render(area, buf);
283285

284286
// Render the List view.
285-
// TODO: add state so we can scroll
286287
StatefulWidget::render(
287288
List::new(list_items).highlight_style(Style::default().black().on_white().bold()),
288289
inner_area,

0 commit comments

Comments
 (0)