From ade699870bc2c0147c6b9da0770243f983b918b5 Mon Sep 17 00:00:00 2001 From: lecheel Date: Mon, 24 Aug 2026 15:35:11 +0800 Subject: [PATCH 1/3] feat: add panel jump shortcuts - Implement `jump_to_panel` to switch active views - Map keys 0-3 to specific panels in `main.rs` - Update `create_title` to display panel IDs in the UI --- src/app.rs | 23 +++++++++++++++++++++++ src/main.rs | 4 ++++ src/ui.rs | 44 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/app.rs b/src/app.rs index 8362e2e..fecf303 100644 --- a/src/app.rs +++ b/src/app.rs @@ -423,6 +423,29 @@ 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..e676dec 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -171,20 +171,42 @@ 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(format!("{}", title))); + } + + // 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 +229,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 +272,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 +296,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 +335,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 +359,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 +473,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, From f9c593c679c66596b5d7298998d33b1ffe37d61f Mon Sep 17 00:00:00 2001 From: lecheel Date: Mon, 24 Aug 2026 15:43:26 +0800 Subject: [PATCH 2/3] style: clean up formatting in app and ui modules - Remove redundant newline in `app.rs` - Format style chain in `ui.rs` for better readability --- src/app.rs | 1 - src/ui.rs | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index fecf303..0e58287 100644 --- a/src/app.rs +++ b/src/app.rs @@ -424,7 +424,6 @@ 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 { diff --git a/src/ui.rs b/src/ui.rs index e676dec..fe767c3 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -178,7 +178,9 @@ fn create_title<'a>(id: &'a str, title: &'a str, hint: &'a str, color: bool) -> let id_span = if color { Span::styled( format!(" {} ", id), - Style::default().fg(Color::Cyan).add_modifier(Modifier::BOLD), + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), ) } else { Span::raw(format!(" {} ", id)) From dba886728aa73a62a4cbfc42da3f203968a46710 Mon Sep 17 00:00:00 2001 From: lecheel Date: Mon, 24 Aug 2026 15:58:07 +0800 Subject: [PATCH 3/3] docs: update CHANGELOG, fix clippy lint --- CHANGELOG.md | 5 ++++- src/ui.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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/ui.rs b/src/ui.rs index fe767c3..e9ec32a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -192,7 +192,7 @@ fn create_title<'a>(id: &'a str, title: &'a str, hint: &'a str, color: bool) -> if id.is_empty() { spans.push(Span::raw(format!(" {}", title))); } else { - spans.push(Span::raw(format!("{}", title))); + spans.push(Span::raw(title.to_string())); } // Add hint with a leading space