diff --git a/src/ui.rs b/src/ui.rs index de63737..c8bd9bb 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,7 +1,7 @@ use color_eyre::owo_colors::OwoColorize; use ratatui::{ layout::{Constraint, Direction, Layout, Rect}, - style::{Color, Style}, + style::{Color, Style, Stylize}, text::{Line, Span, Text}, widgets::{Block, Borders, Clear, List, ListItem, Paragraph, Wrap}, Frame, @@ -100,6 +100,58 @@ pub fn ui(f: &mut Frame, app: &App) { f.render_widget(mode_footer, footer_chunks[0]); f.render_widget(key_notes_footer, footer_chunks[1]); + + if let Some(editing) = &app.currently_editing { + let popup_block = Block::default() + .title("Enter a new key-value pair") + .borders(Borders::NONE) + .style(Style::default().bg(Color::DarkGray)); + + let area = centered_rect(60, 25, f.size()); + f.render_widget(popup_block, area); + + let popup_chunks = Layout::default() + .direction(Direction::Horizontal) + .margin(1) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) + .split(area); + + let mut key_block = Block::default().title("Key").borders(Borders::ALL); + let mut value_block = Block::default().title("Value").borders(Borders::ALL); + + let active_style = Style::default().bg(Color::LightYellow).fg(Color::Black); + + match editing { + CurrentlyEditing::Key => key_block = key_block.style(active_style), + CurrentlyEditing::Value => value_block = value_block.style(active_style), + }; + + let key_text = Paragraph::new(app.key_input.clone()).block(key_block); + f.render_widget(key_text, popup_chunks[0]); + + let value_text = Paragraph::new(app.value_input.clone()).block(value_block); + f.render_widget(value_text, popup_chunks[1]); + } + + if let CurrentScreen::Exiting = app.current_screen { + f.render_widget(Clear, f.size()); + let popup_block = Block::default() + .title("Y/N") + .borders(Borders::NONE) + .style(Style::default().bg(Color::DarkGray)); + + let exit_text = Text::styled( + "Would you like to output the buffer as json? (y/n)", + Style::default().fg(Color::Red), + ); + + let exit_paragraph = Paragraph::new(exit_text) + .block(popup_block) + .wrap(Wrap { trim: false }); + + let area = centered_rect(60, 25, f.size()); + f.render_widget(exit_paragraph, area); + } } fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {