diff options
author | Wang Xuerui <git@xen0n.name> | 2019-11-14 11:48:30 +0800 |
---|---|---|
committer | Wang Xuerui <git@xen0n.name> | 2019-11-14 11:48:32 +0800 |
commit | b9ed24d34fa7d69abcc8169441c5649463915013 (patch) | |
tree | 24c1edfed1364ec641ae49942d510c3e0d48a27b /src/draw.rs | |
parent | 0052bd7b170188ec30fd1beb5ed89b51c8efbd70 (diff) |
Properly calculate string widths with unicode_width
Fixes diffs rendering with lines containing CJK characters.
Diffstat (limited to 'src/draw.rs')
-rw-r--r-- | src/draw.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/draw.rs b/src/draw.rs index 29670693..e89c9388 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -3,7 +3,7 @@ use std::io::Write; use ansi_term::Style; use box_drawing; use console::strip_ansi_codes; -use unicode_segmentation::UnicodeSegmentation; +use unicode_width::UnicodeWidthStr; /// Write text to stream, surrounded by a box, leaving the cursor just /// beyond the bottom right corner. @@ -19,7 +19,7 @@ pub fn write_boxed( } else { box_drawing::light::UP_LEFT }; - let box_width = strip_ansi_codes(text).graphemes(true).count() + 1; + let box_width = UnicodeWidthStr::width(strip_ansi_codes(text).as_ref()) + 1; write_boxed_partial(writer, text, box_width, line_style, heavy)?; write!(writer, "{}", line_style.paint(up_left))?; Ok(()) @@ -34,7 +34,7 @@ pub fn write_boxed_with_line( line_style: Style, heavy: bool, ) -> std::io::Result<()> { - let box_width = strip_ansi_codes(text).graphemes(true).count() + 1; + let box_width = UnicodeWidthStr::width(strip_ansi_codes(text).as_ref()) + 1; write_boxed_with_horizontal_whisker(writer, text, box_width, line_style, heavy)?; write_horizontal_line( writer, |