-
-
Notifications
You must be signed in to change notification settings - Fork 162
Introduce new help view to display information on any view #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
355fb42
4e93b78
31d98b6
5125874
826487e
3d91fe3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use tui::{ | ||
layout::{self, Constraint, Direction, Layout}, | ||
text::Text, | ||
widgets::{Clear, Paragraph, Wrap}, | ||
}; | ||
|
||
use crate::{state::State, view}; | ||
|
||
/// Simple view for help popup | ||
pub(crate) struct HelpView<T> { | ||
help_text: Option<T>, | ||
} | ||
|
||
impl<T> HelpView<T> | ||
where | ||
T: Into<Text<'static>>, | ||
{ | ||
pub(super) fn new(help_text: T) -> Self { | ||
HelpView { | ||
help_text: Some(help_text), | ||
} | ||
} | ||
|
||
pub(crate) fn render<B: tui::backend::Backend>( | ||
&mut self, | ||
styles: &view::Styles, | ||
frame: &mut tui::terminal::Frame<B>, | ||
_area: layout::Rect, | ||
_state: &mut State, | ||
) { | ||
let r = frame.size(); | ||
let content = self | ||
.help_text | ||
.take() | ||
.expect("help_text should be initialized") | ||
.into(); | ||
Comment on lines
+32
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's kind of weird to me that |
||
|
||
let popup_layout = Layout::default() | ||
.direction(Direction::Vertical) | ||
.constraints( | ||
[ | ||
Constraint::Percentage(40), | ||
Constraint::Percentage(20), | ||
Constraint::Percentage(40), | ||
] | ||
.as_ref(), | ||
) | ||
.split(r); | ||
|
||
let popup_area = Layout::default() | ||
.direction(Direction::Horizontal) | ||
.constraints( | ||
[ | ||
Constraint::Percentage(20), | ||
Constraint::Percentage(60), | ||
Constraint::Percentage(20), | ||
] | ||
.as_ref(), | ||
) | ||
.split(popup_layout[1])[1]; | ||
|
||
let display_text = Paragraph::new(content) | ||
.block(styles.border_block().title("Help")) | ||
.wrap(Wrap { trim: true }); | ||
|
||
// Clear the help block area and render the popup | ||
frame.render_widget(Clear, popup_area); | ||
frame.render_widget(display_text, popup_area); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||||||
use crate::view::help::HelpView; | ||||||||
use crate::view::{resources::ResourcesTable, table::TableListState, tasks::TasksTable}; | ||||||||
use crate::{input, state::State}; | ||||||||
use std::{borrow::Cow, cmp}; | ||||||||
|
@@ -8,15 +9,18 @@ use tui::{ | |||||||
}; | ||||||||
|
||||||||
mod async_ops; | ||||||||
mod help; | ||||||||
mod mini_histogram; | ||||||||
mod resource; | ||||||||
mod resources; | ||||||||
mod styles; | ||||||||
mod table; | ||||||||
mod task; | ||||||||
mod tasks; | ||||||||
use self::resource::ResourceView; | ||||||||
pub(crate) use self::styles::{Palette, Styles}; | ||||||||
pub(crate) use self::table::SortBy; | ||||||||
use self::task::TaskView; | ||||||||
|
||||||||
const DUR_LEN: usize = 10; | ||||||||
// This data is only updated every second, so it doesn't make a ton of | ||||||||
|
@@ -36,6 +40,7 @@ pub struct View { | |||||||
tasks_list: TableListState<TasksTable, 11>, | ||||||||
resources_list: TableListState<ResourcesTable, 9>, | ||||||||
state: ViewState, | ||||||||
show_help_toggle: bool, | ||||||||
pub(crate) styles: Styles, | ||||||||
} | ||||||||
|
||||||||
|
@@ -89,13 +94,17 @@ impl View { | |||||||
state: ViewState::TasksList, | ||||||||
tasks_list: TableListState::<TasksTable, 11>::default(), | ||||||||
resources_list: TableListState::<ResourcesTable, 9>::default(), | ||||||||
show_help_toggle: false, | ||||||||
styles, | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
pub(crate) fn update_input(&mut self, event: input::Event, state: &State) -> UpdateKind { | ||||||||
use ViewState::*; | ||||||||
let mut update_kind = UpdateKind::Other; | ||||||||
|
||||||||
self.handl_help_popup(event); | ||||||||
|
||||||||
match self.state { | ||||||||
TasksList => { | ||||||||
// The enter key changes views, so handle here since we can | ||||||||
|
@@ -168,32 +177,56 @@ impl View { | |||||||
update_kind | ||||||||
} | ||||||||
|
||||||||
fn handl_help_popup(&mut self, event: crossterm::event::Event) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: should probably be
Suggested change
|
||||||||
if input::is_help_toggle(&event) { | ||||||||
// TODO: Pause state if we are about to show the help toggle | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should probably do this before merging? |
||||||||
self.show_help_toggle = !self.show_help_toggle; | ||||||||
} | ||||||||
if self.show_help_toggle && !input::is_help_toggle(&event) { | ||||||||
Comment on lines
+184
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, take it or leave it: if we used
Suggested change
|
||||||||
// We have some other key pressed; clear the help popup. | ||||||||
self.show_help_toggle = !self.show_help_toggle; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
pub(crate) fn render<B: tui::backend::Backend>( | ||||||||
&mut self, | ||||||||
frame: &mut tui::terminal::Frame<B>, | ||||||||
area: layout::Rect, | ||||||||
state: &mut State, | ||||||||
) { | ||||||||
let mut help_content; | ||||||||
match self.state { | ||||||||
ViewState::TasksList => { | ||||||||
self.tasks_list.render(&self.styles, frame, area, state, ()); | ||||||||
help_content = HelpView::new(TableListState::<TasksTable>::render_help_content( | ||||||||
&self.styles, | ||||||||
)); | ||||||||
} | ||||||||
ViewState::ResourcesList => { | ||||||||
self.resources_list | ||||||||
.render(&self.styles, frame, area, state, ()); | ||||||||
help_content = HelpView::new( | ||||||||
TableListState::<ResourcesTable>::render_help_content(&self.styles), | ||||||||
); | ||||||||
} | ||||||||
ViewState::TaskInstance(ref mut view) => { | ||||||||
let now = state | ||||||||
.last_updated_at() | ||||||||
.expect("task view implies we've received an update"); | ||||||||
view.render(&self.styles, frame, area, now); | ||||||||
help_content = HelpView::new(TaskView::render_help_content(&self.styles)); | ||||||||
} | ||||||||
ViewState::ResourceInstance(ref mut view) => { | ||||||||
view.render(&self.styles, frame, area, state); | ||||||||
help_content = HelpView::new(ResourceView::render_help_content(&self.styles)); | ||||||||
Comment on lines
+201
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice that this will construct the help content for each view every time we render a screen, even if we're not showing the help window. That seems a little bit inefficient, since we have to allocate a big I think it might be more efficient to add a second |
||||||||
} | ||||||||
} | ||||||||
|
||||||||
state.retain_active(); | ||||||||
|
||||||||
if self.show_help_toggle { | ||||||||
help_content.render(&self.styles, frame, area, state); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
pub(crate) fn current_view(&self) -> &ViewState { | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,10 @@ impl TaskView { | |
frame.render_widget(fields_widget, fields_area); | ||
frame.render_widget(percentiles_widget, percentiles_area); | ||
} | ||
|
||
pub(in crate::view) fn render_help_content(_styles: &view::Styles) -> Spans<'static> { | ||
Spans::from(vec![Span::raw("A view to diplay help data for a task")]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this also include controls? |
||
} | ||
} | ||
|
||
impl Details { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason this has these arguments, when it doesn't use them? since this isn't a trait method, I think we should just not take these arguments just because they are passed to other views'
render
methods.