diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..fd03203 --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +- [ ] make sure that sensitive information (e.g. passwords) for configured databases are encrypted in such a way that credentials can't be snatched by malicious programs \ No newline at end of file diff --git a/src/connection.rs b/src/connection.rs index 6f5f4b7..cc5fd05 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -7,7 +7,7 @@ use ratatui::{ layout::{Constraint, Layout, Rect}, style::{Color, Style}, text::Line, - widgets::{Block, List, ListItem, Paragraph, Wrap}, + widgets::{Block, Clear, List, ListItem, Paragraph, Wrap}, }; use crate::{Result, app::App, db::Database, error_text}; @@ -18,10 +18,11 @@ pub fn run(terminal: &mut DefaultTerminal, initial: Option) -> Result< let mut show_form = browser.is_none(); loop { terminal.draw(|frame| { + if let Some(browser) = &mut browser { + browser.draw(frame); + } if show_form { form.draw(frame, false); - } else if let Some(browser) = &mut browser { - browser.draw(frame); } })?; match event::read()? { @@ -40,7 +41,12 @@ pub fn run(terminal: &mut DefaultTerminal, initial: Option) -> Result< } KeyCode::Enter if form.focus == 0 => form.focus = 1, KeyCode::Enter => { - terminal.draw(|frame| form.draw(frame, true))?; + terminal.draw(|frame| { + if let Some(browser) = &mut browser { + browser.draw(frame); + } + form.draw(frame, true); + })?; match form.connect().and_then(App::new) { Ok(connected) => { form.clear_password(); @@ -165,24 +171,35 @@ impl Form { } fn draw(&self, frame: &mut Frame, connecting: bool) { - let area = frame.area(); - let minimum_height = if self.provider == 0 { 16 } else { 12 }; - if area.width < 70 || area.height < minimum_height { + let screen = frame.area(); + let minimum_height = if self.provider == 0 { 20 } else { 16 }; + if screen.width < 74 || screen.height < minimum_height { + frame.render_widget(Clear, screen); frame.render_widget( Paragraph::new(format!( - "Enlarge terminal to at least 70×{minimum_height}. Ctrl-C to quit." + "Enlarge terminal to at least 74×{minimum_height}. Ctrl-C to quit." )), - area, + screen, ); return; } + let area = Rect::new( + screen.x + (screen.width - screen.width.saturating_sub(4).min(100)) / 2, + screen.y + (screen.height - minimum_height) / 2, + screen.width.saturating_sub(4).min(100), + minimum_height, + ); + let window = Block::bordered().title(" New connection "); + let inner = window.inner(area); + frame.render_widget(Clear, area); + frame.render_widget(window, area); let [header, body, status, help] = Layout::vertical([ Constraint::Length(2), Constraint::Min(4), Constraint::Length(3), Constraint::Length(2), ]) - .areas(area); + .areas(inner); frame.render_widget( Paragraph::new(" dbdash │ New connection │ READ ONLY") .style(Style::default().fg(Color::Cyan)),