Skip to content

Commit

Permalink
✨ added configuration scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Nov 17, 2021
1 parent 6e929dc commit 7f60ba6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct App<'a> {
pub config_display_mode: ConfigDisplayMode,
pub should_quit: bool,
pub should_spawn_ssh: bool,
pub config_paragraph_offset: u16,
}

impl App<'_> {
Expand Down
7 changes: 7 additions & 0 deletions src/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ pub fn handle_inputs(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
};
app.host_state.select(Some(i));
}
KeyCode::PageDown => {
app.config_paragraph_offset += 1;
}
KeyCode::PageUp => {
app.config_paragraph_offset =
(app.config_paragraph_offset as i64 - 1).max(0) as u16;
}
KeyCode::Char('c') => {
app.config_display_mode = match app.config_display_mode {
ConfigDisplayMode::Global => ConfigDisplayMode::Selected,
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut app = App {
selected_group: 0,
config_paragraph_offset: 0,
groups: &scs.groups,
host_state: ListState::default(),
should_quit: false,
Expand All @@ -55,7 +56,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.constraints(
[
Constraint::Percentage(40),
Constraint::Length(2),
Constraint::Percentage(40),
Constraint::Length(2),
Constraint::Percentage(20),
]
.as_ref(),
Expand All @@ -64,8 +67,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

render_group_tabs(&app, chunks[0], frame);
render_host_list(&mut app, chunk_b[0], frame);
render_config(&mut app, chunk_b[1], frame);
render_shortcuts(&app, chunk_b[2], frame);
render_config(&mut app, chunk_b[2], frame);
render_shortcuts(&app, chunk_b[4], frame);
})?;

handle_inputs(&mut app)?;
Expand Down
2 changes: 1 addition & 1 deletion src/render_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn render_config(app: &mut App, area: Rect, frame: &mut Frame<CrosstermBacke
ConfigDisplayMode::Global => get_paragraph_for_global_mode(app, block),
};

frame.render_widget(paragraph, area);
frame.render_widget(paragraph.scroll((app.config_paragraph_offset, 0)), area);
}

fn get_paragraph_for_global_mode<'a>(app: &'a App, block: Block<'a>) -> Paragraph<'a> {
Expand Down
1 change: 1 addition & 0 deletions src/render_shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn render_shortcuts(_app: &App, area: Rect, frame: &mut Frame<CrosstermBacke
Spans::from("'Enter': Validate"),
Spans::from("'Tab': Change Group"),
Spans::from("'c': Configuration Display Mode"),
Spans::from("'PageUp/Down': Scroll Configuration"),
// Spans::from("'g' to alternate between groups mode"),
Spans::from("'q': Exit"),
];
Expand Down

0 comments on commit 7f60ba6

Please sign in to comment.