mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-29 02:53:06 +00:00
Merge pull request #177 from quininer/cjk
Fix TextCellContents cjk width
This commit is contained in:
commit
5bec218878
@ -1,5 +1,6 @@
|
|||||||
//! The `TextCell` type for the details and lines views.
|
//! The `TextCell` type for the details and lines views.
|
||||||
|
|
||||||
|
use std::iter::Sum;
|
||||||
use std::ops::{Add, Deref, DerefMut};
|
use std::ops::{Add, Deref, DerefMut};
|
||||||
|
|
||||||
use ansi_term::{Style, ANSIString, ANSIStrings};
|
use ansi_term::{Style, ANSIString, ANSIStrings};
|
||||||
@ -163,11 +164,9 @@ impl TextCellContents {
|
|||||||
/// Calculates the width that a cell with these contents would take up, by
|
/// Calculates the width that a cell with these contents would take up, by
|
||||||
/// counting the number of characters in each unformatted ANSI string.
|
/// counting the number of characters in each unformatted ANSI string.
|
||||||
pub fn width(&self) -> DisplayWidth {
|
pub fn width(&self) -> DisplayWidth {
|
||||||
let sum = self.0.iter()
|
self.0.iter()
|
||||||
.map(|anstr| anstr.chars().count())
|
.map(|anstr| DisplayWidth::from(anstr.deref()))
|
||||||
.sum();
|
.sum()
|
||||||
|
|
||||||
DisplayWidth(sum)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Promotes these contents to a full cell containing them alongside
|
/// Promotes these contents to a full cell containing them alongside
|
||||||
@ -239,6 +238,12 @@ impl Add<usize> for DisplayWidth {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Sum for DisplayWidth {
|
||||||
|
fn sum<I>(iter: I) -> Self where I: Iterator<Item=Self> {
|
||||||
|
iter.fold(DisplayWidth(0), Add::add)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod width_unit_test {
|
mod width_unit_test {
|
||||||
|
Loading…
Reference in New Issue
Block a user