diff options
author | Joris | 2022-02-12 16:57:19 +0100 |
---|---|---|
committer | Joris | 2022-02-12 16:57:19 +0100 |
commit | 3adf3f9697c4e2beb10e652947046d5fddda2ed4 (patch) | |
tree | 689e704cf4665cc4cd1949c06d4a7b0553d07501 /src/gui/message.rs | |
parent | a2ba205df12332a360d89991fe508f964d88c73f (diff) |
Say when the next card will be available
Diffstat (limited to 'src/gui/message.rs')
-rw-r--r-- | src/gui/message.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/gui/message.rs b/src/gui/message.rs new file mode 100644 index 0000000..158416e --- /dev/null +++ b/src/gui/message.rs @@ -0,0 +1,41 @@ +use crate::gui::util; +use crate::util::event::{Event, Events}; +use anyhow::Result; +use termion::event::Key; +use tui::{ + backend::Backend, + layout::{Alignment, Constraint, Direction, Layout}, + widgets::Paragraph, + Terminal, +}; + +pub fn show<B: Backend>( + terminal: &mut Terminal<B>, + events: &Events, + message: &String, + deck_name: &String, +) -> Result<()> { + loop { + terminal.draw(|f| { + let chunks = Layout::default() + .direction(Direction::Vertical) + .margin(2) + .constraints([Constraint::Length(1), Constraint::Percentage(50)].as_ref()) + .split(f.size()); + + let d1 = util::title(deck_name); + f.render_widget(d1, chunks[0]); + + let message = Paragraph::new(util::center_vertically(chunks[1], &message)) + .alignment(Alignment::Center); + f.render_widget(message, chunks[1]); + })?; + + if let Event::Input(key) = events.next()? { + match key { + Key::Char('q') => return Ok(()), + _ => (), + } + } + } +} |