add normalize_to_nfc config option

refs: #2482
This commit is contained in:
Wez Furlong committed 2022-09-06 08:58:09 -07:00
1 parent bcc4015bc4
commit c25e6820ef
5 files changed
+24 -1

No files matched your search

+3
View File
@@ -310,6 +310,9 @@ pub struct Config {
#[dynamic(default)]
pub debug_key_events: bool,
#[dynamic(default)]
pub normalize_to_nfc: bool,
#[dynamic(default)]
pub disable_default_key_bindings: bool,
pub leader: Option<LeaderKey>,
+4
View File
@@ -97,6 +97,10 @@ impl wezterm_term::TerminalConfiguration for TermConfig {
self.configuration().debug_key_events
}
fn normalize_to_nfc(&self) -> bool {
self.configuration().normalize_to_nfc
}
fn bidi_mode(&self) -> BidiMode {
let config = self.configuration();
BidiMode {
+1
View File
@@ -27,6 +27,7 @@ num-traits = "0.2"
ordered-float = "3.0"
serde = {version="1.0", features = ["rc"]}
terminfo = "0.7"
unicode-normalization = "0.1.21"
unicode-segmentation = "1.8"
url = "2"
wezterm-bidi = { path = "../bidi" }
+6
View File
@@ -193,6 +193,12 @@ pub trait TerminalConfiguration: std::fmt::Debug {
}
}
/// Whether to normalize incoming text runs to
/// canonical NFC unicode representation
fn normalize_to_nfc(&self) -> bool {
false
}
fn debug_key_events(&self) -> bool {
false
}
+10 -1
View File
@@ -20,6 +20,7 @@ use termwiz::escape::{
Action, ControlCode, DeviceControlMode, Esc, EscCode, OperatingSystemCommand, CSI,
};
use termwiz::input::KeyboardEncoding;
use unicode_normalization::{is_nfc_quick, IsNormalized, UnicodeNormalization};
use url::Url;
use wezterm_bidi::ParagraphDirectionHint;
@@ -116,8 +117,16 @@ impl<'a> Performer<'a> {
let seqno = self.seqno;
let mut p = std::mem::take(&mut self.print);
let normalized: String;
let text = if self.config.normalize_to_nfc() && is_nfc_quick(p.chars()) != IsNormalized::Yes
{
normalized = p.as_str().nfc().collect();
normalized.as_str()
} else {
p.as_str()
};
for g in unicode_segmentation::UnicodeSegmentation::graphemes(p.as_str(), true) {
for g in unicode_segmentation::UnicodeSegmentation::graphemes(text, true) {
let g = self.remap_grapheme(g);
let print_width = grapheme_column_width(g, Some(self.unicode_version));