Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,17 +1,16 @@ [package] name = "qpprint" -version = "0.2.1" -authors = ["Jan Danielsson "] -edition = "2021" +version = "0.3.0" +edition = "2024" license = "0BSD" # https://crates.io/category_slugs categories = [ "text-processing" ] keywords = [ "cli", "console", "terminal", "format", "print" ] repository = "https://repos.qrnch.tech/pub/qpprint" description = "Simple console printing/formatting." -rust-version = "1.56" +rust-version = "1.85" exclude = [ ".fossil-settings", ".efiles", ".fslckout", "examples", @@ -23,16 +22,16 @@ # https://doc.rust-lang.org/cargo/reference/manifest.html#the-badges-section [badges] maintenance = { status = "experimental" } [dependencies] -colored = { version = "2.1.0" } -terminal_size = { version = "0.4.0" } +terminal_size = { version = "0.4.2" } +yansi = { version = "1.0.1" } [lints.clippy] -all = { level = "deny", priority = -1 } +all = { level = "warn", priority = -1 } pedantic = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 } cargo = { level = "warn", priority = -1 } multiple_crate_versions = "allow" Index: examples/newtbl.rs ================================================================== --- examples/newtbl.rs +++ examples/newtbl.rs @@ -1,8 +1,8 @@ use qpprint::tbl::{Align, CellValue, Column, Data, Renderer}; -use colored::{Color, ColoredString, Colorize}; +use yansi::{Color, Painted}; fn main() { table1(); println!(); table2(); @@ -49,25 +49,25 @@ /// Print `Id` as blue if it is greater than `20`. Print `Name` as red if it /// is equal to `world`. fn table2() { let idcol = Column::new("Id", ToString::to_string).stylize(|cv, s| { - let cs = ColoredString::from(s); + let cs = Painted::new(s.to_string()); if let CellValue::U64(id) = cv { if *id > 20 { - cs.color(Color::Blue) + cs.fg(Color::Blue) } else { cs } } else { cs } }); let namecol = Column::new("Name", ToString::to_string).stylize(|_cv, s| { - let cs = ColoredString::from(s); + let cs = Painted::new(s.to_string()); if s == "world" { - cs.color(Color::Red) + cs.fg(Color::Red) } else { cs } }); let columns = [idcol, namecol]; Index: src/lib.rs ================================================================== --- src/lib.rs +++ src/lib.rs @@ -1,9 +1,11 @@ pub mod tbl; use terminal_size::{terminal_size, Height, Width}; +pub use yansi::{Color, Painted}; + pub enum Types { Paragraph(String) } pub enum Align { @@ -78,17 +80,17 @@ hang: 0, maxwidth } } - pub fn set_indent(&mut self, indent: u16) -> &mut Self { + pub const fn set_indent(&mut self, indent: u16) -> &mut Self { self.indent = indent; self } /// Set a relative offset for the first line in a paragraph. - pub fn set_hang(&mut self, hang: i16) -> &mut Self { + pub const fn set_hang(&mut self, hang: i16) -> &mut Self { self.hang = hang; self } /* Index: src/tbl.rs ================================================================== --- src/tbl.rs +++ src/tbl.rs @@ -2,11 +2,11 @@ borrow::Cow, fmt, iter::{self, zip} }; -pub use colored::{Color, ColoredString, Colorize}; +use yansi::Painted; pub use super::Align; #[allow(clippy::type_complexity)] @@ -15,11 +15,11 @@ min_width: Option, max_width: Option, trunc_len: usize, trunc_ch: char, renderer: Box String>, - stylize: Option ColoredString>>, + stylize: Option Painted>>, title_align: Align, cell_align: Align } impl Column { @@ -75,48 +75,48 @@ self.max_width = Some(max); self } #[must_use] - pub fn trunc_style(mut self, len: usize, ch: char) -> Self { + pub const fn trunc_style(mut self, len: usize, ch: char) -> Self { self.trunc_style_ref(len, ch); self } - pub fn trunc_style_ref(&mut self, len: usize, ch: char) -> &mut Self { + pub const fn trunc_style_ref(&mut self, len: usize, ch: char) -> &mut Self { self.trunc_len = len; self.trunc_ch = ch; self } #[must_use] pub fn stylize( mut self, - f: impl Fn(&CellValue, &str) -> ColoredString + 'static + f: impl Fn(&CellValue, &str) -> Painted + 'static ) -> Self { self.stylize = Some(Box::new(f)); self } #[must_use] - pub fn title_align(mut self, align: Align) -> Self { + pub const fn title_align(mut self, align: Align) -> Self { self.title_align_ref(align); self } - pub fn title_align_ref(&mut self, align: Align) -> &mut Self { + pub const fn title_align_ref(&mut self, align: Align) -> &mut Self { self.title_align = align; self } #[must_use] - pub fn cell_align(mut self, align: Align) -> Self { + pub const fn cell_align(mut self, align: Align) -> Self { self.cell_align_ref(align); self } - pub fn cell_align_ref(&mut self, align: Align) -> &mut Self { + pub const fn cell_align_ref(&mut self, align: Align) -> &mut Self { self.cell_align = align; self } } @@ -145,11 +145,11 @@ } impl fmt::Display for CellValue { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Self::Str(ref s) => write!(f, "{s}"), + Self::Str(s) => write!(f, "{s}"), Self::U64(v) => write!(f, "{v}") } } } @@ -202,34 +202,34 @@ data: &data.cells } } #[must_use] - pub fn header(mut self, underline: Option) -> Self { + pub const fn header(mut self, underline: Option) -> Self { self.header_ref(underline); self } - pub fn header_ref(&mut self, underline: Option) -> &mut Self { + pub const fn header_ref(&mut self, underline: Option) -> &mut Self { self.show_header = true; self.header_underline = underline; self } #[must_use] - pub fn column_spacing(mut self, n: usize) -> Self { + pub const fn column_spacing(mut self, n: usize) -> Self { self.column_spacing_ref(n); self } - pub fn column_spacing_ref(&mut self, n: usize) -> &mut Self { + pub const fn column_spacing_ref(&mut self, n: usize) -> &mut Self { self.col_spacing = n; self } pub fn print(&self) { - println!("{}", self); + println!("{self}"); } } impl fmt::Display for Renderer<'_> { @@ -329,11 +329,12 @@ // Print heading underline // if let Some(ch) = self.header_underline { fields.clear(); for cw in &col_widths { - let line = iter::repeat(ch).take(*cw).collect::(); + //let line = iter::repeat(ch).take(*cw).collect::(); + let line = std::iter::repeat_n(ch, *cw).collect::(); fields.push(line); } writeln!(f, "{}", fields.join(&colspace))?; } } @@ -396,11 +397,12 @@ trunc_len: usize, trunc_ch: char ) -> Cow { if s.len() > width { let trunc = s[..s.len() - trunc_len - 1].to_string(); - let cont = iter::repeat(trunc_ch).take(trunc_len).collect::(); + //let cont = iter::repeat(trunc_ch).take(trunc_len).collect::(); + let cont = std::iter::repeat_n(trunc_ch, trunc_len).collect::(); let s = format!("{trunc}{cont}"); Cow::from(s) } else { Cow::from(s) } Index: www/changelog.md ================================================================== --- www/changelog.md +++ www/changelog.md @@ -2,17 +2,34 @@ ⚠️ indicates a breaking change. ## [Unreleased] -[Details](/vdiff?from=qpprint-0.2.0&to=trunk) +[Details](/vdiff?from=qpprint-0.3.0&to=trunk) + +### Added + +### Changed + +### Removed + +--- + +## [0.3.0] - 2025-05-16 + +[Details](/vdiff?from=qpprint-0.2.1&to=qpprint-0.3.0) + +### Changed + +- ⚠️ Switch from `colored` to `yansi` for coloring. +- Edition 2024 & MSRV `1.85` + +--- + +## [0.2.1] - 2024-10-21 + +[Details](/vdiff?from=qpprint-0.2.0&to=qpprint-0.2.1) ### Added - Add a new table implementation under `tbl::*`. -### Changed - -### Removed - ---- -