feat: open connection setup in a floating window

This commit is contained in:
Valdemar Lorenzen
2026-10-19 13:09:45 +02:00
parent 415e5c2718
commit d8d7c1f2fc
2 changed files with 28 additions and 10 deletions
+1
View File
@@ -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
+27 -10
View File
@@ -7,7 +7,7 @@ use ratatui::{
layout::{Constraint, Layout, Rect}, layout::{Constraint, Layout, Rect},
style::{Color, Style}, style::{Color, Style},
text::Line, text::Line,
widgets::{Block, List, ListItem, Paragraph, Wrap}, widgets::{Block, Clear, List, ListItem, Paragraph, Wrap},
}; };
use crate::{Result, app::App, db::Database, error_text}; use crate::{Result, app::App, db::Database, error_text};
@@ -18,10 +18,11 @@ pub fn run(terminal: &mut DefaultTerminal, initial: Option<Database>) -> Result<
let mut show_form = browser.is_none(); let mut show_form = browser.is_none();
loop { loop {
terminal.draw(|frame| { terminal.draw(|frame| {
if let Some(browser) = &mut browser {
browser.draw(frame);
}
if show_form { if show_form {
form.draw(frame, false); form.draw(frame, false);
} else if let Some(browser) = &mut browser {
browser.draw(frame);
} }
})?; })?;
match event::read()? { match event::read()? {
@@ -40,7 +41,12 @@ pub fn run(terminal: &mut DefaultTerminal, initial: Option<Database>) -> Result<
} }
KeyCode::Enter if form.focus == 0 => form.focus = 1, KeyCode::Enter if form.focus == 0 => form.focus = 1,
KeyCode::Enter => { 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) { match form.connect().and_then(App::new) {
Ok(connected) => { Ok(connected) => {
form.clear_password(); form.clear_password();
@@ -165,24 +171,35 @@ impl Form {
} }
fn draw(&self, frame: &mut Frame, connecting: bool) { fn draw(&self, frame: &mut Frame, connecting: bool) {
let area = frame.area(); let screen = frame.area();
let minimum_height = if self.provider == 0 { 16 } else { 12 }; let minimum_height = if self.provider == 0 { 20 } else { 16 };
if area.width < 70 || area.height < minimum_height { if screen.width < 74 || screen.height < minimum_height {
frame.render_widget(Clear, screen);
frame.render_widget( frame.render_widget(
Paragraph::new(format!( 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; 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([ let [header, body, status, help] = Layout::vertical([
Constraint::Length(2), Constraint::Length(2),
Constraint::Min(4), Constraint::Min(4),
Constraint::Length(3), Constraint::Length(3),
Constraint::Length(2), Constraint::Length(2),
]) ])
.areas(area); .areas(inner);
frame.render_widget( frame.render_widget(
Paragraph::new(" dbdash │ New connection │ READ ONLY") Paragraph::new(" dbdash │ New connection │ READ ONLY")
.style(Style::default().fg(Color::Cyan)), .style(Style::default().fg(Color::Cyan)),