Skip to content

Commit

Permalink
feat(general): support scrolling general file information
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Aug 22, 2024
1 parent 025b217 commit 5300732
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn start_tui(analyzer: Analyzer, args: Args) -> Result<()> {
},
};
state.system_calls_loaded = true;
state.scroll_index = 0;
state.dynamic_scroll_index = 0;
tui.toggle_pause()?;
state.handle_tab()?;
}
Expand Down
25 changes: 18 additions & 7 deletions src/tui/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ pub struct State<'a> {
pub tab: Tab,
/// Elf info.
pub info_index: usize,
/// Scroll index.
pub scroll_index: usize,
/// List items.
pub list: SelectableList<Vec<String>>,
/// Show heh.
Expand All @@ -38,6 +36,10 @@ pub struct State<'a> {
pub strings_loaded: bool,
/// System calls completed.
pub system_calls_loaded: bool,
/// System calls scroll index.
pub dynamic_scroll_index: usize,
/// File info scroll index.
pub general_scroll_index: usize,
}

impl<'a> State<'a> {
Expand All @@ -47,7 +49,6 @@ impl<'a> State<'a> {
running: true,
tab: Tab::default(),
info_index: 0,
scroll_index: 0,
list: SelectableList::default(),
analyzer,
show_heh: false,
Expand All @@ -56,6 +57,8 @@ impl<'a> State<'a> {
input_mode: false,
strings_loaded: false,
system_calls_loaded: false,
dynamic_scroll_index: 0,
general_scroll_index: 0,
};
state.handle_tab()?;
Ok(state)
Expand Down Expand Up @@ -155,11 +158,15 @@ impl<'a> State<'a> {
self.info_index = (self.info_index.checked_add(amount).unwrap_or_default())
% ELF_INFO_TABS.len();
self.handle_tab()?;
} else if self.tab == Tab::General {
self.general_scroll_index =
self.general_scroll_index.saturating_add(amount);
}
}
ScrollType::List => {
if self.tab == Tab::DynamicAnalysis {
self.scroll_index = self.scroll_index.saturating_add(amount);
self.dynamic_scroll_index =
self.dynamic_scroll_index.saturating_add(amount);
} else {
self.list.next(amount)
}
Expand All @@ -176,26 +183,30 @@ impl<'a> State<'a> {
.checked_sub(amount)
.unwrap_or(ELF_INFO_TABS.len() - 1);
self.handle_tab()?;
} else if self.tab == Tab::General {
self.general_scroll_index =
self.general_scroll_index.saturating_sub(amount);
}
}
ScrollType::List => {
if self.tab == Tab::DynamicAnalysis {
self.scroll_index = self.scroll_index.saturating_sub(amount);
self.dynamic_scroll_index =
self.dynamic_scroll_index.saturating_sub(amount);
} else {
self.list.previous(amount)
}
}
},
Command::Top => {
if self.tab == Tab::DynamicAnalysis {
self.scroll_index = 0;
self.dynamic_scroll_index = 0;
} else {
self.list.first();
}
}
Command::Bottom => {
if self.tab == Tab::DynamicAnalysis {
self.scroll_index = self
self.dynamic_scroll_index = self
.analyzer
.tracer
.syscalls
Expand Down
14 changes: 10 additions & 4 deletions src/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,19 @@ pub fn render_general_info(state: &mut State, frame: &mut Frame, rect: Rect) {
)
.split(info_area)[0];

let max_height = lines.len().saturating_sub(info_area.height as usize) + 2;
if max_height < state.general_scroll_index {
state.general_scroll_index = max_height;
}

frame.render_widget(
Paragraph::new(lines)
.block(
Block::bordered()
.title_alignment(Alignment::Center)
.border_style(Style::default().fg(Color::Rgb(100, 100, 100))),
)
.scroll((state.general_scroll_index as u16, 0))
.wrap(Wrap { trim: true }),
info_area,
);
Expand Down Expand Up @@ -854,8 +860,8 @@ pub fn render_dynamic_analysis(state: &mut State, frame: &mut Frame, rect: Rect)
.len()
.saturating_sub(rect.height as usize)
+ 2;
if max_height < state.scroll_index {
state.scroll_index = max_height;
if max_height < state.dynamic_scroll_index {
state.dynamic_scroll_index = max_height;
}

frame.render_widget(
Expand Down Expand Up @@ -886,7 +892,7 @@ pub fn render_dynamic_analysis(state: &mut State, frame: &mut Frame, rect: Rect)
)
.title_bottom(get_input_line(state)),
)
.scroll((state.scroll_index as u16, 0)),
.scroll((state.dynamic_scroll_index as u16, 0)),
rect,
);

Expand All @@ -899,7 +905,7 @@ pub fn render_dynamic_analysis(state: &mut State, frame: &mut Frame, rect: Rect)
vertical: 1,
horizontal: 0,
}),
&mut ScrollbarState::new(max_height).position(state.scroll_index),
&mut ScrollbarState::new(max_height).position(state.dynamic_scroll_index),
);

if state.show_details && !state.analyzer.tracer.summary.is_empty() {
Expand Down

0 comments on commit 5300732

Please sign in to comment.