Repository: alexpasmantier/television (language: rust)

Issue:
--preview: nerd font glyph support from external previewers: eza --icons
**Problem**
I'm using `tv` as fuzzy folder finder within `ranger-cli`. This works surprisingly well with the current features. But since running `tv dirs --preview "..."` requires a pipe from stdin, the nerd-font icons from eza aren't displayed correctly. I don't know which component exactly introduces this. eza displays nerd-fonts icons correctly, but when piping this to tv with this command, then I get this char in every instance instead of the icon: `␀`
``` bash
fd --type d | tv dirs --preview "eza -a --icons=always --color=always --color-scale --oneline {}"
# same goes for this minimal command
fd --type d | tv dirs --preview "eza --icons=always {}"
 ```

Maybe it's because of the pipe?

tv nerd fonts are active btw and work fine when running tv without piping from stdin.
use_nerd_font_icons = true

television 0.9.2
build: 1.83.0 (2025-01-10)

Tested in kitty and ghostty, both with the same result.

**Feature**
- Support for `--preview` without piping from STDIN
- Support for nerd font glyphs from preview applications lika `eza`.

**Examples**
``` bash
tv dirs --preview "eza -a --icons=always --color=always --color-scale=all --color-scale-mode=gradient --oneline {}"
```
**Additional context**

SIDE NOTE: This is where I use this function:
ranger-cli commands.py 

``` python
class tv_dirs_select(Command):
    def execute(self):
        import subprocess
        from ranger.ext.get_executables import get_executables

        if "tv" not in get_executables():
            self.fm.notify("Could not find tv(television)", bad=True)
            return

        tv = self.fm.execute_command(
            'fd --type d | tv dirs --preview "eza -a --icons=always --color=always --color-scale --oneline {}"',
            universal_newlines=True,
            stdout=subprocess.PIPE,
        )
        stdout, _ = tv.communicate()
        if tv.returncode == 0:
            selected = os.path.abspath(stdout.strip())
            if os.path.isdir(selected):
                self.fm.cd(selected)
            else:
                self.fm.select_file(selected)


```

![Image](https://github.com/user-attachments/assets/c4ac42fb-ef3a-4adc-bfc9-395546726ee2)

BTW, thank you for television! 


Discussion / hints:

Fix patch:
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<char> =
+    '\u{e700}'..='\u{e8ef}';
+const NF_RANGE_SETI: std::ops::RangeInclusive<char> = '\u{e5fa}'..='\u{e6b7}';
+const NF_RANGE_FONT_AWESOME: std::ops::RangeInclusive<char> =
+    '\u{ed00}'..='\u{f2ff}';
+const NF_RANGE_FONT_AWESOME_EXT: std::ops::RangeInclusive<char> =
+    '\u{e200}'..='\u{e2a9}';
+const NF_RANGE_MATERIAL: std::ops::RangeInclusive<char> =
+    '\u{f0001}'..='\u{f1af0}';
+const NF_RANGE_WEATHER: std::ops::RangeInclusive<char> =
+    '\u{e300}'..='\u{e3e3}';
+const NF_RANGE_OCTICONS_1: std::ops::RangeInclusive<char> =
+    '\u{f400}'..='\u{f533}';
+const NF_RANGE_OCTICONS_2: std::ops::RangeInclusive<char> =
+    '\u{2665}'..='\u{26a1}';
+const NF_RANGE_POWERLINE_1: std::ops::RangeInclusive<char> =
+    '\u{e0a0}'..='\u{e0a2}';
+const NF_RANGE_POWERLINE_2: std::ops::RangeInclusive<char> =
+    '\u{e0b0}'..='\u{e0b3}';
+
+const ALL_NF_RANGES: [&std::ops::RangeInclusive<char>; 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);


Test patch: