fix: clear console line

This commit is contained in:
iff 2025-04-09 18:54:25 +02:00
parent 005a3b6661
commit 10d20338e5

View file

@ -21,6 +21,13 @@ fn fill(str: &str) -> Option<String> {
} }
} }
fn clear_format(str: &str) -> String {
let width = termwidth();
let whitespace = " ".repeat(width);
let filled = textwrap_fill(str, width);
format!("\r{}\r{}", whitespace, filled)
}
use colored::Colorize; use colored::Colorize;
#[derive(PartialEq)] #[derive(PartialEq)]
@ -73,7 +80,7 @@ impl Buffer {
let filled = fill(&buffered); let filled = fill(&buffered);
if let Some(filled) = filled { if let Some(filled) = filled {
self.buf.clear(); self.buf.clear();
let formatted = format!("\r{}", filled); let formatted = clear_format(&filled);
eprint!("{}", formatted); eprint!("{}", formatted);
self.buf self.buf
.push(formatted.split_once("\n").unwrap().1.to_string()); .push(formatted.split_once("\n").unwrap().1.to_string());
@ -149,7 +156,7 @@ impl Buffer {
let filled = fill(&buffered); let filled = fill(&buffered);
if let Some(filled) = filled { if let Some(filled) = filled {
self.buf.clear(); self.buf.clear();
let formatted = format!("\r{}", filled); let formatted = clear_format(&filled);
eprint!("{}", formatted); eprint!("{}", formatted);
self.buf self.buf
.push(formatted.split_once("\n").unwrap().1.to_string()); .push(formatted.split_once("\n").unwrap().1.to_string());