feat(fonts): add JetBrainsMono Nerd Font Mono support and update font configurations (#257)
- Introduced JetBrainsMono Nerd Font Mono as a new font option in the application. - Updated CSS to include font-face definitions for both regular and bold styles. - Modified various components and utility files to set JetBrainsMono Nerd Font Mono as the default terminal font. - Enhanced font handling logic to accommodate legacy font configurations.
This commit is contained in:
1 parent
fe68f79542
commit
fd3b5a8e27
6 files changed
+74
-7
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,8 @@ use font_kit::font::Font;
|
||||
use font_kit::source::SystemSource;
|
||||
use serde::Serialize;
|
||||
|
||||
pub const DEFAULT_TERMINAL_FONT_FAMILY: &str = "\"JetBrains Mono\", \"Cascadia Mono\", \"SF Mono\", Menlo, Monaco, Consolas, \"Liberation Mono\", monospace";
|
||||
pub const DEFAULT_TERMINAL_FONT_FAMILY: &str = "\"JetBrainsMono Nerd Font Mono\", \"JetBrains Mono\", \"Cascadia Mono\", \"SF Mono\", Menlo, Monaco, Consolas, \"Liberation Mono\", monospace";
|
||||
const LEGACY_DEFAULT_TERMINAL_FONT_FAMILY: &str = "\"JetBrains Mono\", \"Cascadia Mono\", \"SF Mono\", Menlo, Monaco, Consolas, \"Liberation Mono\", monospace";
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub const DEFAULT_UI_FONT_FAMILY: &str = "system-ui, -apple-system, BlinkMacSystemFont, \"PingFang SC\", \"Helvetica Neue\", Arial, sans-serif";
|
||||
@@ -15,7 +16,7 @@ pub const DEFAULT_UI_FONT_FAMILY: &str =
|
||||
pub const DEFAULT_UI_FONT_FAMILY: &str =
|
||||
"system-ui, \"Noto Sans SC\", \"Noto Sans CJK SC\", \"Helvetica Neue\", Arial, sans-serif";
|
||||
|
||||
const BUILT_IN_MONOSPACE_FONTS: &[&str] = &["JetBrains Mono"];
|
||||
const BUILT_IN_MONOSPACE_FONTS: &[&str] = &["JetBrainsMono Nerd Font Mono", "JetBrains Mono"];
|
||||
const GENERIC_MONOSPACE_FAMILY: &str = "monospace";
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@@ -52,6 +53,14 @@ pub fn list_system_font_families() -> Vec<String> {
|
||||
}
|
||||
|
||||
pub fn normalize_terminal_font_family(font_family: &str) -> String {
|
||||
if is_default_terminal_font_family(font_family) {
|
||||
return DEFAULT_TERMINAL_FONT_FAMILY.to_string();
|
||||
}
|
||||
|
||||
if is_legacy_default_terminal_font_family(font_family) {
|
||||
return DEFAULT_TERMINAL_FONT_FAMILY.to_string();
|
||||
}
|
||||
|
||||
let source = SystemSource::new();
|
||||
let mut kept = Vec::new();
|
||||
|
||||
@@ -82,6 +91,18 @@ fn is_built_in_monospace_family(family: &str) -> bool {
|
||||
.any(|known| known.eq_ignore_ascii_case(family))
|
||||
}
|
||||
|
||||
fn is_default_terminal_font_family(font_family: &str) -> bool {
|
||||
font_family
|
||||
.trim()
|
||||
.eq_ignore_ascii_case(DEFAULT_TERMINAL_FONT_FAMILY)
|
||||
}
|
||||
|
||||
fn is_legacy_default_terminal_font_family(font_family: &str) -> bool {
|
||||
font_family
|
||||
.trim()
|
||||
.eq_ignore_ascii_case(LEGACY_DEFAULT_TERMINAL_FONT_FAMILY)
|
||||
}
|
||||
|
||||
fn is_generic_monospace_family(family: &str) -> bool {
|
||||
family.eq_ignore_ascii_case(GENERIC_MONOSPACE_FAMILY)
|
||||
}
|
||||
@@ -200,7 +221,10 @@ fn push_unique_font_family(families: &mut Vec<String>, family: String) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{split_font_family_stack, unquote_font_family};
|
||||
use super::{
|
||||
DEFAULT_TERMINAL_FONT_FAMILY, normalize_terminal_font_family, split_font_family_stack,
|
||||
unquote_font_family,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn splits_font_stack_without_splitting_inside_quotes() {
|
||||
@@ -215,4 +239,30 @@ mod tests {
|
||||
assert_eq!(unquote_font_family("\"Cascadia Mono\""), "Cascadia Mono");
|
||||
assert_eq!(unquote_font_family("'JetBrains Mono'"), "JetBrains Mono");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalizes_legacy_default_to_nerd_font_default() {
|
||||
assert_eq!(
|
||||
normalize_terminal_font_family(
|
||||
"\"JetBrains Mono\", \"Cascadia Mono\", \"SF Mono\", Menlo, Monaco, Consolas, \"Liberation Mono\", monospace"
|
||||
),
|
||||
DEFAULT_TERMINAL_FONT_FAMILY
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_current_default_terminal_font_stack() {
|
||||
assert_eq!(
|
||||
normalize_terminal_font_family(DEFAULT_TERMINAL_FONT_FAMILY),
|
||||
DEFAULT_TERMINAL_FONT_FAMILY
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_custom_jetbrains_mono_stack_without_forcing_nerd_font() {
|
||||
assert_eq!(
|
||||
normalize_terminal_font_family("\"JetBrains Mono\", monospace"),
|
||||
"\"JetBrains Mono\", monospace"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ interface FontInfo {
|
||||
}
|
||||
|
||||
const PACKAGE_FONT_INFOS: FontInfo[] = [
|
||||
{ family: "JetBrainsMono Nerd Font Mono", monospace: true },
|
||||
{ family: "JetBrains Mono", monospace: true },
|
||||
{ family: "Noto Sans SC Variable", monospace: false },
|
||||
{ family: "Inter", monospace: false },
|
||||
@@ -78,7 +79,7 @@ const SYSTEM_UI_FONT_OPTIONS = [
|
||||
"monospace",
|
||||
];
|
||||
const UI_FALLBACK_FONT = "Inter";
|
||||
const TERMINAL_FALLBACK_FONT = "JetBrains Mono";
|
||||
const TERMINAL_FALLBACK_FONT = "JetBrainsMono Nerd Font Mono";
|
||||
const GENERIC_FONT_FAMILIES = new Set([
|
||||
"serif",
|
||||
"sans-serif",
|
||||
|
||||
+18
-2
@@ -1,6 +1,22 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
|
||||
@font-face {
|
||||
font-family: "JetBrainsMono Nerd Font Mono";
|
||||
src: url("/fonts/JetBrainsMonoNerdFontMono-Regular.ttf") format("truetype");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "JetBrainsMono Nerd Font Mono";
|
||||
src: url("/fonts/JetBrainsMonoNerdFontMono-Bold.ttf") format("truetype");
|
||||
font-weight: 700;
|
||||
font-style: normal;
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme {
|
||||
@@ -11,8 +27,8 @@
|
||||
system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
|
||||
"Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
|
||||
--font-mono:
|
||||
"JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono",
|
||||
monospace;
|
||||
"JetBrainsMono Nerd Font Mono", "JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Monaco,
|
||||
Consolas, "Liberation Mono", monospace;
|
||||
|
||||
--color-primary: var(--df-primary);
|
||||
--color-primary-hover: var(--df-primary-hover);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { isMacOS, isWindows } from "./platform";
|
||||
|
||||
export const DEFAULT_TERMINAL_FONT_FAMILY =
|
||||
'"JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace';
|
||||
'"JetBrainsMono Nerd Font Mono", "JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace';
|
||||
|
||||
export function getDefaultUiFontFamily() {
|
||||
if (isMacOS) {
|
||||
|
||||
Reference in new issue
Block a user