mirror of
https://github.com/uutils/uutils-term-grid.git
synced 2026-06-10 16:13:01 -07:00
Merge pull request #36 from tertsdiepraam/ansi-width
use ansi-width instead of textwrap for width calculation
This commit is contained in:
+1
-1
@@ -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"
|
||||
|
||||
+3
-3
@@ -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<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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user