1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

Add treat_east_asian_ambiguous_width_as_wide option

I've bundled this into termwiz's UnicodeVersion type as that is
a similar concept that is already routed through to the appropriate
function.

refs: https://github.com/wez/wezterm/issues/1888
This commit is contained in:
Wez Furlong 2022-04-19 06:55:43 -07:00
parent 62b7b60012
commit 5b8b9630a3
8 changed files with 51 additions and 11 deletions

View File

@ -595,6 +595,9 @@ pub struct Config {
#[serde(default = "default_unicode_version")]
pub unicode_version: u8,
#[serde(default)]
pub treat_east_asian_ambiguous_width_as_wide: bool,
#[serde(default = "default_true")]
pub allow_download_protocols: bool,

View File

@ -2,6 +2,7 @@
use crate::{configuration, ConfigHandle, NewlineCanon};
use std::sync::Mutex;
use termwiz::cell::UnicodeVersion;
use wezterm_term::color::ColorPalette;
use wezterm_term::config::BidiMode;
@ -80,8 +81,12 @@ impl wezterm_term::TerminalConfiguration for TermConfig {
}
}
fn unicode_version(&self) -> u8 {
self.configuration().unicode_version
fn unicode_version(&self) -> UnicodeVersion {
let config = self.configuration();
UnicodeVersion {
version: config.unicode_version,
ambiguous_are_wide: config.treat_east_asian_ambiguous_width_as_wide,
}
}
fn debug_key_events(&self) -> bool {

View File

@ -19,6 +19,7 @@ As features stabilize some brief notes about them will accumulate here.
* [AttachDomain](config/lua/keyassignment/AttachDomain.md) and [DetachDomain](config/lua/keyassignment/DetachDomain.md) key assignments
* Specifying a domain name in a [SpawnCommand](config/lua/SpawnCommand.md) will cause that domain to be attached if it is in the detached state. This is useful when combined with [SwitchToWorkspace](config/lua/keyassignment/SwitchToWorkspace.md).
* X11: wezterm now sets `_NET_WM_NAME` in addition to `WM_NAME` for clients that don't know how to fallback
* [treat_east_asian_ambiguous_width_as_wide](config/lua/config/treat_east_asian_ambiguous_width_as_wide.md) for control how ambiguous width characters are resolved. [#1888](https://github.com/wez/wezterm/issues/1888)
#### Changed
* Debian packages now register wezterm as an alternative for `x-terminal-emulator`. Thanks to [@xpufx](https://github.com/xpufx)! [#1883](https://github.com/wez/wezterm/pull/1883)

View File

@ -0,0 +1,17 @@
# `treat_east_asian_ambiguous_width_as_wide = fasel`
*Since: nightly builds only*
Unicode defines a number of codepoints as having [Ambiguous
Width](http://www.unicode.org/reports/tr11/#Ambiguous). These are characters
whose width resolves differently according to context that is typically absent
from the monospaced world of the terminal.
WezTerm will by default treat ambiguous width as occupying a single cell.
When `treat_east_asian_ambiguous_width_as_wide = true` WezTerm will treat them
as being two cells wide.
Note that changing this setting may have consequences for layout in text UI
applications if their expectation of width differs from your choice of
configuration.

View File

@ -1,4 +1,5 @@
use crate::color::ColorPalette;
use termwiz::cell::UnicodeVersion;
use termwiz::surface::{Line, SequenceNo};
use wezterm_bidi::ParagraphDirectionHint;
@ -181,8 +182,11 @@ pub trait TerminalConfiguration: std::fmt::Debug {
/// that also alter the width of certain sequences, and that is too
/// new for most deployed applications.
// Coupled with config/src/lib.rs:default_unicode_version
fn unicode_version(&self) -> u8 {
9
fn unicode_version(&self) -> UnicodeVersion {
UnicodeVersion {
version: 9,
ambiguous_are_wide: false,
}
}
fn debug_key_events(&self) -> bool {

View File

@ -497,7 +497,7 @@ impl TerminalState {
let color_map = default_color_map();
let unicode_version = UnicodeVersion(config.unicode_version());
let unicode_version = config.unicode_version();
TerminalState {
config,

View File

@ -7,7 +7,7 @@ use log::{debug, error};
use num_traits::FromPrimitive;
use std::fmt::Write;
use std::ops::{Deref, DerefMut};
use termwiz::cell::{grapheme_column_width, Cell, CellAttributes, SemanticType, UnicodeVersion};
use termwiz::cell::{grapheme_column_width, Cell, CellAttributes, SemanticType};
use termwiz::escape::csi::{CharacterPath, EraseInDisplay};
use termwiz::escape::osc::{
ChangeColorPair, ColorOrQuery, FinalTermSemanticPrompt, ITermProprietary,
@ -559,7 +559,7 @@ impl<'a> Performer<'a> {
self.palette.take();
self.top_and_bottom_margins = 0..self.screen().physical_rows as VisibleRowIndex;
self.left_and_right_margins = 0..self.screen().physical_cols;
self.unicode_version = UnicodeVersion(self.config.unicode_version());
self.unicode_version = self.config.unicode_version();
self.unicode_version_stack.clear();
self.suppress_initial_title_change = false;
self.accumulating_title.take();
@ -638,7 +638,7 @@ impl<'a> Performer<'a> {
}
}
ITermProprietary::UnicodeVersion(ITermUnicodeVersionOp::Set(n)) => {
self.unicode_version = UnicodeVersion(n);
self.unicode_version.version = n;
}
ITermProprietary::UnicodeVersion(ITermUnicodeVersionOp::Push(label)) => {
let vers = self.unicode_version;

View File

@ -829,9 +829,15 @@ impl Cell {
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct UnicodeVersion(pub u8);
pub struct UnicodeVersion {
pub version: u8,
pub ambiguous_are_wide: bool,
}
pub const LATEST_UNICODE_VERSION: UnicodeVersion = UnicodeVersion(14);
pub const LATEST_UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
version: 14,
ambiguous_are_wide: false,
};
/// Returns the number of cells visually occupied by a sequence
/// of graphemes.
@ -875,7 +881,9 @@ pub fn unicode_column_width(s: &str, version: Option<UnicodeVersion>) -> usize {
/// the Cell that is used to hold a grapheme, and that per-Cell version
/// can then be used to calculate width.
pub fn grapheme_column_width(s: &str, version: Option<UnicodeVersion>) -> usize {
let version = version.unwrap_or(LATEST_UNICODE_VERSION).0;
let version = version.unwrap_or(LATEST_UNICODE_VERSION);
let ambiguous_are_wide = version.ambiguous_are_wide;
let version = version.version;
let width: usize = s
.chars()
@ -887,6 +895,8 @@ pub fn grapheme_column_width(s: &str, version: Option<UnicodeVersion>) -> usize
// <https://github.com/wez/wezterm/issues/1864>
if c == WcWidth::Unassigned {
1
} else if c == WcWidth::Ambiguous && ambiguous_are_wide {
2
} else if version >= 9 {
c.width_unicode_9_or_later()
} else {