-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): help view modal (#432)
- Loading branch information
Showing
8 changed files
with
184 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use ratatui::{ | ||
layout::{self, Constraint, Direction, Layout}, | ||
widgets::{Clear, Paragraph}, | ||
}; | ||
|
||
use crate::{state::State, view}; | ||
|
||
pub(crate) trait HelpText { | ||
fn render_help_content(&self, styles: &view::Styles) -> Paragraph<'static>; | ||
} | ||
|
||
/// Simple view for help popup | ||
pub(crate) struct HelpView<'a> { | ||
help_text: Option<Paragraph<'a>>, | ||
} | ||
|
||
impl<'a> HelpView<'a> { | ||
pub(super) fn new(help_text: Paragraph<'a>) -> Self { | ||
HelpView { | ||
help_text: Some(help_text), | ||
} | ||
} | ||
|
||
pub(crate) fn render<B: ratatui::backend::Backend>( | ||
&mut self, | ||
styles: &view::Styles, | ||
frame: &mut ratatui::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"); | ||
|
||
let popup_layout = Layout::default() | ||
.direction(Direction::Vertical) | ||
.constraints( | ||
[ | ||
Constraint::Percentage(20), | ||
Constraint::Min(15), | ||
Constraint::Percentage(20), | ||
] | ||
.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 = content.block(styles.border_block().title("Help")); | ||
|
||
// Clear the help block area and render the popup | ||
frame.render_widget(Clear, popup_area); | ||
frame.render_widget(display_text, popup_area); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters