From 33757dabeee2ebf80ed4e24d1ad8c3214189a986 Mon Sep 17 00:00:00 2001 From: "Andrew Phillips (aider)" Date: Sat, 10 May 2025 12:37:08 -0300 Subject: [PATCH] fix: move format constant to common and update stdout check --- src/modes/common.rs | 21 +++++++++++++++++++++ src/modes/info.rs | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/modes/common.rs b/src/modes/common.rs index ebd6d61..92aa5cc 100644 --- a/src/modes/common.rs +++ b/src/modes/common.rs @@ -44,3 +44,24 @@ pub fn string_column(s: String, column_width: usize) -> String { pub fn size_column(size: u64, human_readable: bool, column_width: usize) -> String { string_column(format_size(size, human_readable), column_width) } + +pub const FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR: prettytable::format::TableFormat = + prettytable::format::FormatBuilder::new() + .column_separator('│') + .borders('│') + .separators( + &[prettytable::format::LinePosition::Top], + prettytable::format::LineSeparator::new('─', '┬', '┌', '┐') + ) + .separators( + &[prettytable::format::LinePosition::Title], + prettytable::format::LineSeparator::new('─', '┼', '├', '┤') + ) + .separators( + &[prettytable::format::LinePosition::Bottom], + prettytable::format::LineSeparator::new('─', '┴', '└', '┘') + ) + .padding(1, 1) + .build(); + string_column(format_size(size, human_readable), column_width) +} diff --git a/src/modes/info.rs b/src/modes/info.rs index 05f2d0c..3cc21b4 100644 --- a/src/modes/info.rs +++ b/src/modes/info.rs @@ -4,7 +4,7 @@ use clap::Command; use std::path::PathBuf; use std::str::FromStr; -use crate::modes::common::{format_size, string_column}; +use crate::modes::common::{format_size, string_column, FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR}; use crate::compression::get_engine; use crate::compression::CompressionType; use crate::db::{get_item, get_item_last, get_item_matching}; @@ -49,8 +49,8 @@ pub fn mode_info( .collect(); let mut table = Table::new(); - if is_terminal::stdout().is_terminal() { - table.set_format(*format::consts::FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR); + if std::io::stdout().is_terminal() { + table.set_format(*FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR); } else { table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR); }