refactor: extract wezterm-char-props from termwiz

This new crate holds the unicode character properties
and other similar data on emoji and nerdfonts codepoints.
This commit is contained in:
Wez Furlong committed 2025-05-10 15:07:20 -07:00
1 parent 0cd3fe8f97
commit 80de3aa313
24 files changed
+182 -142

No files matched your search

+2
View File
@@ -13,6 +13,8 @@ dhat-heap.json
/wezterm*.tar.xz
/pkg
/target/
/wezterm-char-props/codegen/target
/wezterm-char-props/codegen/Cargo.lock
/termwiz/codegen/target
/termwiz/codegen/Cargo.lock
/gh_pages/
Generated
+11
View File
@@ -5678,6 +5678,7 @@ dependencies = [
"vtparse",
"wezterm-bidi",
"wezterm-blob-leases",
"wezterm-char-props",
"wezterm-color-types",
"wezterm-dynamic",
"wezterm-escape-parser",
@@ -6584,6 +6585,16 @@ dependencies = [
"uuid",
]
[[package]]
name = "wezterm-char-props"
version = "0.1.3"
dependencies = [
"k9",
"phf",
"serde",
"ucd-trie",
]
[[package]]
name = "wezterm-client"
version = "0.1.0"
+3 -1
View File
@@ -17,7 +17,8 @@ members = [
]
resolver = "2"
exclude = [
"termwiz/codegen"
"termwiz/codegen",
"wezterm-char-props/codegen",
]
[profile.release]
@@ -239,6 +240,7 @@ wayland-protocols = "0.32"
wayland-protocols-plasma = { version="0.3.6", features=["client"] }
wezterm-bidi = { version="0.2.3", path = "bidi" }
wezterm-blob-leases = { version="0.1.1", path = "wezterm-blob-leases"}
wezterm-char-props = { path = "wezterm-char-props" }
wezterm-client = { path = "wezterm-client" }
wezterm-color-types = { version="0.3", path = "color-types" }
wezterm-config-derive = { version="0.1", path="config/derive" }
+1 -4
View File
@@ -39,6 +39,7 @@ unicode-segmentation.workspace = true
vtparse.workspace = true
wezterm-bidi.workspace = true
wezterm-blob-leases = {workspace=true, optional=true}
wezterm-char-props.workspace = true
wezterm-color-types = {workspace = true, features=["std"]}
wezterm-dynamic = {workspace = true, features=["std"]}
wezterm-escape-parser = {workspace = true, features=["std"]}
@@ -85,10 +86,6 @@ workspace = true
features = ["docs"]
rustdoc-args = ["--cfg", "feature=\"docs\""]
[[bench]]
name = "wcwidth"
harness = false
[[bench]]
name = "cell"
harness = false
-13
View File
@@ -1,13 +0,0 @@
[package]
name = "codegen"
version = "0.1.0"
edition = "2021"
[dependencies]
human-sort.workspace = true
phf_codegen.workspace = true
reqwest = {workspace=true, features=["blocking"]}
serde = {workspace=true, features=["derive"]}
serde_json.workspace = true
ucd-trie.workspace = true
+4 -4
View File
@@ -1,11 +1,8 @@
//! Model a cell in the terminal display
use crate::color::{ColorAttribute, PaletteIndex};
pub use crate::emoji::Presentation;
use crate::emoji_variation::WCWIDTH_TABLE;
pub use crate::escape::osc::Hyperlink;
#[cfg(feature = "image")]
use crate::image::ImageCell;
use crate::widechar_width::WcWidth;
use finl_unicode::grapheme_clusters::Graphemes;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@@ -13,6 +10,9 @@ use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::mem;
use std::sync::Arc;
pub use wezterm_char_props::emoji::Presentation;
use wezterm_char_props::emoji_variation::WCWIDTH_TABLE;
use wezterm_char_props::widechar_width::WcWidth;
use wezterm_dynamic::{FromDynamic, ToDynamic};
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
@@ -879,7 +879,7 @@ pub const LATEST_UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
/// Returns true if the char `c` has the unicode White_Space property
pub fn is_white_space_char(c: char) -> bool {
crate::white_space::WHITE_SPACE.contains_u32(c as u32)
wezterm_char_props::white_space::WHITE_SPACE.contains_u32(c as u32)
}
/// Returns true if the grapheme string `g` consists entirely of characters
+1 -1
View File
@@ -1,8 +1,8 @@
use crate::cell::CellAttributes;
use crate::emoji::Presentation;
use crate::surface::line::CellRef;
use std::borrow::Cow;
use wezterm_bidi::{BidiContext, Direction, ParagraphDirectionHint};
use wezterm_char_props::emoji::Presentation;
/// A `CellCluster` is another representation of a Line.
/// A `Vec<CellCluster>` is produced by walking through the Cells in
+1 -8
View File
@@ -40,12 +40,6 @@
//! * `widgets` - enables the widget layout and related traits
//! * `use_serde` - makes a number of structs serde serializable
mod emoji;
mod emoji_presentation;
mod emoji_variation;
mod white_space;
mod widechar_width;
pub mod caps;
pub mod cell;
pub mod cellcluster;
@@ -59,8 +53,7 @@ pub mod istty;
pub mod keymap;
pub mod lineedit;
mod macros;
pub mod nerdfonts;
mod nerdfonts_data;
pub use wezterm_char_props::nerdfonts;
mod readbuf;
pub mod render;
pub mod surface;
+1 -1
View File
@@ -1,6 +1,6 @@
use crate::cell::{Cell, CellAttributes};
use crate::emoji::Presentation;
use std::hash::{Hash, Hasher};
use wezterm_char_props::emoji::Presentation;
#[derive(Debug, Clone, Copy)]
pub enum CellRef<'a> {
+27
View File
@@ -0,0 +1,27 @@
[package]
authors = ["Wez Furlong"]
name = "wezterm-char-props"
version = "0.1.3"
edition = "2021"
repository = "https://github.com/wezterm/wezterm"
description = "Unicode and other character properties"
license = "MIT"
documentation = "https://docs.rs/wezterm-char-props"
keywords = ["terminal", "unicode", "nerdfonts", "emoji"]
readme = "README.md"
[dependencies]
phf.workspace = true
serde = {workspace=true, optional=true}
ucd-trie.workspace = true
[features]
use_serde = ["serde"]
[dev-dependencies]
k9.workspace = true
[[bench]]
name = "wcwidth"
harness = false
File renamed without changes.
+15
View File
@@ -0,0 +1,15 @@
[package]
name = "wezterm-char-props-codegen"
version = "0.1.0"
edition = "2021"
[dependencies]
# This crate is excluded from the workspace, so its
# deps are managed explicitly here
human-sort = "0.2"
phf_codegen = "0.10"
reqwest = {version="0.12", features=["blocking"]}
serde = {version="1.0", features=["derive"]}
serde_json = "1.0"
ucd-trie = "0.1"
@@ -2,7 +2,6 @@ use std::io::Write;
use serde::Deserialize;
use serde_json::Value;
use std::collections::HashMap;
use std::path::Path;
const VARIATION_SEQUENCES: &str = include_str!("../../data/emoji-variation-sequences.txt");
@@ -11,7 +10,7 @@ include!("../../src/widechar_width.rs");
fn main() {
println!("//! This file was generated by running:");
println!("//! cd ../codegen ; cargo run > ../emoji_variation.rs");
println!("//! cd ../codegen ; cargo run > ../src/emoji_variation.rs");
println!();
emit_variation_map();
emit_classify_table();
@@ -19,8 +18,6 @@ fn main() {
}
fn generate_nerdfonts_data() {
let mut symbols: Vec<(String, char)> = vec![];
let url = "https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/glyphnames.json";
let body = reqwest::blocking::get(url).unwrap().text().unwrap();
@@ -28,19 +25,21 @@ fn generate_nerdfonts_data() {
struct Glyph{
#[serde(rename="char")]
glyph_text: char,
#[allow(unused)]
code: String,
}
#[derive(Deserialize)]
struct Glyphnames {
#[serde(rename="METADATA")]
#[allow(unused)]
metadata: Value,
#[serde(flatten)]
glyphs: HashMap<String, Glyph>,
}
let parsed: Glyphnames = serde_json::from_str(&body).unwrap();
symbols = parsed.glyphs.into_iter().map(|(name, g)| (name.replace("-", "_"), g.glyph_text)).collect();
let mut symbols: Vec<(String, char)> = parsed.glyphs.into_iter().map(|(name, g)| (name.replace("-", "_"), g.glyph_text)).collect();
symbols.sort_by(|(a, _), (b, _)| human_sort::compare(a, b));
let mut f = std::fs::File::create("../src/nerdfonts_data.rs").unwrap();
@@ -116,7 +115,7 @@ fn emit_variation_map() {
println!("use crate::emoji::Presentation;");
println!();
println!(
"pub static VARIATION_MAP: phf::Map<&'static str, (Presentation, Presentation)> = \n{};\n",
"pub const VARIATION_MAP: phf::Map<&'static str, (Presentation, Presentation)> = \n{};\n",
map.build(),
);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,9 +1,9 @@
//! This file was generated by running:
//! cd ../codegen ; cargo run > ../emoji_variation.rs
//! cd ../codegen ; cargo run > ../src/emoji_variation.rs
use crate::emoji::Presentation;
pub static VARIATION_MAP: phf::Map<&'static str, (Presentation, Presentation)> = ::phf::Map {
pub const VARIATION_MAP: phf::Map<&'static str, (Presentation, Presentation)> = ::phf::Map {
key: 12913932095322966823,
disps: &[
(0, 226),
@@ -3064,7 +3064,7 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Combining,
WcWidth::Combining,
WcWidth::Combining,
WcWidth::Combining,
@@ -4180,7 +4180,7 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::Unassigned,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Combining,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
@@ -4655,7 +4655,7 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::Combining,
WcWidth::Combining,
WcWidth::Combining,
WcWidth::Unassigned,
WcWidth::Combining,
WcWidth::Unassigned,
WcWidth::One,
WcWidth::One,
@@ -7855,8 +7855,8 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
@@ -7904,7 +7904,7 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::One,
WcWidth::Combining,
WcWidth::Combining,
WcWidth::Combining,
@@ -8170,8 +8170,8 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
@@ -10120,9 +10120,9 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
@@ -10641,14 +10641,14 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::One,
WcWidth::One,
WcWidth::One,
@@ -10731,12 +10731,12 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::One,
WcWidth::One,
WcWidth::One,
@@ -13149,10 +13149,10 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
@@ -13637,6 +13637,8 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
@@ -13646,9 +13648,7 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
@@ -20769,70 +20769,70 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
WcWidth::Two,
@@ -43820,9 +43820,9 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::One,
@@ -43835,9 +43835,9 @@ pub const WCWIDTH_TABLE: WcLookupTable = WcLookupTable {
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::One,
WcWidth::One,
WcWidth::One,
WcWidth::Unassigned,
WcWidth::Unassigned,
WcWidth::Unassigned,
+7
View File
@@ -0,0 +1,7 @@
pub mod emoji;
pub mod emoji_presentation;
pub mod emoji_variation;
pub mod nerdfonts;
mod nerdfonts_data;
pub mod white_space;
pub mod widechar_width;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.