datafusion_dft/tui/ui/
mod.rspub mod convert;
pub mod tabs;
use ratatui::{prelude::*, style::palette::tailwind};
use strum::{Display, EnumIter, FromRepr};
use crate::tui::App;
use self::tabs::{context, history, logs, sql};
#[derive(Clone, Copy, Debug, Display, FromRepr, EnumIter)]
pub enum SelectedTab {
#[allow(clippy::upper_case_acronyms)]
#[strum(to_string = "SQL")]
SQL,
#[cfg(feature = "flightsql")]
#[strum(to_string = "FlightSQL")]
FlightSQL,
#[strum(to_string = "History")]
History,
#[strum(to_string = "Logs")]
Logs,
#[strum(to_string = "Context")]
Context,
}
impl SelectedTab {
pub fn title(self, _app: &App) -> Line<'static> {
let padding = Span::from(" ");
match self {
SelectedTab::SQL => {
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 status = _app.state.flightsql_tab.connection_status().tab_display();
let title_text = format!("FlightSQL{status} (2)");
let title = Span::from(title_text).bold();
Line::from_iter(vec![padding.clone(), title, padding.clone()])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
}
Self::Logs => {
#[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 => {
#[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 => {
#[cfg(feature = "flightsql")]
let title = Span::from("HISTORY (3)").bold();
#[cfg(not(feature = "flightsql"))]
let title = Span::from("HISTORY (2)").bold();
Line::from_iter(vec![padding.clone(), title, padding.clone()])
.fg(tailwind::SLATE.c200)
.bg(self.bg())
}
}
}
const fn bg(self) -> Color {
match self {
Self::SQL => tailwind::ORANGE.c700,
Self::Logs => tailwind::ORANGE.c700,
Self::Context => tailwind::ORANGE.c700,
Self::History => tailwind::ORANGE.c700,
#[cfg(feature = "flightsql")]
Self::FlightSQL => tailwind::ORANGE.c700,
}
}
pub fn previous(self) -> Self {
let current_index: usize = self as usize;
let previous_index = current_index.saturating_sub(1);
Self::from_repr(previous_index).unwrap_or(self)
}
pub fn next(self) -> Self {
let current_index = self as usize;
let next_index = current_index.saturating_add(1);
Self::from_repr(next_index).unwrap_or(self)
}
fn render_sql(self, area: Rect, buf: &mut Buffer, app: &App) {
sql::render_sql(area, buf, app)
}
fn render_logs(self, area: Rect, buf: &mut Buffer, app: &App) {
logs::render_logs(area, buf, app)
}
fn render_context(self, area: Rect, buf: &mut Buffer, app: &App) {
context::render_context(area, buf, app)
}
fn render_history(self, area: Rect, buf: &mut Buffer, app: &App) {
history::render_history(area, buf, app)
}
#[cfg(feature = "flightsql")]
fn render_flightsql(self, area: Rect, buf: &mut Buffer, app: &App) {
use self::tabs::flightsql;
flightsql::render_sql(area, buf, app)
}
pub fn render(self, area: Rect, buf: &mut Buffer, app: &App) {
match self {
Self::SQL => self.render_sql(area, buf, app),
Self::Logs => self.render_logs(area, buf, app),
Self::Context => self.render_context(area, buf, app),
Self::History => self.render_history(area, buf, app),
#[cfg(feature = "flightsql")]
Self::FlightSQL => self.render_flightsql(area, buf, app),
}
}
}