Fix cursor draw out-of-bounds

This commit is contained in:
mars 2022-10-04 15:56:42 -06:00
parent 9f46f2f32c
commit f106b505a3
1 changed files with 42 additions and 38 deletions

View File

@ -11,7 +11,6 @@ use alacritty_terminal::Term;
use mio_extras::channel::Sender as MioSender;
use softbuffer::GraphicsContext;
use std::borrow::Cow;
use std::collections::HashMap;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::Arc;
use std::thread::JoinHandle;
@ -79,7 +78,7 @@ impl App {
},
..Default::default()
};
alacritty_terminal::tty::setup_env(&term_config);
let term_listener = TermListener::new(sender.clone());
@ -207,55 +206,60 @@ impl App {
}
}
if !missing_chars.is_empty() {
log::debug!("Missing characters: {:?}", missing_chars);
}
let term_row = content.cursor.point.line.0 as usize;
let term_col = content.cursor.point.column.0 as usize;
let mut px_row = term_row * width * self.cell_height + term_col * self.cell_width;
let cursor_color = 0x00ff00ff;
if (term_row + 1) * self.cell_height < height && (term_col + 1) * self.cell_width < width {
let mut px_row = term_row * width * self.cell_height + term_col * self.cell_width;
use alacritty_terminal::ansi::CursorShape;
match content.cursor.shape {
CursorShape::Block => {
for _y in 0..self.cell_height {
let cursor_color = 0x00ff00ff;
use alacritty_terminal::ansi::CursorShape;
match content.cursor.shape {
CursorShape::Block => {
for _y in 0..self.cell_height {
for x in 0..self.cell_width {
buffer[px_row + x as usize] = cursor_color;
}
px_row += width;
}
}
CursorShape::Beam => {
for _y in 0..self.cell_height {
buffer[px_row] = cursor_color;
px_row += width;
}
}
CursorShape::Underline => {
px_row += (self.cell_height - 1) * width;
for x in 0..self.cell_width {
buffer[px_row + x as usize] = cursor_color;
}
}
CursorShape::HollowBlock => {
for x in 0..self.cell_width {
buffer[px_row + x as usize] = cursor_color;
}
px_row += width;
}
}
CursorShape::Beam => {
for _y in 0..self.cell_height {
buffer[px_row] = cursor_color;
px_row += width;
}
}
CursorShape::Underline => {
px_row += (self.cell_height - 1) * width;
for x in 0..self.cell_width {
buffer[px_row + x as usize] = cursor_color;
}
}
CursorShape::HollowBlock => {
for x in 0..self.cell_width {
buffer[px_row + x as usize] = cursor_color;
}
for _y in 0..(self.cell_height - 1) {
buffer[px_row] = cursor_color;
buffer[px_row + self.cell_width - 1] = cursor_color;
px_row += width;
}
for y in 0..(self.cell_height - 1) {
buffer[px_row] = cursor_color;
buffer[px_row + self.cell_width - 1] = cursor_color;
px_row += width;
}
for x in 0..self.cell_width {
buffer[px_row + x as usize] = cursor_color;
for x in 0..self.cell_width {
buffer[px_row + x as usize] = cursor_color;
}
}
CursorShape::Hidden => {}
}
CursorShape::Hidden => {}
}
log::debug!("Missing characters: {:?}", missing_chars);
self.graphics
.set_buffer(&buffer, width as u16, height as u16);
}