From 86334685667411ae36e7a3d9f59f6a7ae1750b7f Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sun, 18 Feb 2024 20:23:58 +0100 Subject: [PATCH] use ansi-width instead of textwrap for width calculation --- Cargo.toml | 2 +- src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 18e1dde..8ccfca4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ rust-version = "1.70" name = "term_grid" [dependencies] -textwrap = { version = "0.16.1", default-features = false, features = ["unicode-width"] } +ansi-width = "0.1.0" diff --git a/src/lib.rs b/src/lib.rs index 4eb5249..0c3a094 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,8 +10,8 @@ #![deny(unsafe_code)] #![doc = include_str!("../README.md")] +use ansi_width::ansi_width; use std::fmt; -use textwrap::core::display_width; /// Direction cells should be written in: either across or downwards. #[derive(PartialEq, Eq, Debug, Copy, Clone)] @@ -43,7 +43,7 @@ impl Filling { fn width(&self) -> usize { match self { Filling::Spaces(w) => *w, - Filling::Text(t) => display_width(t), + Filling::Text(t) => ansi_width(t), } } } @@ -96,7 +96,7 @@ pub struct Grid> { impl> Grid { /// Creates a new grid view with the given cells and options pub fn new(cells: Vec, options: GridOptions) -> Self { - let widths: Vec = cells.iter().map(|c| display_width(c.as_ref())).collect(); + let widths: Vec = cells.iter().map(|c| ansi_width(c.as_ref())).collect(); let widest_cell_width = widths.iter().copied().max().unwrap_or(0); let width = options.width;