|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
use crate::app::InputMode;
|
|
|
|
|
use crate::app::{App, FocusBlock};
|
|
|
|
|
use tui::{
|
|
|
|
|
backend::Backend,
|
|
|
|
@ -11,7 +10,7 @@ use tui::{
|
|
|
|
|
use unicode_width::UnicodeWidthStr;
|
|
|
|
|
|
|
|
|
|
pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<()> {
|
|
|
|
|
if let FocusBlock::ConnectionList = app.focus_type {
|
|
|
|
|
if let FocusBlock::ConnectionList = app.focus_block {
|
|
|
|
|
let percent_x = 60;
|
|
|
|
|
let percent_y = 50;
|
|
|
|
|
let conns = &app.user_config.as_ref().unwrap().conn;
|
|
|
|
@ -25,7 +24,7 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
|
|
|
|
|
let tasks = List::new(connections)
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title("Connections"))
|
|
|
|
|
.highlight_style(Style::default().fg(Color::Green))
|
|
|
|
|
.style(match app.focus_type {
|
|
|
|
|
.style(match app.focus_block {
|
|
|
|
|
FocusBlock::ConnectionList => Style::default().fg(Color::Green),
|
|
|
|
|
_ => Style::default(),
|
|
|
|
|
});
|
|
|
|
@ -84,7 +83,7 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
|
|
|
|
|
let tasks = List::new(databases)
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title("Databases"))
|
|
|
|
|
.highlight_style(Style::default().fg(Color::Green))
|
|
|
|
|
.style(match app.focus_type {
|
|
|
|
|
.style(match app.focus_block {
|
|
|
|
|
FocusBlock::DabataseList(false) => Style::default().fg(Color::Magenta),
|
|
|
|
|
FocusBlock::DabataseList(true) => Style::default().fg(Color::Green),
|
|
|
|
|
_ => Style::default(),
|
|
|
|
@ -103,31 +102,22 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
|
|
|
|
|
let tasks = List::new(tables)
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title("Tables"))
|
|
|
|
|
.highlight_style(Style::default().fg(Color::Green))
|
|
|
|
|
.style(match app.focus_type {
|
|
|
|
|
.style(match app.focus_block {
|
|
|
|
|
FocusBlock::TableList(false) => Style::default().fg(Color::Magenta),
|
|
|
|
|
FocusBlock::TableList(true) => Style::default().fg(Color::Green),
|
|
|
|
|
_ => Style::default(),
|
|
|
|
|
});
|
|
|
|
|
f.render_stateful_widget(tasks, left_chunks[1], &mut app.selected_table);
|
|
|
|
|
|
|
|
|
|
let info: Vec<ListItem> = vec![
|
|
|
|
|
format!(
|
|
|
|
|
"created: {}",
|
|
|
|
|
app.selected_table().unwrap().create_time.to_string()
|
|
|
|
|
),
|
|
|
|
|
// format!(
|
|
|
|
|
// "updated: {}",
|
|
|
|
|
// app.selected_table().unwrap().update_time.to_string()
|
|
|
|
|
// ),
|
|
|
|
|
format!("rows: {}", app.record_table.rows.len()),
|
|
|
|
|
]
|
|
|
|
|
let table_status: Vec<ListItem> = app
|
|
|
|
|
.table_status()
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|i| {
|
|
|
|
|
ListItem::new(vec![Spans::from(Span::raw(i.to_string()))])
|
|
|
|
|
.style(Style::default().fg(Color::White))
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
let tasks = List::new(info)
|
|
|
|
|
let tasks = List::new(table_status)
|
|
|
|
|
.block(Block::default().borders(Borders::ALL))
|
|
|
|
|
.highlight_style(Style::default().fg(Color::Green));
|
|
|
|
|
f.render_widget(tasks, left_chunks[2]);
|
|
|
|
@ -138,18 +128,18 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
|
|
|
|
|
.split(main_chunks[1]);
|
|
|
|
|
|
|
|
|
|
let query = Paragraph::new(app.input.as_ref())
|
|
|
|
|
.style(match app.input_mode {
|
|
|
|
|
InputMode::Normal => Style::default(),
|
|
|
|
|
InputMode::Editing => Style::default().fg(Color::Yellow),
|
|
|
|
|
.style(match app.focus_block {
|
|
|
|
|
FocusBlock::Query(true) => Style::default().fg(Color::Green),
|
|
|
|
|
FocusBlock::Query(false) => Style::default().fg(Color::Magenta),
|
|
|
|
|
_ => Style::default(),
|
|
|
|
|
})
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title("Query"));
|
|
|
|
|
f.render_widget(query, right_chunks[0]);
|
|
|
|
|
match app.input_mode {
|
|
|
|
|
InputMode::Normal => (),
|
|
|
|
|
InputMode::Editing => f.set_cursor(
|
|
|
|
|
right_chunks[0].x + app.input.width() as u16 + 1,
|
|
|
|
|
if let FocusBlock::Query(true) = app.focus_block {
|
|
|
|
|
f.set_cursor(
|
|
|
|
|
right_chunks[0].x + app.input.width() as u16 + 1 - app.input_cursor_x,
|
|
|
|
|
right_chunks[0].y + 1,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let header_cells = app.record_table.headers[app.record_table.column_index..]
|
|
|
|
@ -175,7 +165,7 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
|
|
|
|
|
.header(header)
|
|
|
|
|
.block(Block::default().borders(Borders::ALL).title("Records"))
|
|
|
|
|
.highlight_style(Style::default().fg(Color::Green))
|
|
|
|
|
.style(match app.focus_type {
|
|
|
|
|
.style(match app.focus_block {
|
|
|
|
|
FocusBlock::RecordTable(false) => Style::default().fg(Color::Magenta),
|
|
|
|
|
FocusBlock::RecordTable(true) => Style::default().fg(Color::Green),
|
|
|
|
|
_ => Style::default(),
|
|
|
|
@ -183,5 +173,42 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
|
|
|
|
|
.widths(&widths);
|
|
|
|
|
f.render_stateful_widget(t, right_chunks[1], &mut app.record_table.state);
|
|
|
|
|
|
|
|
|
|
if let Some(err) = app.error.clone() {
|
|
|
|
|
draw_error_popup(f, err)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_error_popup<B: Backend>(f: &mut Frame<'_, B>, error: String) -> anyhow::Result<()> {
|
|
|
|
|
let percent_x = 60;
|
|
|
|
|
let percent_y = 20;
|
|
|
|
|
let error = Paragraph::new(error)
|
|
|
|
|
.block(Block::default().title("Error").borders(Borders::ALL))
|
|
|
|
|
.style(Style::default().fg(Color::Red));
|
|
|
|
|
let popup_layout = Layout::default()
|
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
|
.constraints(
|
|
|
|
|
[
|
|
|
|
|
Constraint::Percentage((100 - percent_y) / 2),
|
|
|
|
|
Constraint::Percentage(percent_y),
|
|
|
|
|
Constraint::Percentage((100 - percent_y) / 2),
|
|
|
|
|
]
|
|
|
|
|
.as_ref(),
|
|
|
|
|
)
|
|
|
|
|
.split(f.size());
|
|
|
|
|
|
|
|
|
|
let area = Layout::default()
|
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
|
.constraints(
|
|
|
|
|
[
|
|
|
|
|
Constraint::Percentage((100 - percent_x) / 2),
|
|
|
|
|
Constraint::Percentage(percent_x),
|
|
|
|
|
Constraint::Percentage((100 - percent_x) / 2),
|
|
|
|
|
]
|
|
|
|
|
.as_ref(),
|
|
|
|
|
)
|
|
|
|
|
.split(popup_layout[1])[1];
|
|
|
|
|
f.render_widget(Clear, area);
|
|
|
|
|
f.render_widget(error, area);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|