Skip to content

Commit 8633468

Browse files
committed
use ansi-width instead of textwrap for width calculation
1 parent d4f1772 commit 8633468

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ rust-version = "1.70"
1515
name = "term_grid"
1616

1717
[dependencies]
18-
textwrap = { version = "0.16.1", default-features = false, features = ["unicode-width"] }
18+
ansi-width = "0.1.0"

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#![deny(unsafe_code)]
1111
#![doc = include_str!("../README.md")]
1212

13+
use ansi_width::ansi_width;
1314
use std::fmt;
14-
use textwrap::core::display_width;
1515

1616
/// Direction cells should be written in: either across or downwards.
1717
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
@@ -43,7 +43,7 @@ impl Filling {
4343
fn width(&self) -> usize {
4444
match self {
4545
Filling::Spaces(w) => *w,
46-
Filling::Text(t) => display_width(t),
46+
Filling::Text(t) => ansi_width(t),
4747
}
4848
}
4949
}
@@ -96,7 +96,7 @@ pub struct Grid<T: AsRef<str>> {
9696
impl<T: AsRef<str>> Grid<T> {
9797
/// Creates a new grid view with the given cells and options
9898
pub fn new(cells: Vec<T>, options: GridOptions) -> Self {
99-
let widths: Vec<usize> = cells.iter().map(|c| display_width(c.as_ref())).collect();
99+
let widths: Vec<usize> = cells.iter().map(|c| ansi_width(c.as_ref())).collect();
100100
let widest_cell_width = widths.iter().copied().max().unwrap_or(0);
101101
let width = options.width;
102102

0 commit comments

Comments
 (0)