Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
22 changes: 22 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,28 @@ impl App {
}
Ok(reload_file_diff)
}

pub fn jump_to_panel(&mut self, panel: u8) -> Result<bool, String> {
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 };
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
_ => {
Expand Down
46 changes: 38 additions & 8 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,44 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, 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,
Expand All @@ -207,6 +231,7 @@ fn draw_branches<B: Backend>(f: &mut Frame<B>, 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,
Expand Down Expand Up @@ -249,6 +274,7 @@ fn draw_branches<B: Backend>(f: &mut Frame<B>, target: Rect, app: &mut App) {

fn draw_commit<B: Backend>(f: &mut Frame<B>, target: Rect, app: &mut App) {
let mut block = Block::default().borders(Borders::ALL).title(create_title(
"(2)",
"Commit",
" <-Graph | Files-> ",
app.color,
Expand All @@ -272,6 +298,7 @@ fn draw_files<B: Backend>(f: &mut Frame<B>, 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,
Expand Down Expand Up @@ -310,6 +337,7 @@ fn draw_files<B: Backend>(f: &mut Frame<B>, 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,
Expand All @@ -333,6 +361,7 @@ fn draw_diff<B: Backend>(f: &mut Frame<B>, 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,
Expand Down Expand Up @@ -446,6 +475,7 @@ fn draw_diff<B: Backend>(f: &mut Frame<B>, 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,
Expand Down
Loading