show branchname in commit mssage box (closes #529)

This commit is contained in:
Stephan Dilly 2021-02-23 16:35:48 +01:00
parent 5cf9986df9
commit e3bb51b277
4 changed files with 47 additions and 3 deletions

View file

@ -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))
- dont 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))

View file

@ -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()?;

View file

@ -12,6 +12,7 @@ use crate::{
};
use anyhow::Result;
use asyncgit::{
cached,
sync::{self, CommitId, HookResult},
CWD,
};
@ -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 {
@ -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(())
}
@ -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);
}
}

View file

@ -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},
@ -39,6 +39,7 @@ pub struct TextInputComponent {
key_config: SharedKeyConfig,
cursor_position: usize,
input_type: InputType,
current_area: Cell<Rect>,
}
impl TextInputComponent {
@ -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()),
}
}
@ -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() {
@ -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(())