From 6c3bede3ca2473d0a9e9d9bd2bc0b42ea9cadbd6 Mon Sep 17 00:00:00 2001 From: Alex Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Sun, 19 Jan 2025 20:09:10 +0100 Subject: [PATCH] feat(preview): add support for displaying nerd fonts in preview (#286) Fixes #280 --- crates/television-utils/src/strings.rs | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/crates/television-utils/src/strings.rs b/crates/television-utils/src/strings.rs index 3f03222..29b71d1 100644 --- a/crates/television-utils/src/strings.rs +++ b/crates/television-utils/src/strings.rs @@ -167,6 +167,39 @@ const NULL_CHARACTER: char = '\x00'; const UNIT_SEPARATOR_CHARACTER: char = '\u{001F}'; const APPLICATION_PROGRAM_COMMAND_CHARACTER: char = '\u{009F}'; +const NF_RANGE_DEVICONS: std::ops::RangeInclusive = + '\u{e700}'..='\u{e8ef}'; +const NF_RANGE_SETI: std::ops::RangeInclusive = '\u{e5fa}'..='\u{e6b7}'; +const NF_RANGE_FONT_AWESOME: std::ops::RangeInclusive = + '\u{ed00}'..='\u{f2ff}'; +const NF_RANGE_FONT_AWESOME_EXT: std::ops::RangeInclusive = + '\u{e200}'..='\u{e2a9}'; +const NF_RANGE_MATERIAL: std::ops::RangeInclusive = + '\u{f0001}'..='\u{f1af0}'; +const NF_RANGE_WEATHER: std::ops::RangeInclusive = + '\u{e300}'..='\u{e3e3}'; +const NF_RANGE_OCTICONS_1: std::ops::RangeInclusive = + '\u{f400}'..='\u{f533}'; +const NF_RANGE_OCTICONS_2: std::ops::RangeInclusive = + '\u{2665}'..='\u{26a1}'; +const NF_RANGE_POWERLINE_1: std::ops::RangeInclusive = + '\u{e0a0}'..='\u{e0a2}'; +const NF_RANGE_POWERLINE_2: std::ops::RangeInclusive = + '\u{e0b0}'..='\u{e0b3}'; + +const ALL_NF_RANGES: [&std::ops::RangeInclusive; 10] = [ + &NF_RANGE_DEVICONS, + &NF_RANGE_SETI, + &NF_RANGE_FONT_AWESOME, + &NF_RANGE_FONT_AWESOME_EXT, + &NF_RANGE_MATERIAL, + &NF_RANGE_WEATHER, + &NF_RANGE_OCTICONS_1, + &NF_RANGE_OCTICONS_2, + &NF_RANGE_POWERLINE_1, + &NF_RANGE_POWERLINE_2, +]; + pub struct ReplaceNonPrintableConfig { pub replace_tab: bool, pub tab_width: usize, @@ -261,6 +294,10 @@ pub fn replace_non_printable( c if ('\u{4E00}'..='\u{9FFF}').contains(&c) => { output.push(c); } + // Nerd fonts + c if ALL_NF_RANGES.iter().any(|r| r.contains(&c)) => { + output.push(c); + } // Unicode characters above 0x0700 seem unstable with ratatui c if c > '\u{0700}' => { output.push(*NULL_SYMBOL);