1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00

#133 Screen.reverse_video_mode + fmt fixes

This commit is contained in:
Autumn Lamonte 2021-06-23 09:48:24 -05:00 committed by Wez Furlong
parent 31aff81884
commit ad30664361
3 changed files with 33 additions and 5 deletions

View File

@ -32,6 +32,10 @@ pub struct Screen {
/// that we're the primary rather than the alternate screen.
allow_scrollback: bool,
/// Whether reverse video mode is enabled. If set, all new lines will
/// be in reverse video.
pub reverse_video_mode: bool,
/// Physical, visible height of the screen (not including scrollback)
pub physical_rows: usize,
/// Physical, visible width of the screen
@ -72,6 +76,7 @@ impl Screen {
physical_rows,
physical_cols,
stable_row_index_offset: 0,
reverse_video_mode: false,
}
}
@ -212,7 +217,8 @@ impl Screen {
// lines than the viewport size, or we resized taller,
// pad us back out to the viewport size
while self.lines.len() < physical_rows {
self.lines.push_back(Line::with_width(0));
self.lines
.push_back(Line::with_width_reverse(0, self.reverse_video_mode));
}
let new_cursor_y;
@ -233,7 +239,8 @@ impl Screen {
physical_rows.saturating_sub(new_cursor_y as usize);
let actual_num_rows_after_cursor = self.lines.len().saturating_sub(cursor_y);
for _ in actual_num_rows_after_cursor..required_num_rows_after_cursor {
self.lines.push_back(Line::with_width(0));
self.lines
.push_back(Line::with_width_reverse(0, self.reverse_video_mode));
}
} else {
// Compute the new cursor location; this is logically the inverse
@ -579,11 +586,15 @@ impl Screen {
if scroll_region.end as usize == self.physical_rows {
// It's cheaper to push() than it is insert() at the end
for _ in 0..to_add {
self.lines.push_back(Line::with_width(0));
self.lines
.push_back(Line::with_width_reverse(0, self.reverse_video_mode));
}
} else {
for _ in 0..to_add {
self.lines.insert(phys_scroll.end, Line::with_width(0));
self.lines.insert(
phys_scroll.end,
Line::with_width_reverse(0, self.reverse_video_mode),
);
}
}
}
@ -626,7 +637,10 @@ impl Screen {
}
for _ in 0..num_rows {
self.lines.insert(phys_scroll.start, Line::with_width(0));
self.lines.insert(
phys_scroll.start,
Line::with_width_reverse(0, self.reverse_video_mode),
);
}
}

View File

@ -1859,6 +1859,7 @@ impl TerminalState {
self.application_keypad = false;
self.top_and_bottom_margins = 0..self.screen().physical_rows as i64;
self.left_and_right_margins = 0..self.screen().physical_cols;
self.screen.reverse_video_mode = false;
self.screen.activate_alt_screen();
self.screen.saved_cursor().take();
self.screen.activate_primary_screen();
@ -2125,6 +2126,7 @@ impl TerminalState {
Mode::SetDecPrivateMode(DecPrivateMode::Code(DecPrivateModeCode::ReverseVideo)) => {
// Turn on reverse video for all of the lines on the
// display.
self.screen.reverse_video_mode = true;
for y in 0..self.screen.physical_rows as i64 {
let line_idx = self.screen.phys_row(VisibleRowIndex::from(y));
let line = self.screen.line_mut(line_idx);
@ -2135,6 +2137,7 @@ impl TerminalState {
Mode::ResetDecPrivateMode(DecPrivateMode::Code(DecPrivateModeCode::ReverseVideo)) => {
// Turn off reverse video for all of the lines on the
// display.
self.screen.reverse_video_mode = false;
for y in 0..self.screen.physical_rows as i64 {
let line_idx = self.screen.phys_row(VisibleRowIndex::from(y));
let line = self.screen.line_mut(line_idx);
@ -3600,6 +3603,7 @@ impl<'a> Performer<'a> {
self.insert = false;
self.dec_auto_wrap = true;
self.reverse_wraparound_mode = false;
self.screen.reverse_video_mode = false;
self.dec_origin_mode = false;
self.use_private_color_registers_for_each_graphic = false;
self.color_map = default_color_map();

View File

@ -50,6 +50,16 @@ impl Line {
Self { bits, cells }
}
pub fn with_width_reverse(width: usize, reverse: bool) -> Self {
let mut cells = Vec::with_capacity(width);
cells.resize(width, Cell::default());
let mut bits = LineBits::DIRTY;
if reverse {
bits |= LineBits::REVERSE;
}
Self { bits, cells }
}
pub fn from_text(s: &str, attrs: &CellAttributes) -> Line {
let mut cells = Vec::new();