aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/cell.rs11
-rw-r--r--src/lib.rs1
-rw-r--r--src/screen.rs3
-rw-r--r--src/unicode.rs18
-rw-r--r--tests/text.rs99
6 files changed, 14 insertions, 120 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e16e88d..25f5b56 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,8 @@
* Fixed RI when the cursor is at the top of the screen (fixes scrolling up in
`less`, for instance).
* Fixed VPA incorrectly being clamped to the scroll region.
+* Stop treating soft hyphen specially (as far as i can tell, no other terminals
+ do this, and i'm not sure why i thought it was necessary to begin with).
## [0.3.1] - 2019-11-06
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)
-}
diff --git a/tests/text.rs b/tests/text.rs
index b23d892..2469440 100644
--- a/tests/text.rs
+++ b/tests/text.rs
@@ -208,102 +208,3 @@ fn wrap() {
assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "");
}
-
-#[test]
-fn soft_hyphen() {
- let mut parser = vt100::Parser::new(24, 140);
- parser.process(b"Free En\xc2\xadter\xc2\xadprise is gonna ru\xc2\xadin ev\xc2\xadery\xc2\xadthing good un\xc2\xadless we take a knife to its tes\xc2\xadti\xc2\xadcles first.");
- assert_eq!(parser.screen().contents(), "Free En\u{00ad}ter\u{00ad}prise is gonna ru\u{00ad}in ev\u{00ad}ery\u{00ad}thing good un\u{00ad}less we take a knife to its tes\u{00ad}ti\u{00ad}cles first.");
- assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "F");
- assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "r");
- assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), "E");
- assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), "n\u{00ad}");
- assert_eq!(parser.screen().cell(0, 7).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 8).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 9).unwrap().contents(), "r\u{00ad}");
- assert_eq!(parser.screen().cell(0, 10).unwrap().contents(), "p");
- assert_eq!(parser.screen().cell(0, 11).unwrap().contents(), "r");
- assert_eq!(parser.screen().cell(0, 12).unwrap().contents(), "i");
- assert_eq!(parser.screen().cell(0, 13).unwrap().contents(), "s");
- assert_eq!(parser.screen().cell(0, 14).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 15).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 16).unwrap().contents(), "i");
- assert_eq!(parser.screen().cell(0, 17).unwrap().contents(), "s");
- assert_eq!(parser.screen().cell(0, 18).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 19).unwrap().contents(), "g");
- assert_eq!(parser.screen().cell(0, 20).unwrap().contents(), "o");
- assert_eq!(parser.screen().cell(0, 21).unwrap().contents(), "n");
- assert_eq!(parser.screen().cell(0, 22).unwrap().contents(), "n");
- assert_eq!(parser.screen().cell(0, 23).unwrap().contents(), "a");
- assert_eq!(parser.screen().cell(0, 24).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 25).unwrap().contents(), "r");
- assert_eq!(parser.screen().cell(0, 26).unwrap().contents(), "u\u{00ad}");
- assert_eq!(parser.screen().cell(0, 27).unwrap().contents(), "i");
- assert_eq!(parser.screen().cell(0, 28).unwrap().contents(), "n");
- assert_eq!(parser.screen().cell(0, 29).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 30).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 31).unwrap().contents(), "v\u{00ad}");
- assert_eq!(parser.screen().cell(0, 32).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 33).unwrap().contents(), "r");
- assert_eq!(parser.screen().cell(0, 34).unwrap().contents(), "y\u{00ad}");
- assert_eq!(parser.screen().cell(0, 35).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 36).unwrap().contents(), "h");
- assert_eq!(parser.screen().cell(0, 37).unwrap().contents(), "i");
- assert_eq!(parser.screen().cell(0, 38).unwrap().contents(), "n");
- assert_eq!(parser.screen().cell(0, 39).unwrap().contents(), "g");
- assert_eq!(parser.screen().cell(0, 40).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 41).unwrap().contents(), "g");
- assert_eq!(parser.screen().cell(0, 42).unwrap().contents(), "o");
- assert_eq!(parser.screen().cell(0, 43).unwrap().contents(), "o");
- assert_eq!(parser.screen().cell(0, 44).unwrap().contents(), "d");
- assert_eq!(parser.screen().cell(0, 45).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 46).unwrap().contents(), "u");
- assert_eq!(parser.screen().cell(0, 47).unwrap().contents(), "n\u{00ad}");
- assert_eq!(parser.screen().cell(0, 48).unwrap().contents(), "l");
- assert_eq!(parser.screen().cell(0, 49).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 50).unwrap().contents(), "s");
- assert_eq!(parser.screen().cell(0, 51).unwrap().contents(), "s");
- assert_eq!(parser.screen().cell(0, 52).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 53).unwrap().contents(), "w");
- assert_eq!(parser.screen().cell(0, 54).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 55).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 56).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 57).unwrap().contents(), "a");
- assert_eq!(parser.screen().cell(0, 58).unwrap().contents(), "k");
- assert_eq!(parser.screen().cell(0, 59).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 60).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 61).unwrap().contents(), "a");
- assert_eq!(parser.screen().cell(0, 62).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 63).unwrap().contents(), "k");
- assert_eq!(parser.screen().cell(0, 64).unwrap().contents(), "n");
- assert_eq!(parser.screen().cell(0, 65).unwrap().contents(), "i");
- assert_eq!(parser.screen().cell(0, 66).unwrap().contents(), "f");
- assert_eq!(parser.screen().cell(0, 67).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 68).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 69).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 70).unwrap().contents(), "o");
- assert_eq!(parser.screen().cell(0, 71).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 72).unwrap().contents(), "i");
- assert_eq!(parser.screen().cell(0, 73).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 74).unwrap().contents(), "s");
- assert_eq!(parser.screen().cell(0, 75).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 76).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 77).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 78).unwrap().contents(), "s\u{00ad}");
- assert_eq!(parser.screen().cell(0, 79).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 80).unwrap().contents(), "i\u{00ad}");
- assert_eq!(parser.screen().cell(0, 81).unwrap().contents(), "c");
- assert_eq!(parser.screen().cell(0, 82).unwrap().contents(), "l");
- assert_eq!(parser.screen().cell(0, 83).unwrap().contents(), "e");
- assert_eq!(parser.screen().cell(0, 84).unwrap().contents(), "s");
- assert_eq!(parser.screen().cell(0, 85).unwrap().contents(), " ");
- assert_eq!(parser.screen().cell(0, 86).unwrap().contents(), "f");
- assert_eq!(parser.screen().cell(0, 87).unwrap().contents(), "i");
- assert_eq!(parser.screen().cell(0, 88).unwrap().contents(), "r");
- assert_eq!(parser.screen().cell(0, 89).unwrap().contents(), "s");
- assert_eq!(parser.screen().cell(0, 90).unwrap().contents(), "t");
- assert_eq!(parser.screen().cell(0, 91).unwrap().contents(), ".");
-}