This commit is contained in:
Thomas Forgione 2023-10-22 18:25:04 +02:00
parent 7dd3d2a9e8
commit 6fd87b899f
1 changed files with 31 additions and 24 deletions

View File

@ -254,7 +254,7 @@ impl Tile {
// Check if we're running into \x1b[K // Check if we're running into \x1b[K
clear_line_counter = match (c, clear_line_counter) { clear_line_counter = match (c, clear_line_counter) {
('\x1b', _) => { ('\x1b', _) => {
self.counting = true; self.counting = false;
1 1
} }
('[', 1) => 2, ('[', 1) => 2,
@ -262,8 +262,7 @@ impl Tile {
_ => 0, _ => 0,
}; };
match (clear_line_counter, self.cursor) { if let (3, Some(cursor)) = (clear_line_counter, self.cursor) {
(3, Some(cursor)) => {
// Find the size of the string until the next '\n' or end // Find the size of the string until the next '\n' or end
let mut counter = 0; let mut counter = 0;
loop { loop {
@ -285,13 +284,12 @@ impl Tile {
self.counting = true; self.counting = true;
continue; continue;
} }
_ => (),
}
if c == '\r' { if c == '\r' {
// Set cursor at the right place // Set cursor at the right place
let mut index = self.len; let mut index = self.len;
let mut reverse = self.stdout.chars().rev(); let mut reverse = self.stdout.chars().rev();
self.column_number = 0;
loop { loop {
match reverse.next() { match reverse.next() {
@ -408,6 +406,8 @@ impl Tile {
/// Renders the content of the tile. /// Renders the content of the tile.
pub fn render_content(&self) -> String { pub fn render_content(&self) -> String {
const DELETE_CHAR: char = '-';
let (x, y) = self.inner_position; let (x, y) = self.inner_position;
let (w, h) = self.inner_size; let (w, h) = self.inner_size;
@ -415,6 +415,7 @@ impl Tile {
let mut counting = true; let mut counting = true;
let mut line_index = 0; let mut line_index = 0;
let mut old_current_char_index = 0;
let mut current_char_index = 0; let mut current_char_index = 0;
let scroll = self.scroll as u16; let scroll = self.scroll as u16;
@ -425,17 +426,17 @@ impl Tile {
counting = false; counting = false;
} }
old_current_char_index = current_char_index;
match c { match c {
'\n' => { '\n' => {
line_index += 1; line_index += 1;
let old_current_char_index = current_char_index;
current_char_index = 0; current_char_index = 0;
if line_index >= scroll && line_index <= h + scroll { if line_index >= scroll && line_index <= h + scroll {
if old_current_char_index < w { if old_current_char_index < w {
let mut spaces = String::new(); let mut spaces = String::new();
for _ in old_current_char_index..w { for _ in old_current_char_index..w {
spaces.push(' '); spaces.push(DELETE_CHAR);
} }
buffer.push(spaces); buffer.push(spaces);
} }
@ -475,6 +476,12 @@ impl Tile {
} }
} }
let mut spaces = String::new();
for _ in old_current_char_index..w {
spaces.push(DELETE_CHAR);
}
buffer.push(spaces);
buffer.push(format!("{}", style::Reset)); buffer.push(format!("{}", style::Reset));
buffer.join("") buffer.join("")
} }