diff --git a/.gitignore b/.gitignore index eb713f8ad..79ab1de61 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/Cargo.lock b/Cargo.lock index ade14b790..a41f89573 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 63e4f0879..767d52908 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/termwiz/Cargo.toml b/termwiz/Cargo.toml index c3ea45f02..7a8d94d47 100644 --- a/termwiz/Cargo.toml +++ b/termwiz/Cargo.toml @@ -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 diff --git a/termwiz/codegen/Cargo.toml b/termwiz/codegen/Cargo.toml deleted file mode 100644 index c2bb2e30e..000000000 --- a/termwiz/codegen/Cargo.toml +++ /dev/null @@ -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 - diff --git a/termwiz/src/cell.rs b/termwiz/src/cell.rs index bbe5fc382..630fe618d 100644 --- a/termwiz/src/cell.rs +++ b/termwiz/src/cell.rs @@ -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 diff --git a/termwiz/src/cellcluster.rs b/termwiz/src/cellcluster.rs index ddc102a9c..8edcbd26b 100644 --- a/termwiz/src/cellcluster.rs +++ b/termwiz/src/cellcluster.rs @@ -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` is produced by walking through the Cells in diff --git a/termwiz/src/lib.rs b/termwiz/src/lib.rs index 0f92ec9d8..17bcb72e2 100644 --- a/termwiz/src/lib.rs +++ b/termwiz/src/lib.rs @@ -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; diff --git a/termwiz/src/surface/line/cellref.rs b/termwiz/src/surface/line/cellref.rs index d6e86b155..097a565de 100644 --- a/termwiz/src/surface/line/cellref.rs +++ b/termwiz/src/surface/line/cellref.rs @@ -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> { diff --git a/wezterm-char-props/Cargo.toml b/wezterm-char-props/Cargo.toml new file mode 100644 index 000000000..c456544fd --- /dev/null +++ b/wezterm-char-props/Cargo.toml @@ -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 + diff --git a/termwiz/benches/wcwidth.rs b/wezterm-char-props/benches/wcwidth.rs similarity index 100% rename from termwiz/benches/wcwidth.rs rename to wezterm-char-props/benches/wcwidth.rs diff --git a/wezterm-char-props/codegen/Cargo.toml b/wezterm-char-props/codegen/Cargo.toml new file mode 100644 index 000000000..d57da3639 --- /dev/null +++ b/wezterm-char-props/codegen/Cargo.toml @@ -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" + diff --git a/termwiz/codegen/src/main.rs b/wezterm-char-props/codegen/src/main.rs similarity index 91% rename from termwiz/codegen/src/main.rs rename to wezterm-char-props/codegen/src/main.rs index 48e61f4c8..9a01753b9 100644 --- a/termwiz/codegen/src/main.rs +++ b/wezterm-char-props/codegen/src/main.rs @@ -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, } 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(), ); } diff --git a/termwiz/codegen/src/nerdfonts.rs b/wezterm-char-props/codegen/src/nerdfonts.rs similarity index 100% rename from termwiz/codegen/src/nerdfonts.rs rename to wezterm-char-props/codegen/src/nerdfonts.rs diff --git a/termwiz/data/emoji-data.txt b/wezterm-char-props/data/emoji-data.txt similarity index 100% rename from termwiz/data/emoji-data.txt rename to wezterm-char-props/data/emoji-data.txt diff --git a/termwiz/data/emoji-variation-sequences.txt b/wezterm-char-props/data/emoji-variation-sequences.txt similarity index 100% rename from termwiz/data/emoji-variation-sequences.txt rename to wezterm-char-props/data/emoji-variation-sequences.txt diff --git a/termwiz/src/emoji.rs b/wezterm-char-props/src/emoji.rs similarity index 100% rename from termwiz/src/emoji.rs rename to wezterm-char-props/src/emoji.rs diff --git a/termwiz/src/emoji_presentation.rs b/wezterm-char-props/src/emoji_presentation.rs similarity index 100% rename from termwiz/src/emoji_presentation.rs rename to wezterm-char-props/src/emoji_presentation.rs diff --git a/termwiz/src/emoji_variation.rs b/wezterm-char-props/src/emoji_variation.rs similarity index 99% rename from termwiz/src/emoji_variation.rs rename to wezterm-char-props/src/emoji_variation.rs index d395d4054..f6ef3da4d 100644 --- a/termwiz/src/emoji_variation.rs +++ b/wezterm-char-props/src/emoji_variation.rs @@ -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, diff --git a/wezterm-char-props/src/lib.rs b/wezterm-char-props/src/lib.rs new file mode 100644 index 000000000..42c794120 --- /dev/null +++ b/wezterm-char-props/src/lib.rs @@ -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; diff --git a/termwiz/src/nerdfonts.rs b/wezterm-char-props/src/nerdfonts.rs similarity index 100% rename from termwiz/src/nerdfonts.rs rename to wezterm-char-props/src/nerdfonts.rs diff --git a/termwiz/src/nerdfonts_data.rs b/wezterm-char-props/src/nerdfonts_data.rs similarity index 100% rename from termwiz/src/nerdfonts_data.rs rename to wezterm-char-props/src/nerdfonts_data.rs diff --git a/termwiz/src/white_space.rs b/wezterm-char-props/src/white_space.rs similarity index 100% rename from termwiz/src/white_space.rs rename to wezterm-char-props/src/white_space.rs diff --git a/termwiz/src/widechar_width.rs b/wezterm-char-props/src/widechar_width.rs similarity index 100% rename from termwiz/src/widechar_width.rs rename to wezterm-char-props/src/widechar_width.rs