Skip to content

use ansi-width instead of textwrap for width calculation #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ pub struct Grid<T: AsRef<str>> {
impl<T: AsRef<str>> Grid<T> {
/// Creates a new grid view with the given cells and options
pub fn new(cells: Vec<T>, options: GridOptions) -> Self {
let widths: Vec<usize> = cells.iter().map(|c| display_width(c.as_ref())).collect();
let widths: Vec<usize> = 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;

Expand Down