Files
LLeMbas-TTY/term/src/config.rs
T
Wez Furlong 225e7a1243 introduce unicode_version config
This is a fairly far-reaching commit. The idea is:

* Introduce a unicode_version config that specifies the default level
  of unicode conformance for each newly created Terminal (each Pane)
* The unicode_version is passed down to the `grapheme_column_width`
  function which interprets the width based on the version
* `Cell` records the width so that later calculations don't need to
  know the unicode version

In a subsequent diff, I will introduce an escape sequence that allows
setting/pushing/popping the unicode version so that it can be overridden
via eg: a shell alias prior to launching an application that uses a
different version of unicode from the default.

This approach allows output from multiple applications with differing
understanding of unicode to coexist on the same screen a little more
sanely.

Note that the default `unicode_version` is set to 9, which means that
emoji presentation selectors are now by-default ignored.  This was
selected to better match the level of support in widely deployed
applications.

I expect to raise that default version in the future.

Also worth noting: there are a number of callers of
`unicode_column_width` in things like overlays and lua helper functions
that pass `None` for the unicode version: these will assume the latest
known-to-wezterm/termwiz version of unicode to be desired. If those
overlays do things with emoji presentation selectors, then there may be
some alignment artifacts. That can be tackled in a follow up commit.

refs: #1231
refs: #997
2021-11-25 09:00:45 -07:00

99 lines
3.8 KiB
Rust

use crate::color::ColorPalette;
use termwiz::hyperlink::Rule as HyperlinkRule;
/// TerminalConfiguration allows for the embedding application to pass configuration
/// information to the Terminal.
/// The configuration can be changed at runtime; provided that the implementation
/// increments the generation counter appropriately, the changes will be detected
/// and applied at the next appropriate opportunity.
pub trait TerminalConfiguration: std::fmt::Debug {
/// Returns a generation counter for the active
/// configuration. If the implementation may be
/// changed at runtime, it must increment the generation
/// number with each change so that any caches maintained
/// by the terminal can be flushed.
fn generation(&self) -> usize {
0
}
/// Returns the size of the scrollback in terms of the number of rows.
fn scrollback_size(&self) -> usize {
3500
}
/// Return true if the embedding application wants to use CSI-u encoding
/// for keys that would otherwise be ambiguous.
/// <http://www.leonerd.org.uk/hacks/fixterms/>
fn enable_csi_u_key_encoding(&self) -> bool {
false
}
/// Returns the current generation and its associated hyperlink rules.
/// hyperlink rules are used to recognize and automatically generate
/// hyperlink attributes for runs of text that match the provided rules.
fn hyperlink_rules(&self) -> (usize, Vec<HyperlinkRule>) {
(self.generation(), vec![])
}
/// Returns the default color palette for the application.
/// Various escape sequences can dynamically modify the effective
/// color palette for a terminal instance at runtime, but this method
/// defines the initial palette.
fn color_palette(&self) -> ColorPalette;
/// Return true if a resize operation should consider rows that have
/// made it to scrollback as being immutable.
/// When immutable, the resize operation will pad out the screen height
/// with additional blank rows and due to implementation details means
/// that the user will need to scroll back the scrollbar post-resize
/// than they would otherwise.
///
/// When mutable, resizing the window taller won't add extra rows;
/// instead the resize will tend to have "bottom gravity" meaning that
/// making the window taller will reveal more history than in the other
/// mode.
///
/// mutable is generally speaking a nicer experience.
///
/// On Windows, the PTY layer doesn't play well with a mutable scrollback,
/// frequently moving the cursor up to high and erasing portions of the
/// screen.
///
/// This behavior only happens with the windows pty layer; it doesn't
/// manifest when using eg: ssh directly to a remote unix system.
///
/// Ideally we'd have this return `true` only for the native windows
/// pty layer, but for the sake of simplicity, we make this conditional
/// on being a windows build.
fn resize_preserves_scrollback(&self) -> bool {
cfg!(windows)
}
fn canonicalize_pasted_newlines(&self) -> bool {
cfg!(windows)
}
fn alternate_buffer_wheel_scroll_speed(&self) -> u8 {
3
}
fn enq_answerback(&self) -> String {
"".to_string()
}
fn enable_kitty_graphics(&self) -> bool {
false
}
/// The default unicode version to assume.
/// This affects how the width of certain sequences is interpreted.
/// At the time of writing, we default to 9 even though the current
/// version of unicode is 14. 14 introduced emoji presentation selectors
/// 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
}
}