Skip to content

Commit 39400aa

Browse files
author
Stephan Dilly
authored
pending merge: more obvious repo state visualization (#943)
fixes #925
1 parent d78b029 commit 39400aa

File tree

3 files changed

+58
-38
lines changed

3 files changed

+58
-38
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
**rebase merge with conflicts**
11+
12+
![rebase-merge](assets/rebase.png)
13+
1014
## Added
1115
- support rebasing branches with conflicts ([#895](https://github.com/extrawurst/gitui/issues/895))
1216
- add a key binding to stage / unstage items [[@alessandroasm](https://github.com/alessandroasm)] ([#909](https://github.com/extrawurst/gitui/issues/909))

assets/rebase.png

510 KB
Loading

src/tabs/status.rs

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ use crossbeam_channel::Sender;
2323
use crossterm::event::Event;
2424
use itertools::Itertools;
2525
use std::convert::Into;
26-
use std::convert::TryFrom;
2726
use tui::{
2827
layout::{Alignment, Constraint, Direction, Layout},
2928
style::{Color, Style},
30-
widgets::Paragraph,
29+
widgets::{Block, BorderType, Borders, Paragraph},
3130
};
3231

3332
/// what part of the screen is focused
@@ -80,6 +79,19 @@ impl DrawableComponent for Status {
8079
f: &mut tui::Frame<B>,
8180
rect: tui::layout::Rect,
8281
) -> Result<()> {
82+
let repo_unclean = Self::repo_state_unclean();
83+
let rects = if repo_unclean {
84+
Layout::default()
85+
.direction(Direction::Vertical)
86+
.constraints(
87+
[Constraint::Min(1), Constraint::Length(3)]
88+
.as_ref(),
89+
)
90+
.split(rect)
91+
} else {
92+
vec![rect]
93+
};
94+
8395
let chunks = Layout::default()
8496
.direction(Direction::Horizontal)
8597
.constraints(
@@ -96,7 +108,7 @@ impl DrawableComponent for Status {
96108
}
97109
.as_ref(),
98110
)
99-
.split(rect);
111+
.split(rects[0]);
100112

101113
let left_chunks = Layout::default()
102114
.direction(Direction::Vertical)
@@ -120,7 +132,10 @@ impl DrawableComponent for Status {
120132
self.index.draw(f, left_chunks[1])?;
121133
self.diff.draw(f, chunks[1])?;
122134
self.draw_branch_state(f, &left_chunks);
123-
Self::draw_repo_state(f, left_chunks[0])?;
135+
136+
if repo_unclean {
137+
Self::draw_repo_state(f, rects[1]);
138+
}
124139

125140
Ok(())
126141
}
@@ -221,32 +236,27 @@ impl Status {
221236
let ids =
222237
sync::mergehead_ids(CWD).unwrap_or_default();
223238

224-
let ids = format!(
225-
"({})",
239+
format!(
240+
"Commits: {}",
226241
ids.iter()
227242
.map(sync::CommitId::get_short_string)
228243
.join(",")
229-
);
230-
231-
format!("{:?} {}", state, ids)
244+
)
232245
}
233246
RepoState::Rebase => {
234-
let progress =
235-
if let Ok(p) = sync::rebase_progress(CWD) {
236-
format!(
237-
"[{}] {}/{}",
238-
p.current_commit
239-
.as_ref()
240-
.map(CommitId::get_short_string)
241-
.unwrap_or_default(),
242-
p.current + 1,
243-
p.steps
244-
)
245-
} else {
246-
String::new()
247-
};
248-
249-
format!("{:?} ({})", state, progress)
247+
if let Ok(p) = sync::rebase_progress(CWD) {
248+
format!(
249+
"Step: {}/{} Current Commit: {}",
250+
p.current + 1,
251+
p.steps,
252+
p.current_commit
253+
.as_ref()
254+
.map(CommitId::get_short_string)
255+
.unwrap_or_default(),
256+
)
257+
} else {
258+
String::new()
259+
}
250260
}
251261
_ => format!("{:?}", state),
252262
}
@@ -255,30 +265,36 @@ impl Status {
255265
fn draw_repo_state<B: tui::backend::Backend>(
256266
f: &mut tui::Frame<B>,
257267
r: tui::layout::Rect,
258-
) -> Result<()> {
268+
) {
259269
if let Ok(state) = sync::repo_state(CWD) {
260270
if state != RepoState::Clean {
261271
let txt = Self::repo_state_text(&state);
262272

263-
let txt_len = u16::try_from(txt.len())?;
264273
let w = Paragraph::new(txt)
274+
.block(
275+
Block::default()
276+
.border_type(BorderType::Plain)
277+
.borders(Borders::all())
278+
.border_style(
279+
Style::default().fg(Color::Yellow),
280+
)
281+
.title(format!("Pending {:?}", state)),
282+
)
265283
.style(Style::default().fg(Color::Red))
266284
.alignment(Alignment::Left);
267285

268-
let mut rect = r;
269-
rect.x += 1;
270-
rect.width =
271-
rect.width.saturating_sub(2).min(txt_len);
272-
rect.y += rect.height.saturating_sub(1);
273-
rect.height = rect
274-
.height
275-
.saturating_sub(rect.height.saturating_sub(1));
276-
277-
f.render_widget(w, rect);
286+
f.render_widget(w, r);
278287
}
279288
}
289+
}
280290

281-
Ok(())
291+
fn repo_state_unclean() -> bool {
292+
if let Ok(state) = sync::repo_state(CWD) {
293+
if state != RepoState::Clean {
294+
return true;
295+
}
296+
}
297+
false
282298
}
283299

284300
fn can_focus_diff(&self) -> bool {

0 commit comments

Comments
 (0)