Skip to content

Commit

Permalink
json editor part 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Apr 26, 2024
1 parent 6f1e684 commit 9414d08
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9414d08

Please sign in to comment.