-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/tui: show regex error as a popup
- Loading branch information
Showing
6 changed files
with
86 additions
and
10 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
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,46 @@ | ||
use crossterm::event::KeyEvent; | ||
use ratatui::{ | ||
buffer::Buffer, | ||
layout::Rect, | ||
style::Stylize, | ||
text::Line, | ||
widgets::{Paragraph, StatefulWidget, WidgetRef, Wrap}, | ||
}; | ||
use tui_popup::Popup; | ||
|
||
use crate::action::Action; | ||
|
||
use super::{sized_paragraph::SizedParagraph, theme::THEME}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ErrorPopupState { | ||
pub title: String, | ||
pub message: Vec<Line<'static>>, | ||
} | ||
|
||
impl ErrorPopupState { | ||
pub fn handle_key_event(&mut self, _key: KeyEvent) -> Option<Action> { | ||
Some(Action::CancelCurrentPopup) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ErrorPopup; | ||
|
||
impl StatefulWidget for ErrorPopup { | ||
type State = ErrorPopupState; | ||
|
||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { | ||
let help = Line::raw("Press any key to close this popup"); | ||
let mut message = state.message.clone(); | ||
message.push("".into()); | ||
message.push(help.centered().bold()); | ||
let paragraph = Paragraph::new(message).wrap(Wrap { trim: false }); | ||
let popup = Popup::new( | ||
Line::raw(state.title.as_str()).centered(), | ||
SizedParagraph::new(paragraph, (area.width as f32 * 0.7) as usize), | ||
) | ||
.style(THEME.error_popup); | ||
popup.render_ref(area, buf); | ||
} | ||
} |
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