Repository: alexpasmantier/television (language: rust)

Issue:
zsh_history breaks
**Description**
When I run Ctrl-R or simply go to the zsh-history channel. it breaks

**Example**
```
$ tWell, this is embarrassing.                                             0 / 0                                                              

television had a problem and crashed. To help us diagnose the problem you can send us a crash report.

We have generated a report file at "/var/folders/ms/vc5jg4yn5mq4lj8t6qk1qs8c0000gn/T/report-d5f9077b-63d7-49bd-9ff5-6eb1dc232701.toml". Submit an issue or email with the subject of "television Crash Report" and include the report as an attachment.

- Homepage: https://github.com/alexpasmantier/television
- Authors: Alexandre Pasmantier <alex.pasmant@gmail.com>

We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.

Thank you kindly!
The application panicked (crashed).
Message:  called `Result::unwrap()` on an `Err` value: Error { kind: InvalidData, message: "stream did not contain valid UTF-8" }
Location: /Users/anirudhgupta/.cargo/registry/src/index.crates.io-6f17d22bba15001f/television-channels-0.0.20/src/channels/cable.rs:121

This is a bug. Consider reporting it at https://github.com/alexpasmantier/television
```
**Expected behavior**
in Version 0.9.0, it was working just fine, as expected.

**Actual behavior**

**Environment**
 - OS: MacOS
 - Rust version: rustup 1.27.1 (1980-01-01), cargo 1.83.0 (5ffbef321 2024-10-29)
 - Project version: 0.9.1
 - [Any other dependency version if needed]

**Additional context**
Please remove `.txt` from the file

[report-d5f9077b-63d7-49bd-9ff5-6eb1dc232701.toml.txt](https://github.com/user-attachments/files/18365879/report-d5f9077b-63d7-49bd-9ff5-6eb1dc232701.toml.txt)





Discussion / hints:
Another bug
When I do `ls | tv`, it shows this. `Ctrl-t` after `ls`, works fine. However the pipe doesnt work. 

![40292](https://github.com/user-attachments/assets/3b8f9301-5254-451e-93e5-163593cde038)


you may export LC_ALL="en_US.UTF-8", which will let zsh save history in UTF-8.
![image](https://github.com/user-attachments/assets/224df0ad-d485-4fc6-96f7-df459ad89a08)
(It works fine on archlinux)
television 0.9.1
target triple: x86_64-unknown-linux-gnu
build: 1.83.0 (2025-01-09)

The first issue is your zsh history not containing valid utf-8. I guess television could just filter out the lines that aren't utf-8 instead of crashing entirely, will add that to the next release.

In the meantime, you could set `LC_ALL="en_US.UTF-8"` as @xsy420 pointed out to make sure zsh produces utf-8.

> Another bug
When I do ls | tv, it shows this. Ctrl-t after ls, works fine. However the pipe doesnt work.

This is just your input containing ansi formatting escape sequences which aren't currently being parsed by tv (I'm working on that as we speak and it'll soon be released).

Fix patch:
diff --git a/crates/television-channels/src/channels/cable.rs b/crates/television-channels/src/channels/cable.rs
index 2f0f36f..8ec848c 100644
--- a/crates/television-channels/src/channels/cable.rs
+++ b/crates/television-channels/src/channels/cable.rs
@@ -117,13 +117,15 @@ async fn load_candidates(command: String, injector: Injector<String>) {
         let reader = BufReader::new(out);
         let mut produced_output = false;
 
+        #[allow(clippy::manual_flatten)]
         for line in reader.lines() {
-            let line = line.unwrap();
-            if !line.trim().is_empty() {
-                let () = injector.push(line, |e, cols| {
-                    cols[0] = e.clone().into();
-                });
-                produced_output = true;
+            if let Ok(l) = line {
+                if !l.trim().is_empty() {
+                    let () = injector.push(l, |e, cols| {
+                        cols[0] = e.clone().into();
+                    });
+                    produced_output = true;
+                }
             }
         }
 


Test patch: