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

fonts: add wezterm ls-fonts --text "hello" to explain per-glyph font

```
; ./target/debug/wezterm ls-fonts --text "␉ ␌ ␍ ␊ ␋"
␉    \u{2409}     glyph=885  wezterm.font("Terminus", weight="Bold", stretch="Normal", italic=false)
                             /home/wez/.fonts/terminus-bold.otb, FontDirs
     \u{20}       glyph=2    wezterm.font("Operator Mono SSm Lig", weight="DemiLight", stretch="Normal", italic=false)
                             /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
␌    \u{240c}     glyph=888  wezterm.font("Terminus", weight="Bold", stretch="Normal", italic=false)
                             /home/wez/.fonts/terminus-bold.otb, FontDirs
     \u{20}       glyph=2    wezterm.font("Operator Mono SSm Lig", weight="DemiLight", stretch="Normal", italic=false)
                             /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
␍    \u{240d}     glyph=889  wezterm.font("Terminus", weight="Bold", stretch="Normal", italic=false)
                             /home/wez/.fonts/terminus-bold.otb, FontDirs
     \u{20}       glyph=2    wezterm.font("Operator Mono SSm Lig", weight="DemiLight", stretch="Normal", italic=false)
                             /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
␊    \u{240a}     glyph=886  wezterm.font("Terminus", weight="Bold", stretch="Normal", italic=false)
                             /home/wez/.fonts/terminus-bold.otb, FontDirs
     \u{20}       glyph=2    wezterm.font("Operator Mono SSm Lig", weight="DemiLight", stretch="Normal", italic=false)
                             /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
␋    \u{240b}     glyph=887  wezterm.font("Terminus", weight="Bold", stretch="Normal", italic=false)
                             /home/wez/.fonts/terminus-bold.otb, FontDirs
```
This commit is contained in:
Wez Furlong 2021-06-19 16:54:29 -07:00
parent d317f0f312
commit fdf871c3cb
3 changed files with 36 additions and 0 deletions

View File

@ -43,6 +43,7 @@ As features stabilize some brief notes about them will accumulate here.
* Changed: `COLORTERM=truecolor` is now set in the environment. [#875](https://github.com/wez/wezterm/issues/875)
* New: `wezterm cli spawn --new-window` flag for creating a new window via the CLI [#887](https://github.com/wez/wezterm/issues/887)
* Fixed: closing last pane in a tab via `CloseCurrentPane` could cause the window to close [#890](https://github.com/wez/wezterm/issues/890)
* Improved: `wezterm ls-fonts --list-system` shows all available fonts, `wezterm ls-fonts --text "hello"` explains which fonts are used for each glyph in the supplied text
### 20210502-154244-3f7122cb

View File

@ -114,4 +114,8 @@ pub struct LsFontsCommand {
/// Whether to list all fonts available to the system
#[structopt(long = "list-system")]
pub list_system: bool,
/// Explain which fonts are used to render the supplied text string
#[structopt(long = "text", conflicts_with = "list-system")]
pub text: Option<String>,
}

View File

@ -13,6 +13,8 @@ use std::ffi::OsString;
use std::rc::Rc;
use std::sync::Arc;
use structopt::StructOpt;
use termwiz::cell::CellAttributes;
use termwiz::surface::Line;
use wezterm_client::domain::{ClientDomain, ClientDomainConfig};
use wezterm_gui_subcommands::*;
use wezterm_ssh::*;
@ -419,6 +421,35 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho
let font_config = wezterm_font::FontConfiguration::new(Some(config.clone()))?;
if let Some(text) = &cmd.text {
let line = Line::from_text(text, &CellAttributes::default());
let cell_clusters = line.cluster();
for cluster in cell_clusters {
let style = font_config.match_style(&config, &cluster.attrs);
let font = font_config.resolve_font(style)?;
let handles = font.clone_handles();
let infos = font.shape(&cluster.text, || {}, |_| {}).unwrap();
for info in infos {
let cell_idx = cluster.byte_to_cell_idx(info.cluster as usize);
let cells = &line.cells()[cell_idx..][..info.num_cells as usize];
let text = cells.iter().map(|c| c.str()).collect::<String>();
let parsed = &handles[info.font_idx];
let escaped = format!("{}", text.escape_unicode());
println!(
"{:4} {:12} glyph={:<4} {}\n{:29}{}",
text,
escaped,
info.glyph_pos,
parsed.lua_name(),
"",
parsed.handle.diagnostic_string()
);
}
}
return Ok(());
}
println!("Primary font:");
let default_font = font_config.default_font()?;
println!(