2021-07-18 15:50:39 +00:00
|
|
|
use super::{Component, DrawableComponent, EventState};
|
2021-07-29 10:47:36 +00:00
|
|
|
use crate::components::command::CommandInfo;
|
2021-07-08 14:08:04 +00:00
|
|
|
use crate::event::Key;
|
|
|
|
use anyhow::Result;
|
|
|
|
use database_tree::Table;
|
|
|
|
use tui::{
|
|
|
|
backend::Backend,
|
|
|
|
layout::Rect,
|
|
|
|
style::{Color, Style},
|
|
|
|
text::{Span, Spans},
|
2021-09-11 04:07:53 +00:00
|
|
|
widgets::{Block, Borders, Paragraph},
|
2021-07-08 14:08:04 +00:00
|
|
|
Frame,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub struct TableStatusComponent {
|
2021-09-05 13:50:38 +00:00
|
|
|
column_count: Option<usize>,
|
|
|
|
row_count: Option<usize>,
|
2021-07-25 14:34:51 +00:00
|
|
|
table: Option<Table>,
|
2021-07-08 14:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TableStatusComponent {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-09-05 13:50:38 +00:00
|
|
|
row_count: None,
|
|
|
|
column_count: None,
|
2021-07-08 14:08:04 +00:00
|
|
|
table: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TableStatusComponent {
|
2021-09-05 13:50:38 +00:00
|
|
|
pub fn new(
|
|
|
|
row_count: Option<usize>,
|
|
|
|
column_count: Option<usize>,
|
|
|
|
table: Option<Table>,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
row_count,
|
|
|
|
column_count,
|
|
|
|
table,
|
2021-07-08 14:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DrawableComponent for TableStatusComponent {
|
2021-09-17 06:16:31 +00:00
|
|
|
fn draw<B: Backend>(&self, f: &mut Frame<B>, area: Rect, focused: bool) -> Result<()> {
|
2021-09-05 13:50:38 +00:00
|
|
|
let status = Paragraph::new(Spans::from(vec![
|
|
|
|
Span::from(format!(
|
2021-09-06 07:09:09 +00:00
|
|
|
"rows: {}, ",
|
2021-09-05 13:50:38 +00:00
|
|
|
self.row_count.map_or("-".to_string(), |c| c.to_string())
|
|
|
|
)),
|
|
|
|
Span::from(format!(
|
2021-09-06 07:09:09 +00:00
|
|
|
"columns: {}, ",
|
2021-09-05 13:50:38 +00:00
|
|
|
self.column_count.map_or("-".to_string(), |c| c.to_string())
|
|
|
|
)),
|
2021-09-06 07:09:09 +00:00
|
|
|
Span::from(format!(
|
|
|
|
"engine: {}",
|
|
|
|
self.table.as_ref().map_or("-".to_string(), |c| {
|
|
|
|
c.engine.as_ref().map_or("-".to_string(), |e| e.to_string())
|
|
|
|
})
|
|
|
|
)),
|
2021-09-05 13:50:38 +00:00
|
|
|
]))
|
|
|
|
.block(Block::default().borders(Borders::TOP).style(if focused {
|
|
|
|
Style::default()
|
|
|
|
} else {
|
|
|
|
Style::default().fg(Color::DarkGray)
|
2021-09-11 04:07:53 +00:00
|
|
|
}));
|
2021-09-05 13:50:38 +00:00
|
|
|
f.render_widget(status, area);
|
2021-07-08 14:08:04 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for TableStatusComponent {
|
2021-07-31 16:03:39 +00:00
|
|
|
fn commands(&self, _out: &mut Vec<CommandInfo>) {}
|
2021-07-29 10:47:36 +00:00
|
|
|
|
2021-07-18 15:50:39 +00:00
|
|
|
fn event(&mut self, _key: Key) -> Result<EventState> {
|
|
|
|
Ok(EventState::NotConsumed)
|
2021-07-08 14:08:04 +00:00
|
|
|
}
|
|
|
|
}
|