Fix bugs
This commit is contained in:
parent
7dd3d2a9e8
commit
6fd87b899f
55
src/tile.rs
55
src/tile.rs
|
@ -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,36 +262,34 @@ 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 {
|
counter += 1;
|
||||||
counter += 1;
|
|
||||||
|
|
||||||
// TODO fix utf8
|
// TODO fix utf8
|
||||||
if self.stdout.len() <= counter + cursor
|
if self.stdout.len() <= counter + cursor
|
||||||
|| &self.stdout[cursor + counter..cursor + counter + 1] == "\n"
|
|| &self.stdout[cursor + counter..cursor + counter + 1] == "\n"
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stdout
|
|
||||||
.replace_range((cursor - 2)..(cursor + counter), "");
|
|
||||||
self.len -= 2 + counter;
|
|
||||||
self.cursor = None;
|
|
||||||
self.column_number = 0;
|
|
||||||
self.counting = true;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
|
self.stdout
|
||||||
|
.replace_range((cursor - 2)..(cursor + counter), "");
|
||||||
|
self.len -= 2 + counter;
|
||||||
|
self.cursor = None;
|
||||||
|
self.column_number = 0;
|
||||||
|
self.counting = true;
|
||||||
|
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("")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue