summaryrefslogtreecommitdiffstats
path: root/src/skim.rs
diff options
context:
space:
mode:
authorquentin konieczko <konieczko@gmail.com>2023-03-21 17:24:19 +0100
committerquentin konieczko <konieczko@gmail.com>2023-03-21 17:24:19 +0100
commitcdefd70dbbd8ddfa34caab75efd6a81ed8410321 (patch)
treee01f94b3ab49910a12c731712c2ac97922a463ad /src/skim.rs
parent738caef8ea8f17c6201b118ad16591a689f53e98 (diff)
use skim ansi parser to print ansi formated line
Diffstat (limited to 'src/skim.rs')
-rw-r--r--src/skim.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/skim.rs b/src/skim.rs
index 8e27796..ea7335b 100644
--- a/src/skim.rs
+++ b/src/skim.rs
@@ -96,3 +96,24 @@ fn pick_first_installed<'a>(commands: &'a [&'a str]) -> Option<&'a str> {
}
None
}
+
+/// Print an ANSI escaped with corresponding colors.
+pub fn print_ansi_str(
+ text: &str,
+ term: &Arc<tuikit::term::Term>,
+ col: Option<usize>,
+ row: Option<usize>,
+) -> anyhow::Result<()> {
+ let mut col = match col {
+ Some(col) => col,
+ None => 0,
+ };
+ let row = match row {
+ Some(row) => row,
+ None => 0,
+ };
+ for (chr, attr) in skim::AnsiString::parse(text).iter() {
+ col += term.print_with_attr(row, col, &chr.to_string(), attr)?;
+ }
+ Ok(())
+}