From e3bb51b2775eaa892e8dc5d475d352a20973d248 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Tue, 23 Feb 2021 16:35:48 +0100 Subject: [PATCH] show branchname in commit mssage box (closes #529) --- CHANGELOG.md | 1 + src/app.rs | 1 + src/components/commit.rs | 37 +++++++++++++++++++++++++++++++++++-- src/components/textinput.rs | 11 ++++++++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47fd5f0af2..0ef16b655f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/app.rs b/src/app.rs index 4d10352f5d..b9c544b0fa 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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()?; diff --git a/src/components/commit.rs b/src/components/commit.rs index 3678e48756..5ff7c2f8be 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -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, 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, 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(&self, f: &mut Frame) { + 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); } } diff --git a/src/components/textinput.rs b/src/components/textinput.rs index fcb76411a4..2f676dd227 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -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, } 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(())