Skip to content

Commit de7f48f

Browse files
author
Stephan Dilly
committed
show placeholder popup when waiting for external editor #157
1 parent 7016f17 commit de7f48f

File tree

6 files changed

+118
-3
lines changed

6 files changed

+118
-3
lines changed

src/app.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::{
33
cmdbar::CommandBar,
44
components::{
55
event_pump, CommandBlocking, CommandInfo, CommitComponent,
6-
Component, DrawableComponent, HelpComponent,
7-
InspectCommitComponent, MsgComponent, ResetComponent,
8-
StashMsgComponent,
6+
Component, DrawableComponent, ExternalEditorComponent,
7+
HelpComponent, InspectCommitComponent, MsgComponent,
8+
ResetComponent, StashMsgComponent,
99
},
1010
input::{Input, InputEvent, InputState},
1111
keys,
@@ -35,6 +35,7 @@ pub struct App {
3535
commit: CommitComponent,
3636
stashmsg_popup: StashMsgComponent,
3737
inspect_commit_popup: InspectCommitComponent,
38+
external_editor_popup: ExternalEditorComponent,
3839
cmdbar: RefCell<CommandBar>,
3940
tab: usize,
4041
revlog: Revlog,
@@ -76,6 +77,9 @@ impl App {
7677
sender,
7778
theme.clone(),
7879
),
80+
external_editor_popup: ExternalEditorComponent::new(
81+
theme.clone(),
82+
),
7983
do_quit: false,
8084
cmdbar: RefCell::new(CommandBar::new(theme.clone())),
8185
help: HelpComponent::new(theme.clone()),
@@ -190,6 +194,7 @@ impl App {
190194
self.update_commands();
191195
}
192196
} else if let InputEvent::State(polling_state) = ev {
197+
self.external_editor_popup.hide();
193198
if let InputState::Paused = polling_state {
194199
if let Err(e) = self.commit.show_editor() {
195200
let msg =
@@ -274,6 +279,7 @@ impl App {
274279
commit,
275280
stashmsg_popup,
276281
inspect_commit_popup,
282+
external_editor_popup,
277283
help,
278284
revlog,
279285
status_tab,
@@ -404,6 +410,8 @@ impl App {
404410
}
405411
InternalEvent::SuspendPolling => {
406412
self.input.set_polling(false);
413+
self.external_editor_popup.show()?;
414+
flags.insert(NeedsUpdate::COMMANDS)
407415
}
408416
};
409417

@@ -458,6 +466,7 @@ impl App {
458466
|| self.msg.is_visible()
459467
|| self.stashmsg_popup.is_visible()
460468
|| self.inspect_commit_popup.is_visible()
469+
|| self.external_editor_popup.is_visible()
461470
}
462471

463472
fn draw_popups<B: Backend>(
@@ -481,6 +490,7 @@ impl App {
481490
self.help.draw(f, size)?;
482491
self.msg.draw(f, size)?;
483492
self.inspect_commit_popup.draw(f, size)?;
493+
self.external_editor_popup.draw(f, size)?;
484494

485495
Ok(())
486496
}

src/components/commit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl Component for CommitComponent {
9797
self.queue
9898
.borrow_mut()
9999
.push_back(InternalEvent::SuspendPolling);
100+
self.hide();
100101
}
101102

102103
_ => (),
@@ -204,6 +205,7 @@ impl CommitComponent {
204205
let message = message.trim().to_string();
205206

206207
self.input.set_text(message);
208+
self.input.show()?;
207209

208210
Ok(())
209211
}

src/components/externaleditor.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
use crate::{
2+
components::{
3+
visibility_blocking, CommandBlocking, CommandInfo, Component,
4+
DrawableComponent,
5+
},
6+
strings,
7+
ui::{self, style::SharedTheme},
8+
};
9+
use anyhow::Result;
10+
use crossterm::event::Event;
11+
use tui::{
12+
backend::Backend,
13+
layout::Rect,
14+
widgets::{Block, BorderType, Borders, Clear, Paragraph, Text},
15+
Frame,
16+
};
17+
18+
///
19+
pub struct ExternalEditorComponent {
20+
visible: bool,
21+
theme: SharedTheme,
22+
}
23+
24+
impl ExternalEditorComponent {
25+
///
26+
pub fn new(theme: SharedTheme) -> Self {
27+
Self {
28+
visible: false,
29+
theme,
30+
}
31+
}
32+
}
33+
34+
impl DrawableComponent for ExternalEditorComponent {
35+
fn draw<B: Backend>(
36+
&self,
37+
f: &mut Frame<B>,
38+
_rect: Rect,
39+
) -> Result<()> {
40+
if self.visible {
41+
let txt =
42+
vec![Text::Raw(strings::MSG_OPENING_EDITOR.into())];
43+
44+
let area = ui::centered_rect_absolute(25, 3, f.size());
45+
f.render_widget(Clear, area);
46+
f.render_widget(
47+
Paragraph::new(txt.iter())
48+
.block(
49+
Block::default()
50+
.borders(Borders::ALL)
51+
.border_type(BorderType::Thick)
52+
.title_style(self.theme.title(true))
53+
.border_style(self.theme.block(true)),
54+
)
55+
.style(self.theme.text_danger()),
56+
area,
57+
);
58+
}
59+
60+
Ok(())
61+
}
62+
}
63+
64+
impl Component for ExternalEditorComponent {
65+
fn commands(
66+
&self,
67+
out: &mut Vec<CommandInfo>,
68+
_force_all: bool,
69+
) -> CommandBlocking {
70+
if self.visible {
71+
out.clear();
72+
}
73+
74+
visibility_blocking(self)
75+
}
76+
77+
fn event(&mut self, _ev: Event) -> Result<bool> {
78+
if self.visible {
79+
return Ok(true);
80+
}
81+
82+
Ok(false)
83+
}
84+
85+
fn is_visible(&self) -> bool {
86+
self.visible
87+
}
88+
89+
fn hide(&mut self) {
90+
self.visible = false
91+
}
92+
93+
fn show(&mut self) -> Result<()> {
94+
self.visible = true;
95+
96+
Ok(())
97+
}
98+
}

src/components/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod commit;
44
mod commit_details;
55
mod commitlist;
66
mod diff;
7+
mod externaleditor;
78
mod filetree;
89
mod help;
910
mod inspect_commit;
@@ -22,6 +23,7 @@ pub use commit::CommitComponent;
2223
pub use commit_details::CommitDetailsComponent;
2324
pub use commitlist::CommitList;
2425
pub use diff::DiffComponent;
26+
pub use externaleditor::ExternalEditorComponent;
2527
pub use filetree::FileTreeComponent;
2628
pub use help::HelpComponent;
2729
pub use inspect_commit::InspectCommitComponent;

src/queue.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub enum InternalEvent {
4949
///
5050
InspectCommit(CommitId),
5151
///
52+
//TODO: make this a generic OpenExternalEditor to also use it for other places
53+
//(see https://github.com/extrawurst/gitui/issues/166)
5254
SuspendPolling,
5355
}
5456

src/strings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub static TAB_DIVIDER: &str = " | ";
1010

1111
pub static CMD_SPLITTER: &str = " ";
1212

13+
pub static MSG_OPENING_EDITOR: &str = "opening editor...";
1314
pub static MSG_TITLE_ERROR: &str = "Error";
1415
pub static COMMIT_TITLE: &str = "Commit";
1516
pub static COMMIT_TITLE_AMEND: &str = "Commit (Amend)";

0 commit comments

Comments
 (0)