Skip to content

show branchname in commit mssage box #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2021
Merged
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
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