summaryrefslogtreecommitdiffstats
path: root/src/draw.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2019-07-19 17:45:09 -0400
committerDan Davison <dandavison7@gmail.com>2019-07-20 18:10:27 -0400
commit2404597c29f1ca4125740891224216d00e75ac6f (patch)
tree09deb1306a8f7f9911f8af89004a4389d5aca40c /src/draw.rs
parent003d3c464888f603df63b727adab639b024a6ab3 (diff)
Use grapheme units for all visible character calculations0.0.4
Diffstat (limited to 'src/draw.rs')
-rw-r--r--src/draw.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/draw.rs b/src/draw.rs
index 1018614f..7fe54e1d 100644
--- a/src/draw.rs
+++ b/src/draw.rs
@@ -3,6 +3,7 @@ use std::io::Write;
use ansi_term::Style;
use box_drawing;
use console::strip_ansi_codes;
+use unicode_segmentation::UnicodeSegmentation;
/// Write text to stream, surrounded by a box, leaving the cursor just
/// beyond the bottom right corner.
@@ -18,7 +19,7 @@ pub fn write_boxed(
} else {
box_drawing::light::UP_LEFT
};
- let box_width = strip_ansi_codes(text).len() + 1;
+ let box_width = strip_ansi_codes(text).graphemes(true).count() + 1;
write_boxed_partial(writer, text, box_width, line_style, heavy)?;
write!(writer, "{}", line_style.paint(up_left))?;
Ok(())
@@ -33,7 +34,7 @@ pub fn write_boxed_with_line(
line_style: Style,
heavy: bool,
) -> std::io::Result<()> {
- let box_width = strip_ansi_codes(text).len() + 1;
+ let box_width = strip_ansi_codes(text).graphemes(true).count() + 1;
write_boxed_with_horizontal_whisker(writer, text, box_width, line_style, heavy)?;
write_horizontal_line(writer, line_width - box_width - 1, line_style, heavy)?;
Ok(())