aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-08 10:29:31 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-08 10:29:31 -0500
commit25831eb0dbe5a9e222f3e31669f6c0c921d7e911 (patch)
tree09dd00e36ea23219c4a0489fcf845861f4be7519 /src
parentdbeb15e1104d682c118ff3916af797279d080405 (diff)
downloadvt100-rust-25831eb0dbe5a9e222f3e31669f6c0c921d7e911.tar.gz
vt100-rust-25831eb0dbe5a9e222f3e31669f6c0c921d7e911.zip
stop treating soft hyphen specially
Diffstat (limited to 'src')
-rw-r--r--src/cell.rs11
-rw-r--r--src/lib.rs1
-rw-r--r--src/screen.rs3
-rw-r--r--src/unicode.rs18
4 files changed, 12 insertions, 21 deletions
diff --git a/src/cell.rs b/src/cell.rs
index 54f433d..8d7e32f 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -1,4 +1,5 @@
use unicode_normalization::UnicodeNormalization as _;
+use unicode_width::UnicodeWidthChar as _;
/// Represents a single terminal cell.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
@@ -45,7 +46,15 @@ impl Cell {
/// Returns whether the text data in the cell represents a wide character.
pub fn is_wide(&self) -> bool {
- crate::unicode::str_width(&self.contents) > 1
+ // strings in this context should always be an arbitrary character
+ // followed by zero or more zero-width characters, so we should only
+ // have to look at the first character
+ let width = self
+ .contents
+ .chars()
+ .next()
+ .map_or(0, |c| c.width().unwrap_or(0));
+ width > 1
}
pub(crate) fn attrs(&self) -> &crate::attrs::Attrs {
diff --git a/src/lib.rs b/src/lib.rs
index 570f2d7..48dee07 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -33,7 +33,6 @@ mod grid;
mod parser;
mod row;
mod screen;
-mod unicode;
pub use attrs::Color;
pub use cell::Cell;
diff --git a/src/screen.rs b/src/screen.rs
index 7224f6a..7abd72c 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -1,4 +1,5 @@
use std::convert::TryInto as _;
+use unicode_width::UnicodeWidthChar as _;
const DEFAULT_MULTI_PARAMS: &[i64] = &[0];
@@ -470,7 +471,7 @@ impl Screen {
}
}
- let width = crate::unicode::char_width(c);
+ let width = c.width().unwrap_or(0).try_into().unwrap();
let attrs = self.attrs;
self.grid_mut().col_wrap(width);
diff --git a/src/unicode.rs b/src/unicode.rs
deleted file mode 100644
index 7897792..0000000
--- a/src/unicode.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-use std::convert::TryInto as _;
-use unicode_width::UnicodeWidthChar as _;
-
-// soft hyphen is defined as width 1, but in a terminal setting it should
-// always be width 0
-pub fn char_width(c: char) -> u16 {
- match c {
- '\u{00ad}' => 0,
- _ => c.width().unwrap_or(0).try_into().unwrap(),
- }
-}
-
-// strings in this context should always be an arbitrary character followed by
-// zero or more zero-width characters, so we should only have to look at the
-// first character
-pub fn str_width(s: &str) -> u16 {
- s.chars().next().map_or(0, char_width)
-}