Skip to content

Commit beb118c

Browse files
committed
show key hint as config
1 parent 7f85768 commit beb118c

24 files changed

+1051
-466
lines changed

src/app.rs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
input::{Input, InputEvent, InputState},
1111
keys::{KeyConfig, SharedKeyConfig},
1212
queue::{Action, InternalEvent, NeedsUpdate, Queue},
13-
strings::{self, commands, order},
13+
strings::{self, order},
1414
tabs::{Revlog, StashList, Stashing, Status},
1515
ui::style::{SharedTheme, Theme},
1616
};
@@ -71,7 +71,11 @@ impl App {
7171

7272
Self {
7373
input,
74-
reset: ResetComponent::new(queue.clone(), theme.clone()),
74+
reset: ResetComponent::new(
75+
queue.clone(),
76+
theme.clone(),
77+
key_config.clone(),
78+
),
7579
commit: CommitComponent::new(
7680
queue.clone(),
7781
theme.clone(),
@@ -80,6 +84,7 @@ impl App {
8084
stashmsg_popup: StashMsgComponent::new(
8185
queue.clone(),
8286
theme.clone(),
87+
key_config.clone(),
8388
),
8489
inspect_commit_popup: InspectCommitComponent::new(
8590
&queue,
@@ -89,13 +94,18 @@ impl App {
8994
),
9095
external_editor_popup: ExternalEditorComponent::new(
9196
theme.clone(),
97+
key_config.clone(),
9298
),
9399
tag_commit_popup: TagCommitComponent::new(
94100
queue.clone(),
95101
theme.clone(),
102+
key_config.clone(),
96103
),
97104
do_quit: false,
98-
cmdbar: RefCell::new(CommandBar::new(theme.clone())),
105+
cmdbar: RefCell::new(CommandBar::new(
106+
theme.clone(),
107+
key_config.clone(),
108+
)),
99109
help: HelpComponent::new(
100110
theme.clone(),
101111
key_config.clone(),
@@ -191,10 +201,10 @@ impl App {
191201
{
192202
self.toggle_tabs(true)?;
193203
NeedsUpdate::COMMANDS
194-
} else if k == self.key_config.tab_1
195-
|| k == self.key_config.tab_2
196-
|| k == self.key_config.tab_3
197-
|| k == self.key_config.tab_4
204+
} else if k == self.key_config.tab_status
205+
|| k == self.key_config.tab_log
206+
|| k == self.key_config.tab_stashing
207+
|| k == self.key_config.tab_stashes
198208
{
199209
self.switch_tab(k)?;
200210
NeedsUpdate::COMMANDS
@@ -360,13 +370,13 @@ impl App {
360370
}
361371

362372
fn switch_tab(&mut self, k: KeyEvent) -> Result<()> {
363-
if k == self.key_config.tab_1 {
373+
if k == self.key_config.tab_status {
364374
self.set_tab(0)?
365-
} else if k == self.key_config.tab_2 {
375+
} else if k == self.key_config.tab_log {
366376
self.set_tab(1)?
367-
} else if k == self.key_config.tab_3 {
377+
} else if k == self.key_config.tab_stashing {
368378
self.set_tab(2)?
369-
} else if k == self.key_config.tab_4 {
379+
} else if k == self.key_config.tab_stashes {
370380
self.set_tab(3)?
371381
}
372382

@@ -479,15 +489,19 @@ impl App {
479489

480490
res.push(
481491
CommandInfo::new(
482-
commands::TOGGLE_TABS,
492+
strings::commands::toggle_tabs(
493+
self.key_config.clone(),
494+
),
483495
true,
484496
!self.any_popup_visible(),
485497
)
486498
.order(order::NAV),
487499
);
488500
res.push(
489501
CommandInfo::new(
490-
commands::TOGGLE_TABS_DIRECT,
502+
strings::commands::toggle_tabs_direct(
503+
self.key_config.clone(),
504+
),
491505
true,
492506
!self.any_popup_visible(),
493507
)
@@ -496,7 +510,7 @@ impl App {
496510

497511
res.push(
498512
CommandInfo::new(
499-
commands::QUIT,
513+
strings::commands::quit(self.key_config.clone()),
500514
true,
501515
!self.any_popup_visible(),
502516
)
@@ -552,10 +566,10 @@ impl App {
552566
});
553567

554568
let tabs = &[
555-
strings::TAB_STATUS,
556-
strings::TAB_LOG,
557-
strings::TAB_STASHING,
558-
strings::TAB_STASHES,
569+
strings::tab_status(self.key_config.clone()),
570+
strings::tab_log(self.key_config.clone()),
571+
strings::tab_stashing(self.key_config.clone()),
572+
strings::tab_stashes(self.key_config.clone()),
559573
];
560574

561575
f.render_widget(
@@ -568,7 +582,9 @@ impl App {
568582
.titles(tabs)
569583
.style(self.theme.tab(false))
570584
.highlight_style(self.theme.tab(true))
571-
.divider(strings::TAB_DIVIDER)
585+
.divider(&strings::tab_divider(
586+
self.key_config.clone(),
587+
))
572588
.select(self.tab),
573589
r,
574590
);

src/cmdbar.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
components::CommandInfo, strings, ui::style::SharedTheme,
2+
components::CommandInfo, keys::SharedKeyConfig, strings,
3+
ui::style::SharedTheme,
34
};
45
use std::borrow::Cow;
56
use tui::{
@@ -27,6 +28,7 @@ pub struct CommandBar {
2728
draw_list: Vec<DrawListEntry>,
2829
cmd_infos: Vec<CommandInfo>,
2930
theme: SharedTheme,
31+
key_config: SharedKeyConfig,
3032
lines: u16,
3133
width: u16,
3234
expandable: bool,
@@ -36,11 +38,15 @@ pub struct CommandBar {
3638
const MORE_WIDTH: u16 = 11;
3739

3840
impl CommandBar {
39-
pub const fn new(theme: SharedTheme) -> Self {
41+
pub const fn new(
42+
theme: SharedTheme,
43+
key_config: SharedKeyConfig,
44+
) -> Self {
4045
Self {
4146
draw_list: Vec::new(),
4247
cmd_infos: Vec::new(),
4348
theme,
49+
key_config,
4450
lines: 0,
4551
width: 0,
4652
expandable: false,
@@ -58,7 +64,8 @@ impl CommandBar {
5864
fn is_multiline(&self, width: u16) -> bool {
5965
let mut line_width = 0_usize;
6066
for c in &self.cmd_infos {
61-
let entry_w = UnicodeWidthStr::width(c.text.name);
67+
let entry_w =
68+
UnicodeWidthStr::width(c.text.name.as_str());
6269

6370
if line_width + entry_w > width as usize {
6471
return true;
@@ -83,7 +90,8 @@ impl CommandBar {
8390
let mut lines = 1_u16;
8491

8592
for c in &self.cmd_infos {
86-
let entry_w = UnicodeWidthStr::width(c.text.name);
93+
let entry_w =
94+
UnicodeWidthStr::width(c.text.name.as_str());
8795

8896
if line_width + entry_w > width as usize {
8997
self.draw_list.push(DrawListEntry::LineBreak);
@@ -131,7 +139,9 @@ impl CommandBar {
131139
}
132140

133141
pub fn draw<B: Backend>(&self, f: &mut Frame<B>, r: Rect) {
134-
let splitter = Text::Raw(Cow::from(strings::CMD_SPLITTER));
142+
let splitter = Text::Raw(Cow::from(strings::cmd_splitter(
143+
self.key_config.clone(),
144+
)));
135145

136146
let texts = self
137147
.draw_list

src/components/changes.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use anyhow::Result;
1414
use asyncgit::{cached, sync, StatusItem, StatusItemType, CWD};
1515
use crossterm::event::Event;
1616
use std::path::Path;
17-
use strings::commands;
1817
use tui::{backend::Backend, layout::Rect, Frame};
1918

2019
///
@@ -210,39 +209,51 @@ impl Component for ChangesComponent {
210209

211210
if self.is_working_dir {
212211
out.push(CommandInfo::new(
213-
commands::STAGE_ALL,
212+
strings::commands::stage_all(self.key_config.clone()),
214213
some_selection,
215214
self.focused(),
216215
));
217216
out.push(CommandInfo::new(
218-
commands::STAGE_ITEM,
217+
strings::commands::stage_item(
218+
self.key_config.clone(),
219+
),
219220
some_selection,
220221
self.focused(),
221222
));
222223
out.push(CommandInfo::new(
223-
commands::RESET_ITEM,
224+
strings::commands::reset_item(
225+
self.key_config.clone(),
226+
),
224227
some_selection,
225228
self.focused(),
226229
));
227230
out.push(CommandInfo::new(
228-
commands::IGNORE_ITEM,
231+
strings::commands::ignore_item(
232+
self.key_config.clone(),
233+
),
229234
some_selection,
230235
self.focused(),
231236
));
232237
} else {
233238
out.push(CommandInfo::new(
234-
commands::UNSTAGE_ITEM,
239+
strings::commands::unstage_item(
240+
self.key_config.clone(),
241+
),
235242
some_selection,
236243
self.focused(),
237244
));
238245
out.push(CommandInfo::new(
239-
commands::UNSTAGE_ALL,
246+
strings::commands::unstage_all(
247+
self.key_config.clone(),
248+
),
240249
some_selection,
241250
self.focused(),
242251
));
243252
out.push(
244253
CommandInfo::new(
245-
commands::COMMIT_OPEN,
254+
strings::commands::commit_open(
255+
self.key_config.clone(),
256+
),
246257
!self.is_empty(),
247258
self.focused() || force_all,
248259
)

src/components/command.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
///
2-
#[derive(Copy, Clone, PartialEq, PartialOrd, Ord, Eq)]
2+
#[derive(Clone, PartialEq, PartialOrd, Ord, Eq)]
33
pub struct CommandText {
44
///
5-
pub name: &'static str,
5+
pub name: String,
66
///
77
pub desc: &'static str,
88
///
@@ -14,7 +14,7 @@ pub struct CommandText {
1414
impl CommandText {
1515
///
1616
pub const fn new(
17-
name: &'static str,
17+
name: String,
1818
desc: &'static str,
1919
group: &'static str,
2020
) -> Self {
@@ -77,7 +77,7 @@ impl CommandInfo {
7777
}
7878
///
7979
pub fn print(&self, out: &mut String) {
80-
out.push_str(self.text.name);
80+
out.push_str(&self.text.name);
8181
}
8282
///
8383
pub fn show_in_quickbar(&self) -> bool {

src/components/commit.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
get_app_config_path,
88
keys::SharedKeyConfig,
99
queue::{InternalEvent, NeedsUpdate, Queue},
10-
strings::{self, commands},
10+
strings,
1111
ui::style::SharedTheme,
1212
};
1313
use anyhow::Result;
@@ -52,19 +52,25 @@ impl Component for CommitComponent {
5252

5353
if self.is_visible() || force_all {
5454
out.push(CommandInfo::new(
55-
commands::COMMIT_ENTER,
55+
strings::commands::commit_enter(
56+
self.key_config.clone(),
57+
),
5658
self.can_commit(),
5759
true,
5860
));
5961

6062
out.push(CommandInfo::new(
61-
commands::COMMIT_AMEND,
63+
strings::commands::commit_amend(
64+
self.key_config.clone(),
65+
),
6266
self.can_amend(),
6367
true,
6468
));
6569

6670
out.push(CommandInfo::new(
67-
commands::COMMIT_OPEN_EDITOR,
71+
strings::commands::commit_open_editor(
72+
self.key_config.clone(),
73+
),
6874
true,
6975
true,
7076
));
@@ -113,7 +119,9 @@ impl Component for CommitComponent {
113119
self.amend = None;
114120

115121
self.input.clear();
116-
self.input.set_title(strings::COMMIT_TITLE.into());
122+
self.input.set_title(strings::commit_title(
123+
self.key_config.clone(),
124+
));
117125
self.input.show()?;
118126

119127
Ok(())
@@ -132,8 +140,9 @@ impl CommitComponent {
132140
amend: None,
133141
input: TextInputComponent::new(
134142
theme,
143+
key_config.clone(),
135144
"",
136-
strings::COMMIT_MSG,
145+
&strings::commit_msg(key_config.clone()),
137146
),
138147
key_config,
139148
}
@@ -151,7 +160,10 @@ impl CommitComponent {
151160
"{}\n",
152161
self.input.get_text()
153162
))?;
154-
file.write_all(strings::COMMIT_EDITOR_MSG.as_bytes())?;
163+
file.write_all(
164+
strings::commit_editor_msg(self.key_config.clone())
165+
.as_bytes(),
166+
)?;
155167
}
156168

157169
ExternalEditorComponent::open_file_in_editor(&config_path)?;
@@ -252,7 +264,9 @@ impl CommitComponent {
252264

253265
let details = sync::get_commit_details(CWD, id)?;
254266

255-
self.input.set_title(strings::COMMIT_TITLE_AMEND.into());
267+
self.input.set_title(strings::commit_title_amend(
268+
self.key_config.clone(),
269+
));
256270

257271
if let Some(msg) = details.message {
258272
self.input.set_text(msg.combine());

0 commit comments

Comments
 (0)