diff --git a/CHANGELOG.md b/CHANGELOG.md index dee31dc..8d6c737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Changed +### Added +- Panel jump shortcuts: keys 0–3 to switch between panels. +### Changed +- Clean up formatting in `app.rs` and `ui.rs`. - Upgrade to gleisbau 0.7.3 diff --git a/src/app.rs b/src/app.rs index 8362e2e..0e58287 100644 --- a/src/app.rs +++ b/src/app.rs @@ -423,6 +423,28 @@ impl App { } Ok(reload_file_diff) } + + pub fn jump_to_panel(&mut self, panel: u8) -> Result { + let mut reload_file_diff = false; + let new_view = match panel { + 0 => ActiveView::Branches, + 1 => ActiveView::Graph, + 2 => ActiveView::Commit, + 3 => { + if let Some(commit) = &mut self.commit_state.content { + if commit.diffs.state.selected.is_none() && !commit.diffs.items.is_empty() { + commit.diffs.state.selected = Some(0); + reload_file_diff = true; + } + } + ActiveView::Files + } + _ => return Ok(false), + }; + self.active_view = new_view; + Ok(reload_file_diff) + } + pub fn on_left(&mut self, is_shift: bool, is_ctrl: bool) { if is_ctrl { let step = if is_shift { 15 } else { 3 }; diff --git a/src/main.rs b/src/main.rs index 45b4f7d..64008f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -607,6 +607,10 @@ fn run( } KeyCode::Char('h') => app.show_help(), KeyCode::F(1) => app.show_help(), + KeyCode::Char('0') => reload_file = app.jump_to_panel(0)?, + KeyCode::Char('1') => reload_file = app.jump_to_panel(1)?, + KeyCode::Char('2') => reload_file = app.jump_to_panel(2)?, + KeyCode::Char('3') => reload_file = app.jump_to_panel(3)?, KeyCode::Char('m') => match app.active_view { ActiveView::Models | ActiveView::Search | ActiveView::Help(_) => {} _ => { diff --git a/src/ui.rs b/src/ui.rs index 3cb4b70..e9ec32a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -171,20 +171,44 @@ pub fn draw(f: &mut Frame, app: &mut App) { } } -fn create_title<'a>(title: &'a str, hint: &'a str, color: bool) -> Spans<'a> { - Spans(vec![ - Span::raw(format!(" {} ", title)), - if color { - Span::styled(hint, *HINT_STYLE) +fn create_title<'a>(id: &'a str, title: &'a str, hint: &'a str, color: bool) -> Spans<'a> { + let mut spans = Vec::new(); + + if !id.is_empty() { + let id_span = if color { + Span::styled( + format!(" {} ", id), + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ) } else { - Span::raw(hint) - }, - ]) + Span::raw(format!(" {} ", id)) + }; + spans.push(id_span); + } + + // Add title with a leading space only if no id was added + if id.is_empty() { + spans.push(Span::raw(format!(" {}", title))); + } else { + spans.push(Span::raw(title.to_string())); + } + + // Add hint with a leading space + if color { + spans.push(Span::styled(format!(" {}", hint), *HINT_STYLE)); + } else { + spans.push(Span::raw(format!(" {}", hint))); + } + + Spans(spans) } fn draw_graph(f: &mut Frame, target: Rect, app: &mut App) { let title = format!("Graph - {}", app.repo_name); let mut block = Block::default().borders(Borders::ALL).title(create_title( + "(1)", &title, " <-Branches | Commit-> ", app.color, @@ -207,6 +231,7 @@ fn draw_branches(f: &mut Frame, target: Rect, app: &mut App) { let color = app.color; let mut block = Block::default().borders(Borders::ALL).title(create_title( + "(0)", "Branches", " Graph-> ", app.color, @@ -249,6 +274,7 @@ fn draw_branches(f: &mut Frame, target: Rect, app: &mut App) { fn draw_commit(f: &mut Frame, target: Rect, app: &mut App) { let mut block = Block::default().borders(Borders::ALL).title(create_title( + "(2)", "Commit", " <-Graph | Files-> ", app.color, @@ -272,6 +298,7 @@ fn draw_files(f: &mut Frame, target: Rect, app: &mut App) { &state.oid.to_string()[..7] ); let mut block = Block::default().borders(Borders::ALL).title(create_title( + "(3)", &title, " <-Commit | Diff-> ", app.color, @@ -310,6 +337,7 @@ fn draw_files(f: &mut Frame, target: Rect, app: &mut App) { f.render_stateful_widget(list, target, &mut state.diffs.state); } else { let mut block = Block::default().borders(Borders::ALL).title(create_title( + "(3)", "Files", " <-Commit | Diff-> ", app.color, @@ -333,6 +361,7 @@ fn draw_diff(f: &mut Frame, target: Rect, app: &mut App) { DiffMode::New => format!("Diff (new: {})", &state.oid.to_string()[..7],), }; let mut block = Block::default().borders(Borders::ALL).title(create_title( + "", &title, " <-Files ", app.color, @@ -446,6 +475,7 @@ fn draw_diff(f: &mut Frame, target: Rect, app: &mut App) { f.render_widget(paragraph, target); } else { let mut block = Block::default().borders(Borders::ALL).title(create_title( + "", "Diff", " <-Files ", app.color,