feat: persist configured databases and connect from sidebar
This commit is contained in:
+9
-18
@@ -1,7 +1,7 @@
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::{Constraint, Layout},
|
||||
layout::{Constraint, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
text::Line,
|
||||
widgets::{Block, Cell, List, ListItem, ListState, Paragraph, Row, Table, TableState},
|
||||
@@ -24,7 +24,7 @@ pub struct App {
|
||||
rows_state: TableState,
|
||||
schema_state: TableState,
|
||||
column_offset: usize,
|
||||
sidebar_focus: bool,
|
||||
pub(crate) sidebar_focus: bool,
|
||||
show_schema: bool,
|
||||
error: Option<String>,
|
||||
}
|
||||
@@ -55,19 +55,12 @@ impl App {
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_key(&mut self, key: KeyEvent) -> bool {
|
||||
if key.code == KeyCode::Char('q')
|
||||
|| (key.code == KeyCode::Char('c') && key.modifiers.contains(KeyModifiers::CONTROL))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
pub(crate) fn handle_key(&mut self, key: KeyEvent) {
|
||||
match key.code {
|
||||
KeyCode::Tab | KeyCode::BackTab => self.sidebar_focus = !self.sidebar_focus,
|
||||
KeyCode::Enter if self.sidebar_focus => {
|
||||
self.open_selection();
|
||||
self.sidebar_focus = false;
|
||||
}
|
||||
KeyCode::Esc => self.sidebar_focus = true,
|
||||
KeyCode::Down | KeyCode::Char('j') => self.move_selection(1),
|
||||
KeyCode::Up | KeyCode::Char('k') => self.move_selection(-1),
|
||||
KeyCode::Home | KeyCode::Char('g') => self.move_selection(isize::MIN),
|
||||
@@ -98,7 +91,6 @@ impl App {
|
||||
KeyCode::Char('r') => self.refresh(),
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn move_selection(&mut self, delta: isize) {
|
||||
@@ -171,9 +163,8 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw(&mut self, frame: &mut Frame) {
|
||||
let area = frame.area();
|
||||
if area.width < 70 || area.height < 12 {
|
||||
pub(crate) fn draw(&mut self, frame: &mut Frame, area: Rect, focused: bool) {
|
||||
if area.width < 46 || area.height < 12 {
|
||||
frame.render_widget(
|
||||
Paragraph::new("Enlarge terminal to at least 70×12. q to quit."),
|
||||
area,
|
||||
@@ -199,7 +190,7 @@ impl App {
|
||||
let [sidebar, content] =
|
||||
Layout::horizontal([Constraint::Length(28), Constraint::Min(1)]).areas(body);
|
||||
let sidebar_title = format!(" Relations ({}) ", self.relations.len());
|
||||
let sidebar_block = panel(&sidebar_title, self.sidebar_focus);
|
||||
let sidebar_block = panel(&sidebar_title, focused && self.sidebar_focus);
|
||||
if self.relations.is_empty() {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No readable tables or views.\nr to refresh.").block(sidebar_block),
|
||||
@@ -221,7 +212,7 @@ impl App {
|
||||
} else {
|
||||
" Rows · s for schema "
|
||||
};
|
||||
let content_block = panel(title, !self.sidebar_focus);
|
||||
let content_block = panel(title, focused && !self.sidebar_focus);
|
||||
let count = if self.show_schema {
|
||||
5
|
||||
} else {
|
||||
@@ -348,7 +339,7 @@ impl App {
|
||||
);
|
||||
}
|
||||
frame.render_widget(Paragraph::new(
|
||||
" Tab focus · ↑↓/jk move · Enter open · s schema/rows\n ←→/hl columns · n/p page · r refresh · c connect · q quit"
|
||||
" Tab focus · Esc databases · ↑↓/jk move · Enter open · s schema/rows\n ←→/hl columns · n/p page · r refresh · c add database · q quit"
|
||||
).style(Style::default().fg(Color::DarkGray)), help);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user