mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
support showing char count (closes #466)
This commit is contained in:
parent
c0d0e31186
commit
c428db09f6
7 changed files with 43 additions and 2 deletions
|
|
@ -138,6 +138,7 @@ impl CommitComponent {
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
"",
|
"",
|
||||||
&strings::commit_msg(&key_config),
|
&strings::commit_msg(&key_config),
|
||||||
|
true,
|
||||||
),
|
),
|
||||||
key_config,
|
key_config,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ impl CreateBranchComponent {
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
&strings::create_branch_popup_title(&key_config),
|
&strings::create_branch_popup_title(&key_config),
|
||||||
&strings::create_branch_popup_msg(&key_config),
|
&strings::create_branch_popup_msg(&key_config),
|
||||||
|
true,
|
||||||
),
|
),
|
||||||
commit_id: None,
|
commit_id: None,
|
||||||
key_config,
|
key_config,
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ impl CredComponent {
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
&strings::username_popup_title(&key_config),
|
&strings::username_popup_title(&key_config),
|
||||||
&strings::username_popup_msg(&key_config),
|
&strings::username_popup_msg(&key_config),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.with_input_type(InputType::Singleline),
|
.with_input_type(InputType::Singleline),
|
||||||
input_password: TextInputComponent::new(
|
input_password: TextInputComponent::new(
|
||||||
|
|
@ -44,6 +45,7 @@ impl CredComponent {
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
&strings::password_popup_title(&key_config),
|
&strings::password_popup_title(&key_config),
|
||||||
&strings::password_popup_msg(&key_config),
|
&strings::password_popup_msg(&key_config),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.with_input_type(InputType::Password),
|
.with_input_type(InputType::Password),
|
||||||
key_config,
|
key_config,
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ impl RenameBranchComponent {
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
&strings::rename_branch_popup_title(&key_config),
|
&strings::rename_branch_popup_title(&key_config),
|
||||||
&strings::rename_branch_popup_msg(&key_config),
|
&strings::rename_branch_popup_msg(&key_config),
|
||||||
|
true,
|
||||||
),
|
),
|
||||||
branch_ref: None,
|
branch_ref: None,
|
||||||
key_config,
|
key_config,
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ impl StashMsgComponent {
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
&strings::stash_popup_title(&key_config),
|
&strings::stash_popup_title(&key_config),
|
||||||
&strings::stash_popup_msg(&key_config),
|
&strings::stash_popup_msg(&key_config),
|
||||||
|
true,
|
||||||
),
|
),
|
||||||
key_config,
|
key_config,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ impl TagCommitComponent {
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
&strings::tag_commit_popup_title(&key_config),
|
&strings::tag_commit_popup_title(&key_config),
|
||||||
&strings::tag_commit_popup_msg(&key_config),
|
&strings::tag_commit_popup_msg(&key_config),
|
||||||
|
true,
|
||||||
),
|
),
|
||||||
commit_id: None,
|
commit_id: None,
|
||||||
key_config,
|
key_config,
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ use itertools::Itertools;
|
||||||
use std::{collections::HashMap, ops::Range};
|
use std::{collections::HashMap, ops::Range};
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
layout::Rect,
|
layout::{Alignment, Rect},
|
||||||
style::Modifier,
|
style::Modifier,
|
||||||
text::{Spans, Text},
|
text::{Spans, Text},
|
||||||
widgets::Clear,
|
widgets::{Clear, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -34,6 +34,7 @@ pub struct TextInputComponent {
|
||||||
default_msg: String,
|
default_msg: String,
|
||||||
msg: String,
|
msg: String,
|
||||||
visible: bool,
|
visible: bool,
|
||||||
|
show_char_count: bool,
|
||||||
theme: SharedTheme,
|
theme: SharedTheme,
|
||||||
key_config: SharedKeyConfig,
|
key_config: SharedKeyConfig,
|
||||||
cursor_position: usize,
|
cursor_position: usize,
|
||||||
|
|
@ -47,12 +48,14 @@ impl TextInputComponent {
|
||||||
key_config: SharedKeyConfig,
|
key_config: SharedKeyConfig,
|
||||||
title: &str,
|
title: &str,
|
||||||
default_msg: &str,
|
default_msg: &str,
|
||||||
|
show_char_count: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
msg: String::new(),
|
msg: String::new(),
|
||||||
visible: false,
|
visible: false,
|
||||||
theme,
|
theme,
|
||||||
key_config,
|
key_config,
|
||||||
|
show_char_count,
|
||||||
title: title.to_string(),
|
title: title.to_string(),
|
||||||
default_msg: default_msg.to_string(),
|
default_msg: default_msg.to_string(),
|
||||||
cursor_position: 0,
|
cursor_position: 0,
|
||||||
|
|
@ -209,6 +212,28 @@ impl TextInputComponent {
|
||||||
_ => self.msg[range].to_owned(),
|
_ => self.msg[range].to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_char_count<B: Backend>(&self, f: &mut Frame<B>, r: Rect) {
|
||||||
|
let count = self.msg.len();
|
||||||
|
if count > 0 {
|
||||||
|
let w = Paragraph::new(format!("[{} chars]", count))
|
||||||
|
.alignment(Alignment::Right);
|
||||||
|
|
||||||
|
let mut rect = {
|
||||||
|
let mut rect = r;
|
||||||
|
rect.y += rect.height.saturating_sub(1);
|
||||||
|
rect
|
||||||
|
};
|
||||||
|
|
||||||
|
rect.x += 1;
|
||||||
|
rect.width = rect.width.saturating_sub(2);
|
||||||
|
rect.height = rect
|
||||||
|
.height
|
||||||
|
.saturating_sub(rect.height.saturating_sub(1));
|
||||||
|
|
||||||
|
f.render_widget(w, rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// merges last line of `txt` with first of `append` so we do not generate unneeded newlines
|
// merges last line of `txt` with first of `append` so we do not generate unneeded newlines
|
||||||
|
|
@ -269,6 +294,10 @@ impl DrawableComponent for TextInputComponent {
|
||||||
),
|
),
|
||||||
area,
|
area,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if self.show_char_count {
|
||||||
|
self.draw_char_count(f, area);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -369,6 +398,7 @@ mod tests {
|
||||||
SharedKeyConfig::default(),
|
SharedKeyConfig::default(),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
comp.set_text(String::from("a\nb"));
|
comp.set_text(String::from("a\nb"));
|
||||||
|
|
@ -389,6 +419,7 @@ mod tests {
|
||||||
SharedKeyConfig::default(),
|
SharedKeyConfig::default(),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
let theme = SharedTheme::default();
|
let theme = SharedTheme::default();
|
||||||
let underlined = theme
|
let underlined = theme
|
||||||
|
|
@ -411,6 +442,7 @@ mod tests {
|
||||||
SharedKeyConfig::default(),
|
SharedKeyConfig::default(),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
let theme = SharedTheme::default();
|
let theme = SharedTheme::default();
|
||||||
let underlined_whitespace = theme
|
let underlined_whitespace = theme
|
||||||
|
|
@ -444,6 +476,7 @@ mod tests {
|
||||||
SharedKeyConfig::default(),
|
SharedKeyConfig::default(),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let theme = SharedTheme::default();
|
let theme = SharedTheme::default();
|
||||||
|
|
@ -473,6 +506,7 @@ mod tests {
|
||||||
SharedKeyConfig::default(),
|
SharedKeyConfig::default(),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let theme = SharedTheme::default();
|
let theme = SharedTheme::default();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue