Skip to content

Commit

Permalink
Merge pull request #112 from matthewmturner/feat/more-cleanup
Browse files Browse the repository at this point in the history
More UI improvements
  • Loading branch information
matthewmturner authored Aug 30, 2024
2 parents 846e401 + 3df8de5 commit 570c098
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 62 deletions.
12 changes: 6 additions & 6 deletions src/app/handlers/flightsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::time::{Duration, Instant};

use datafusion::arrow::array::RecordBatch;
use log::{error, info};
use ratatui::crossterm::event::{KeyCode, KeyEvent};
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use tokio_stream::StreamExt;
use tonic::IntoRequest;

Expand All @@ -32,11 +32,11 @@ use super::App;
pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {
match key.code {
KeyCode::Char('q') => app.state.should_quit = true,
tab @ (KeyCode::Char('s')
| KeyCode::Char('h')
| KeyCode::Char('l')
| KeyCode::Char('x')
| KeyCode::Char('f')) => tab_navigation_handler(app, tab),
tab @ (KeyCode::Char('1')
| KeyCode::Char('2')
| KeyCode::Char('3')
| KeyCode::Char('4')
| KeyCode::Char('5')) => tab_navigation_handler(app, tab),
KeyCode::Char('c') => app.state.flightsql_tab.clear_editor(),
KeyCode::Char('e') => {
info!("Handling");
Expand Down
10 changes: 5 additions & 5 deletions src/app/handlers/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub fn app_event_handler(app: &mut App, event: AppEvent) {
match event {
AppEvent::Key(key) => match key.code {
KeyCode::Char('q') => app.state.should_quit = true,
tab @ (KeyCode::Char('s')
| KeyCode::Char('h')
| KeyCode::Char('l')
| KeyCode::Char('x')
| KeyCode::Char('f')) => tab_navigation_handler(app, tab),
tab @ (KeyCode::Char('1')
| KeyCode::Char('2')
| KeyCode::Char('3')
| KeyCode::Char('4')
| KeyCode::Char('5')) => tab_navigation_handler(app, tab),

KeyCode::Down => {
if let Some(s) = app.state.history_tab.history_table_state() {
Expand Down
49 changes: 30 additions & 19 deletions src/app/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,39 @@ pub fn crossterm_event_handler(event: event::Event) -> Option<AppEvent> {
}

fn tab_navigation_handler(app: &mut App, key: KeyCode) {
#[cfg(feature = "flightsql")]
match key {
KeyCode::Char('s') => app.state.tabs.selected = SelectedTab::SQL,
KeyCode::Char('l') => app.state.tabs.selected = SelectedTab::Logs,
KeyCode::Char('x') => app.state.tabs.selected = SelectedTab::Context,
KeyCode::Char('h') => app.state.tabs.selected = SelectedTab::History,
#[cfg(feature = "flightsql")]
KeyCode::Char('f') => app.state.tabs.selected = SelectedTab::FlightSQL,
KeyCode::Char('1') => app.state.tabs.selected = SelectedTab::SQL,
KeyCode::Char('2') => app.state.tabs.selected = SelectedTab::FlightSQL,
KeyCode::Char('3') => app.state.tabs.selected = SelectedTab::History,
KeyCode::Char('4') => app.state.tabs.selected = SelectedTab::Logs,
KeyCode::Char('5') => app.state.tabs.selected = SelectedTab::Context,
_ => {}
};
#[cfg(not(feature = "flightsql"))]
match key {
KeyCode::Char('1') => app.state.tabs.selected = SelectedTab::SQL,
KeyCode::Char('2') => app.state.tabs.selected = SelectedTab::History,
KeyCode::Char('3') => app.state.tabs.selected = SelectedTab::Logs,
KeyCode::Char('4') => app.state.tabs.selected = SelectedTab::Context,
_ => {}
};
}

fn logs_tab_key_event_handler(app: &mut App, key: KeyEvent) {
match key.code {
KeyCode::Char('q') => app.state.should_quit = true,
tab @ (KeyCode::Char('s')
| KeyCode::Char('h')
| KeyCode::Char('l')
| KeyCode::Char('x')
| KeyCode::Char('f')) => tab_navigation_handler(app, tab),
// KeyCode::Char('h') => {
// app.state.logs_tab.transition(TuiWidgetEvent::HideKey);
// }
tab @ (KeyCode::Char('1')
| KeyCode::Char('2')
| KeyCode::Char('3')
| KeyCode::Char('4')
| KeyCode::Char('5')) => tab_navigation_handler(app, tab),
KeyCode::Char('f') => {
app.state.logs_tab.transition(TuiWidgetEvent::FocusKey);
}
KeyCode::Char('h') => {
app.state.logs_tab.transition(TuiWidgetEvent::HideKey);
}
KeyCode::Char('+') => {
app.state.logs_tab.transition(TuiWidgetEvent::PlusKey);
}
Expand Down Expand Up @@ -113,11 +124,11 @@ fn logs_tab_key_event_handler(app: &mut App, key: KeyEvent) {
fn context_tab_key_event_handler(app: &mut App, key: KeyEvent) {
match key.code {
KeyCode::Char('q') => app.state.should_quit = true,
tab @ (KeyCode::Char('s')
| KeyCode::Char('l')
| KeyCode::Char('h')
| KeyCode::Char('x')
| KeyCode::Char('f')) => tab_navigation_handler(app, tab),
tab @ (KeyCode::Char('1')
| KeyCode::Char('2')
| KeyCode::Char('3')
| KeyCode::Char('4')
| KeyCode::Char('5')) => tab_navigation_handler(app, tab),
_ => {}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/handlers/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use super::App;
pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {
match key.code {
KeyCode::Char('q') => app.state.should_quit = true,
tab @ (KeyCode::Char('s')
| KeyCode::Char('h')
| KeyCode::Char('l')
| KeyCode::Char('x')
| KeyCode::Char('f')) => tab_navigation_handler(app, tab),
tab @ (KeyCode::Char('1')
| KeyCode::Char('2')
| KeyCode::Char('3')
| KeyCode::Char('4')
| KeyCode::Char('5')) => tab_navigation_handler(app, tab),
KeyCode::Char('c') => app.state.sql_tab.clear_editor(),
KeyCode::Char('e') => {
let editor = app.state.sql_tab.editor();
Expand Down
51 changes: 26 additions & 25 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,46 @@ impl SelectedTab {
let padding = Span::from(" ");
match self {
SelectedTab::SQL => {
let bold_char = Span::from("S").bold().black();
let remaining = Span::from("QL");
Line::from_iter(vec![padding.clone(), bold_char, remaining, padding.clone()])
let title = Span::from("SQL (1)").bold();
Line::from_iter(vec![padding.clone(), title, padding.clone()])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
}
#[cfg(feature = "flightsql")]
Self::FlightSQL => {
let bold_char = Span::from("F").bold().black();
let remaining = Span::from("lightSQL");
Line::from_iter(vec![padding.clone(), bold_char, remaining, padding.clone()])
let title = Span::from("FlightSQL (2)").bold();
Line::from_iter(vec![padding.clone(), title, padding.clone()])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
}
Self::Logs => {
let bold_char = Span::from("L").bold().black();
let remaining = Span::from("OGS");
Line::from_iter(vec![padding.clone(), bold_char, remaining, padding.clone()])
#[cfg(feature = "flightsql")]
let title = Span::from("LOGS (4)").bold();

#[cfg(not(feature = "flightsql"))]
let title = Span::from("LOGS (3)").bold();

Line::from_iter(vec![padding.clone(), title, padding.clone()])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
}
Self::Context => {
let start = Span::from("CONTE");
let bold_char = Span::from("X").bold().black();
let remaining = Span::from("T");
Line::from_iter(vec![
padding.clone(),
start,
bold_char,
remaining,
padding.clone(),
])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
#[cfg(feature = "flightsql")]
let title = Span::from("CONTEXT (5)").bold();

#[cfg(not(feature = "flightsql"))]
let title = Span::from("CONTEXT (4)").bold();

Line::from_iter(vec![padding.clone(), title, padding.clone()])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
}
Self::History => {
let bold_char = Span::from("H").bold().black();
let remaining = Span::from("ISTORY");
Line::from_iter(vec![padding.clone(), bold_char, remaining, padding.clone()])
#[cfg(feature = "flightsql")]
let title = Span::from("HISTORY (3)");
#[cfg(not(feature = "flightsql"))]
let title = Span::from("HISTORY (2)");
Line::from_iter(vec![padding.clone(), title, padding.clone()])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
}
Expand All @@ -98,7 +99,7 @@ impl SelectedTab {
Self::Context => tailwind::ORANGE.c700,
Self::History => tailwind::ORANGE.c700,
#[cfg(feature = "flightsql")]
Self::FlightSQL => tailwind::EMERALD.c700,
Self::FlightSQL => tailwind::ORANGE.c700,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ui/tabs/flightsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{app::App, ui::convert::record_batches_to_table};

pub fn render_sql_editor(area: Rect, buf: &mut Buffer, app: &App) {
let border_color = if app.state.flightsql_tab.editor_editable() {
tailwind::GREEN.c300
tailwind::ORANGE.c300
} else {
tailwind::WHITE
};
Expand All @@ -51,7 +51,7 @@ pub fn render_sql_results(area: Rect, buf: &mut Buffer, app: &App) {
q.num_rows().unwrap_or(0),
q.elapsed_time().as_millis()
))
.fg(tailwind::GREEN.c300);
.fg(tailwind::ORANGE.c500);
let maybe_table = record_batches_to_table(r);
match maybe_table {
Ok(table) => {
Expand Down

0 comments on commit 570c098

Please sign in to comment.