Skip to content

Commit

Permalink
show branchname in commit mssage box (closes #529)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Feb 23, 2021
1 parent 5cf9986 commit e3bb51b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
![push](assets/char_count.gif)

### Fixed
- don't hide branch name while in commit dialog ([#529](https://github.com/extrawurst/gitui/issues/529))
- don't discard commit message without confirmation ([#530](https://github.com/extrawurst/gitui/issues/530))
- compilation broken on freebsd ([#461](https://github.com/extrawurst/gitui/issues/461))
- 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))
Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ impl App {
pub fn update(&mut self) -> Result<()> {
log::trace!("update");

self.commit.update()?;
self.status_tab.update()?;
self.revlog.update()?;
self.stashing_tab.update()?;
Expand Down
37 changes: 35 additions & 2 deletions src/components/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};
use anyhow::Result;
use asyncgit::{
cached,
sync::{self, CommitId, HookResult},
CWD,
};
Expand All @@ -21,13 +22,19 @@ use std::{
io::{Read, Write},
path::PathBuf,
};
use tui::{backend::Backend, layout::Rect, Frame};
use tui::{
backend::Backend,
layout::{Alignment, Rect},
widgets::Paragraph,
Frame,
};

pub struct CommitComponent {
input: TextInputComponent,
amend: Option<CommitId>,
queue: Queue,
key_config: SharedKeyConfig,
git_branch_name: cached::BranchName,
}

impl DrawableComponent for CommitComponent {
Expand All @@ -36,7 +43,10 @@ impl DrawableComponent for CommitComponent {
f: &mut Frame<B>,
rect: Rect,
) -> Result<()> {
self.input.draw(f, rect)?;
if self.is_visible() {
self.input.draw(f, rect)?;
self.draw_branch_name(f);
}

Ok(())
}
Expand Down Expand Up @@ -143,6 +153,29 @@ impl CommitComponent {
true,
),
key_config,
git_branch_name: cached::BranchName::new(CWD),
}
}

///
pub fn update(&mut self) -> Result<()> {
self.git_branch_name.lookup().map(Some).unwrap_or(None);
Ok(())
}

fn draw_branch_name<B: Backend>(&self, f: &mut Frame<B>) {
if let Some(name) = self.git_branch_name.last() {
let w = Paragraph::new(format!("{{{}}}", name))
.alignment(Alignment::Right);

let rect = {
let mut rect = self.input.get_area();
rect.height = 1;
rect.width = rect.width.saturating_sub(1);
rect
};

f.render_widget(w, rect);
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/components/textinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
use anyhow::Result;
use crossterm::event::{Event, KeyCode, KeyModifiers};
use itertools::Itertools;
use std::{collections::HashMap, ops::Range};
use std::{cell::Cell, collections::HashMap, ops::Range};
use tui::{
backend::Backend,
layout::{Alignment, Rect},
Expand Down Expand Up @@ -39,6 +39,7 @@ pub struct TextInputComponent {
key_config: SharedKeyConfig,
cursor_position: usize,
input_type: InputType,
current_area: Cell<Rect>,
}

impl TextInputComponent {
Expand All @@ -60,6 +61,7 @@ impl TextInputComponent {
default_msg: default_msg.to_string(),
cursor_position: 0,
input_type: InputType::Multiline,
current_area: Cell::new(Rect::default()),
}
}

Expand All @@ -82,6 +84,11 @@ impl TextInputComponent {
&self.msg
}

/// screen area (last time we got drawn)
pub fn get_area(&self) -> Rect {
self.current_area.get()
}

/// Move the cursor right one char.
fn incr_cursor(&mut self) {
if let Some(pos) = self.next_char_position() {
Expand Down Expand Up @@ -298,6 +305,8 @@ impl DrawableComponent for TextInputComponent {
if self.show_char_count {
self.draw_char_count(f, area);
}

self.current_area.set(area);
}

Ok(())
Expand Down

0 comments on commit e3bb51b

Please sign in to comment.