mirror of
https://github.com/wez/wezterm.git
synced 2024-11-26 08:25:50 +03:00
ls-fonts: refine output a bit
It now outputs something that you could conceivably put into your config file, although the intent is to show the canonical way to reference the individual fonts that were found, rather than to specify a fully baked list to paste into a config. eg: ``` ; ./target/debug/wezterm ls-fonts Primary font: wezterm.font_with_fallback({ -- /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs {family="Operator Mono SSm Lig", weight="DemiLight"}, -- /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontConfig {family="Operator Mono SSm Lig", weight="DemiLight"}, -- /home/wez/.fonts/MaterialDesignIconsDesktop.ttf, FontDirs "Material Design Icons Desktop", -- /home/wez/.fonts/terminus-bold.otb, FontDirs {family="Terminus", weight="Bold"}, -- /home/wez/.fonts/JetBrainsMono-Regular.ttf, FontDirs "JetBrains Mono", -- /home/wez/.fonts/NotoColorEmoji.ttf, FontDirs "Noto Color Emoji", -- /home/wez/.fonts/MaterialDesignIconsDesktop.ttf, FontConfig "Material Design Icons Desktop", -- /usr/share/fonts/terminus-fonts/ter-u32n.otb, FontConfig "Terminus", -- /home/wez/.fonts/JetBrainsMono-Regular.ttf, FontConfig "JetBrains Mono", -- /home/wez/.fonts/NotoColorEmoji.ttf, FontConfig "Noto Color Emoji", -- <built-in>, BuiltIn "Last Resort High-Efficiency", }) ```
This commit is contained in:
parent
1f6bfd453b
commit
67d8848676
@ -125,6 +125,33 @@ impl ParsedFont {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn lua_fallback(handles: &[Self]) -> String {
|
||||
let mut code = "wezterm.font_with_fallback({\n".to_string();
|
||||
|
||||
for p in handles {
|
||||
code.push_str(&format!(" -- {}\n", p.handle.diagnostic_string()));
|
||||
|
||||
if p.weight == FontWeight::Regular && p.stretch == FontStretch::Normal && !p.italic {
|
||||
code.push_str(&format!(" \"{}\",\n", p.names.family));
|
||||
} else {
|
||||
code.push_str(&format!(" {{family=\"{}\"", p.names.family));
|
||||
if p.weight != FontWeight::Regular {
|
||||
code.push_str(&format!(", weight=\"{}\"", p.weight));
|
||||
}
|
||||
if p.stretch != FontStretch::Normal {
|
||||
code.push_str(&format!(", stretch=\"{}\"", p.stretch));
|
||||
}
|
||||
if p.italic {
|
||||
code.push_str(", italic=true");
|
||||
}
|
||||
code.push_str("},\n")
|
||||
}
|
||||
code.push_str("\n");
|
||||
}
|
||||
code.push_str("})");
|
||||
code
|
||||
}
|
||||
|
||||
pub fn from_face(face: &crate::ftwrap::Face, handle: FontDataHandle) -> anyhow::Result<Self> {
|
||||
let italic = face.italic();
|
||||
let (weight, width) = face.weight_and_width();
|
||||
|
@ -414,6 +414,8 @@ fn maybe_show_configuration_error_window() {
|
||||
}
|
||||
|
||||
pub fn run_ls_fonts(config: config::ConfigHandle, _cmd: &LsFontsCommand) -> anyhow::Result<()> {
|
||||
use wezterm_font::parser::ParsedFont;
|
||||
|
||||
// Disable the normal config error UI window, as we don't have
|
||||
// a fully baked GUI environment running
|
||||
config::assign_error_callback(|err| eprintln!("{}", err));
|
||||
@ -422,11 +424,11 @@ pub fn run_ls_fonts(config: config::ConfigHandle, _cmd: &LsFontsCommand) -> anyh
|
||||
|
||||
println!("Primary font:");
|
||||
let default_font = font_config.default_font()?;
|
||||
for f in default_font.clone_handles() {
|
||||
println!(" {}", f.lua_name());
|
||||
println!(" ({})", f.handle.diagnostic_string());
|
||||
println!();
|
||||
}
|
||||
println!(
|
||||
"{}",
|
||||
ParsedFont::lua_fallback(&default_font.clone_handles())
|
||||
);
|
||||
println!();
|
||||
|
||||
for rule in &config.font_rules {
|
||||
println!();
|
||||
@ -456,11 +458,8 @@ pub fn run_ls_fonts(config: config::ConfigHandle, _cmd: &LsFontsCommand) -> anyh
|
||||
|
||||
println!("{}:", condition);
|
||||
let font = font_config.resolve_font(&rule.font)?;
|
||||
for f in font.clone_handles() {
|
||||
println!(" {}", f.lua_name());
|
||||
println!(" ({})", f.handle.diagnostic_string());
|
||||
println!();
|
||||
}
|
||||
println!("{}", ParsedFont::lua_fallback(&font.clone_handles()));
|
||||
println!();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user