mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-02 06:44:23 +01:00
cli: Make pretty mode pretty like DuckDB
DuckDB is pretty, I want to be pretty! ``` limbo> CREATE TABLE t(x); INSERT INTO t VALUES (1), (2), (3); limbo> .mode pretty limbo> SELECT * FROM t; ┌───┐ │ x │ ├───┤ │ 1 │ ├───┤ │ 2 │ ├───┤ │ 3 │ └───┘ ```
This commit is contained in:
41
cli/app.rs
41
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<Vec<cli_table::CellStruct>>) {
|
||||
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!(
|
||||
|
||||
Reference in New Issue
Block a user