From e73cad387f2d9182e32f5cc5b632f257d20109ab Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Wed, 5 Mar 2025 17:03:03 -0300 Subject: [PATCH] adding table colors --- cli/Cargo.toml | 13 +++++++------ cli/app.rs | 25 ++++++++++++++++--------- cli/build.rs | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 67c90b208..99add273d 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -20,23 +20,24 @@ path = "main.rs" [dependencies] anyhow = "1.0.75" -cfg-if = "1.0.0" clap = { version = "4.5", features = ["derive"] } comfy-table = "7.1.4" -csv = "1.3.1" -ctrlc = "3.4.4" dirs = "5.0.1" env_logger = "0.10.1" limbo_core = { path = "../core", default-features = true, features = [ "completion", ] } -miette = { version = "7.4.0", features = ["fancy"] } rustyline = { version = "15.0.0", default-features = true, features = [ "derive", ] } -syntect = "5.2.0" -tracing = "0.1.41" +ctrlc = "3.4.4" +csv = "1.3.1" +miette = { version = "7.4.0", features = ["fancy"] } +cfg-if = "1.0.0" tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } +tracing = "0.1.41" +syntect = "5.2.0" + [features] default = ["io_uring"] diff --git a/cli/app.rs b/cli/app.rs index a6cd6d03e..dc5df06c1 100644 --- a/cli/app.rs +++ b/cli/app.rs @@ -4,7 +4,7 @@ use crate::{ input::{get_io, get_writer, DbLocation, Io, OutputMode, Settings, HELP_MSG}, opcodes_dictionary::OPCODE_DESCRIPTIONS, }; -use comfy_table::{Attribute, Cell, CellAlignment, ContentArrangement, Row, Table}; +use comfy_table::{Attribute, Cell, CellAlignment, Color, ContentArrangement, Row, Table}; use limbo_core::{Database, LimboError, OwnedValue, Statement, StepResult}; use clap::{Parser, ValueEnum}; @@ -742,24 +742,31 @@ impl<'a> Limbo<'a> { let mut row = Row::new(); row.max_height(1); for value in record.get_values() { - let (content, alignment) = match value { - OwnedValue::Null => { - (self.opts.null_value.clone(), CellAlignment::Left) - } + let (content, alignment, color) = match value { + OwnedValue::Null => ( + self.opts.null_value.clone(), + CellAlignment::Left, + Color::White, + ), OwnedValue::Integer(i) => { - (i.to_string(), CellAlignment::Right) + (i.to_string(), CellAlignment::Right, Color::DarkRed) } OwnedValue::Float(f) => { - (f.to_string(), CellAlignment::Right) + (f.to_string(), CellAlignment::Right, Color::DarkRed) + } + OwnedValue::Text(s) => { + (s.to_string(), CellAlignment::Left, Color::DarkGreen) } - OwnedValue::Text(s) => (s.to_string(), CellAlignment::Left), OwnedValue::Blob(b) => ( String::from_utf8_lossy(b).to_string(), CellAlignment::Left, + Color::DarkGreen, ), _ => unreachable!(), }; - row.add_cell(Cell::new(content).set_alignment(alignment)); + row.add_cell( + Cell::new(content).set_alignment(alignment).fg(color), + ); } table.add_row(row); } diff --git a/cli/build.rs b/cli/build.rs index 515725fa5..a47762294 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,5 +1,5 @@ //! Build.rs script to generate a binary syntax set for syntect -//! based on the SQL.sublime-syntax file. +//! based on the SQL.sublime-syntax file. use std::env; use std::path::Path;