diff --git a/cli/app.rs b/cli/app.rs index 729a8cf6e..7fa7b70f0 100644 --- a/cli/app.rs +++ b/cli/app.rs @@ -2,6 +2,7 @@ use crate::{ import::{ImportFile, IMPORT_HELP}, opcodes_dictionary::OPCODE_DESCRIPTIONS, }; +use cli_table::format::{Border, HorizontalLine, Separator, VerticalLine}; use cli_table::{Cell, Style, Table}; use limbo_core::{Database, LimboError, Statement, StepResult, Value}; @@ -717,11 +718,7 @@ impl Limbo { } } } - if let Ok(table) = table_rows.table().display() { - let _ = self.write_fmt(format_args!("{}", table)); - } else { - let _ = self.writeln("Error displaying table."); - } + self.print_table(table_rows); } }, Ok(None) => {} @@ -737,6 +734,40 @@ impl Limbo { Ok(()) } + fn print_table(&mut self, table_rows: Vec>) { + if table_rows.is_empty() { + return; + } + + let horizontal_line = HorizontalLine::new('┌', '┐', '┬', '─'); + let horizontal_line_mid = HorizontalLine::new('├', '┤', '┼', '─'); + let horizontal_line_bottom = HorizontalLine::new('└', '┘', '┴', '─'); + let vertical_line = VerticalLine::new('│'); + + let border = Border::builder() + .top(horizontal_line) + .bottom(horizontal_line_bottom) + .left(vertical_line.clone()) + .right(vertical_line.clone()) + .build(); + + let separator = Separator::builder() + .column(Some(vertical_line)) + .row(Some(horizontal_line_mid)) + .build(); + + if let Ok(table) = table_rows + .table() + .border(border) + .separator(separator) + .display() + { + let _ = self.write_fmt(format_args!("{}", table)); + } else { + let _ = self.writeln("Error displaying table."); + } + } + fn display_schema(&mut self, table: Option<&str>) -> anyhow::Result<()> { let sql = match table { Some(table_name) => format!(