mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-03 01:50:12 +00:00
fix(preview): add a post-processing step to clean out ansi text from non-displayable characters (#509)
This commit is contained in:
parent
cfe49ce81c
commit
1741a15e52
@ -12,7 +12,10 @@ use tracing::debug;
|
||||
|
||||
use crate::{
|
||||
channels::{entry::Entry, preview::PreviewCommand},
|
||||
utils::command::shell_command,
|
||||
utils::{
|
||||
command::shell_command,
|
||||
strings::{replace_non_printable, ReplaceNonPrintableConfig},
|
||||
},
|
||||
};
|
||||
|
||||
pub mod state;
|
||||
@ -211,7 +214,12 @@ pub fn try_preview(
|
||||
|
||||
let preview: Preview = {
|
||||
if child.status.success() {
|
||||
let content = String::from_utf8_lossy(&child.stdout);
|
||||
let (content, _) = replace_non_printable(
|
||||
&child.stdout,
|
||||
ReplaceNonPrintableConfig::default()
|
||||
.keep_line_feed()
|
||||
.keep_control_characters(),
|
||||
);
|
||||
Preview::new(
|
||||
&entry.name,
|
||||
content.to_string(),
|
||||
@ -219,7 +227,12 @@ pub fn try_preview(
|
||||
u16::try_from(content.lines().count()).unwrap_or(u16::MAX),
|
||||
)
|
||||
} else {
|
||||
let content = String::from_utf8_lossy(&child.stderr);
|
||||
let (content, _) = replace_non_printable(
|
||||
&child.stderr,
|
||||
ReplaceNonPrintableConfig::default()
|
||||
.keep_line_feed()
|
||||
.keep_control_characters(),
|
||||
);
|
||||
Preview::new(
|
||||
&entry.name,
|
||||
content.to_string(),
|
||||
|
@ -210,6 +210,16 @@ impl ReplaceNonPrintableConfig {
|
||||
self.tab_width = tab_width;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn keep_line_feed(&mut self) -> &mut Self {
|
||||
self.replace_line_feed = false;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn keep_control_characters(&mut self) -> &mut Self {
|
||||
self.replace_control_characters = false;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ReplaceNonPrintableConfig {
|
||||
|
Loading…
x
Reference in New Issue
Block a user