-
-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show placeholder popup when waiting for external editor #157
- Loading branch information
Stephan Dilly
committed
Jul 4, 2020
1 parent
7016f17
commit de7f48f
Showing
6 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use crate::{ | ||
components::{ | ||
visibility_blocking, CommandBlocking, CommandInfo, Component, | ||
DrawableComponent, | ||
}, | ||
strings, | ||
ui::{self, style::SharedTheme}, | ||
}; | ||
use anyhow::Result; | ||
use crossterm::event::Event; | ||
use tui::{ | ||
backend::Backend, | ||
layout::Rect, | ||
widgets::{Block, BorderType, Borders, Clear, Paragraph, Text}, | ||
Frame, | ||
}; | ||
|
||
/// | ||
pub struct ExternalEditorComponent { | ||
visible: bool, | ||
theme: SharedTheme, | ||
} | ||
|
||
impl ExternalEditorComponent { | ||
/// | ||
pub fn new(theme: SharedTheme) -> Self { | ||
Self { | ||
visible: false, | ||
theme, | ||
} | ||
} | ||
} | ||
|
||
impl DrawableComponent for ExternalEditorComponent { | ||
fn draw<B: Backend>( | ||
&self, | ||
f: &mut Frame<B>, | ||
_rect: Rect, | ||
) -> Result<()> { | ||
if self.visible { | ||
let txt = | ||
vec![Text::Raw(strings::MSG_OPENING_EDITOR.into())]; | ||
|
||
let area = ui::centered_rect_absolute(25, 3, f.size()); | ||
f.render_widget(Clear, area); | ||
f.render_widget( | ||
Paragraph::new(txt.iter()) | ||
.block( | ||
Block::default() | ||
.borders(Borders::ALL) | ||
.border_type(BorderType::Thick) | ||
.title_style(self.theme.title(true)) | ||
.border_style(self.theme.block(true)), | ||
) | ||
.style(self.theme.text_danger()), | ||
area, | ||
); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Component for ExternalEditorComponent { | ||
fn commands( | ||
&self, | ||
out: &mut Vec<CommandInfo>, | ||
_force_all: bool, | ||
) -> CommandBlocking { | ||
if self.visible { | ||
out.clear(); | ||
} | ||
|
||
visibility_blocking(self) | ||
} | ||
|
||
fn event(&mut self, _ev: Event) -> Result<bool> { | ||
if self.visible { | ||
return Ok(true); | ||
} | ||
|
||
Ok(false) | ||
} | ||
|
||
fn is_visible(&self) -> bool { | ||
self.visible | ||
} | ||
|
||
fn hide(&mut self) { | ||
self.visible = false | ||
} | ||
|
||
fn show(&mut self) -> Result<()> { | ||
self.visible = true; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters