Skip to content

Commit f377f93

Browse files
author
Stephan Dilly
committed
show branchname in commit mssage box (closes #529)
1 parent 5cf9986 commit f377f93

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
![push](assets/char_count.gif)
1616

1717
### Fixed
18+
- don't hide branch name while in commit dialog ([#529](https://github.com/extrawurst/gitui/issues/529))
1819
- don't discard commit message without confirmation ([#530](https://github.com/extrawurst/gitui/issues/530))
1920
- compilation broken on freebsd ([#461](https://github.com/extrawurst/gitui/issues/461))
2021
- don’t fail if `user.name` is not set [[@cruessler](https://github.com/cruessler)] ([#79](https://github.com/extrawurst/gitui/issues/79)) ([#228](https://github.com/extrawurst/gitui/issues/228))

src/app.rs

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl App {
278278
pub fn update(&mut self) -> Result<()> {
279279
log::trace!("update");
280280

281+
self.commit.update()?;
281282
self.status_tab.update()?;
282283
self.revlog.update()?;
283284
self.stashing_tab.update()?;

src/components/commit.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
};
1313
use anyhow::Result;
1414
use asyncgit::{
15+
cached,
1516
sync::{self, CommitId, HookResult},
1617
CWD,
1718
};
@@ -21,13 +22,19 @@ use std::{
2122
io::{Read, Write},
2223
path::PathBuf,
2324
};
24-
use tui::{backend::Backend, layout::Rect, Frame};
25+
use tui::{
26+
backend::Backend,
27+
layout::{Alignment, Rect},
28+
widgets::Paragraph,
29+
Frame,
30+
};
2531

2632
pub struct CommitComponent {
2733
input: TextInputComponent,
2834
amend: Option<CommitId>,
2935
queue: Queue,
3036
key_config: SharedKeyConfig,
37+
git_branch_name: cached::BranchName,
3138
}
3239

3340
impl DrawableComponent for CommitComponent {
@@ -36,7 +43,10 @@ impl DrawableComponent for CommitComponent {
3643
f: &mut Frame<B>,
3744
rect: Rect,
3845
) -> Result<()> {
39-
self.input.draw(f, rect)?;
46+
if self.is_visible() {
47+
self.input.draw(f, rect)?;
48+
self.draw_branch_name(f);
49+
}
4050

4151
Ok(())
4252
}
@@ -143,6 +153,29 @@ impl CommitComponent {
143153
true,
144154
),
145155
key_config,
156+
git_branch_name: cached::BranchName::new(CWD),
157+
}
158+
}
159+
160+
///
161+
pub fn update(&mut self) -> Result<()> {
162+
self.git_branch_name.lookup().map(Some).unwrap_or(None);
163+
Ok(())
164+
}
165+
166+
fn draw_branch_name<B: Backend>(&self, f: &mut Frame<B>) {
167+
if let Some(name) = self.git_branch_name.last() {
168+
let w = Paragraph::new(format!("{{{}}}", name))
169+
.alignment(Alignment::Right);
170+
171+
let rect = {
172+
let mut rect = self.input.get_area();
173+
rect.height = 1;
174+
rect.width = rect.width.saturating_sub(1);
175+
rect
176+
};
177+
178+
f.render_widget(w, rect);
146179
}
147180
}
148181

src/components/textinput.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
use anyhow::Result;
1212
use crossterm::event::{Event, KeyCode, KeyModifiers};
1313
use itertools::Itertools;
14-
use std::{collections::HashMap, ops::Range};
14+
use std::{cell::Cell, collections::HashMap, ops::Range};
1515
use tui::{
1616
backend::Backend,
1717
layout::{Alignment, Rect},
@@ -39,6 +39,7 @@ pub struct TextInputComponent {
3939
key_config: SharedKeyConfig,
4040
cursor_position: usize,
4141
input_type: InputType,
42+
current_area: Cell<Rect>,
4243
}
4344

4445
impl TextInputComponent {
@@ -60,6 +61,7 @@ impl TextInputComponent {
6061
default_msg: default_msg.to_string(),
6162
cursor_position: 0,
6263
input_type: InputType::Multiline,
64+
current_area: Cell::new(Rect::default()),
6365
}
6466
}
6567

@@ -82,6 +84,11 @@ impl TextInputComponent {
8284
&self.msg
8385
}
8486

87+
/// screen area (last time we got drawn)
88+
pub fn get_area(&self) -> Rect {
89+
self.current_area.get()
90+
}
91+
8592
/// Move the cursor right one char.
8693
fn incr_cursor(&mut self) {
8794
if let Some(pos) = self.next_char_position() {
@@ -298,6 +305,8 @@ impl DrawableComponent for TextInputComponent {
298305
if self.show_char_count {
299306
self.draw_char_count(f, area);
300307
}
308+
309+
self.current_area.set(area);
301310
}
302311

303312
Ok(())

0 commit comments

Comments
 (0)