#133 cleanup + terminalstate-level reverse video mode
This commit is contained in:
1 parent
ce9d166733
commit
d100dded23
4 files changed
+36
-73
No files matched your search
@@ -74,6 +74,7 @@ pub fn terminal_get_lines(
|
||||
term: &mut Terminal,
|
||||
lines: Range<StableRowIndex>,
|
||||
) -> (StableRowIndex, Vec<Line>) {
|
||||
let reverse = term.get_reverse_video();
|
||||
let screen = term.screen_mut();
|
||||
let phys_range = screen.stable_range(&lines);
|
||||
(
|
||||
@@ -84,8 +85,9 @@ pub fn terminal_get_lines(
|
||||
.skip(phys_range.start)
|
||||
.take(phys_range.end - phys_range.start)
|
||||
.map(|line| {
|
||||
let cloned = line.clone();
|
||||
let mut cloned = line.clone();
|
||||
line.clear_dirty();
|
||||
cloned.set_reverse(reverse);
|
||||
cloned
|
||||
})
|
||||
.collect(),
|
||||
|
||||
+5
-19
@@ -32,10 +32,6 @@ 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
|
||||
@@ -76,7 +72,6 @@ impl Screen {
|
||||
physical_rows,
|
||||
physical_cols,
|
||||
stable_row_index_offset: 0,
|
||||
reverse_video_mode: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,8 +212,7 @@ 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_reverse(0, self.reverse_video_mode));
|
||||
self.lines.push_back(Line::with_width(0));
|
||||
}
|
||||
|
||||
let new_cursor_y;
|
||||
@@ -239,8 +233,7 @@ 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_reverse(0, self.reverse_video_mode));
|
||||
self.lines.push_back(Line::with_width(0));
|
||||
}
|
||||
} else {
|
||||
// Compute the new cursor location; this is logically the inverse
|
||||
@@ -586,15 +579,11 @@ 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_reverse(0, self.reverse_video_mode));
|
||||
self.lines.push_back(Line::with_width(0));
|
||||
}
|
||||
} else {
|
||||
for _ in 0..to_add {
|
||||
self.lines.insert(
|
||||
phys_scroll.end,
|
||||
Line::with_width_reverse(0, self.reverse_video_mode),
|
||||
);
|
||||
self.lines.insert(phys_scroll.end, Line::with_width(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -637,10 +626,7 @@ impl Screen {
|
||||
}
|
||||
|
||||
for _ in 0..num_rows {
|
||||
self.lines.insert(
|
||||
phys_scroll.start,
|
||||
Line::with_width_reverse(0, self.reverse_video_mode),
|
||||
);
|
||||
self.lines.insert(phys_scroll.start, Line::with_width(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-15
@@ -104,7 +104,7 @@ impl TabStop {
|
||||
// If we want to exactly match VT100/xterm behavior, then
|
||||
// we cannot honor ClearCharacterTabStopsAtActiveLine.
|
||||
TabulationClear::ClearAllCharacterTabStops => {
|
||||
// | TabulationClear::ClearCharacterTabStopsAtActiveLine => {
|
||||
// | TabulationClear::ClearCharacterTabStopsAtActiveLine
|
||||
for t in &mut self.tabs {
|
||||
*t = false;
|
||||
}
|
||||
@@ -250,6 +250,9 @@ pub struct TerminalState {
|
||||
/// Reverse Wraparound Mode
|
||||
reverse_wraparound_mode: bool,
|
||||
|
||||
/// Reverse video mode
|
||||
reverse_video_mode: bool,
|
||||
|
||||
/// https://vt100.net/docs/vt510-rm/DECOM.html
|
||||
/// When OriginMode is enabled, cursor is constrained to the
|
||||
/// scroll region and its position is relative to the scroll
|
||||
@@ -487,6 +490,7 @@ impl TerminalState {
|
||||
// a dec terminal is false, because it is more useful this way.
|
||||
dec_auto_wrap: true,
|
||||
reverse_wraparound_mode: false,
|
||||
reverse_video_mode: false,
|
||||
dec_origin_mode: false,
|
||||
insert: false,
|
||||
application_cursor_keys: false,
|
||||
@@ -1863,13 +1867,13 @@ 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();
|
||||
self.screen.saved_cursor().take();
|
||||
|
||||
self.reverse_wraparound_mode = false;
|
||||
self.reverse_video_mode = false;
|
||||
}
|
||||
Device::RequestPrimaryDeviceAttributes => {
|
||||
let mut ident = "\x1b[?65".to_string(); // Vt500
|
||||
@@ -2121,23 +2125,13 @@ 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);
|
||||
line.set_reverse(true);
|
||||
}
|
||||
self.reverse_video_mode = true;
|
||||
}
|
||||
|
||||
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);
|
||||
line.set_reverse(false);
|
||||
}
|
||||
self.reverse_video_mode = false;
|
||||
}
|
||||
|
||||
Mode::SetDecPrivateMode(DecPrivateMode::Code(DecPrivateModeCode::Select132Columns))
|
||||
@@ -3178,6 +3172,11 @@ impl TerminalState {
|
||||
|
||||
Ok(zones)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_reverse_video(&self) -> bool {
|
||||
self.reverse_video_mode
|
||||
}
|
||||
}
|
||||
|
||||
/// A helper struct for implementing `vtparse::VTActor` while compartmentalizing
|
||||
@@ -3638,7 +3637,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.reverse_video_mode = false;
|
||||
self.dec_origin_mode = false;
|
||||
self.use_private_color_registers_for_each_graphic = false;
|
||||
self.color_map = default_color_map();
|
||||
|
||||
+14
-38
@@ -68,16 +68,6 @@ 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();
|
||||
|
||||
@@ -129,13 +119,6 @@ impl Line {
|
||||
.map(|chunk| {
|
||||
let mut line = Line {
|
||||
cells: chunk.to_vec(),
|
||||
// AZL TODO:
|
||||
//
|
||||
// How to "| self.bits.LineBits::REVERSE"
|
||||
// here?
|
||||
//
|
||||
// The wrapped line pieces should also be
|
||||
// reversed.
|
||||
bits: LineBits::DIRTY,
|
||||
};
|
||||
if line.cells.len() == width {
|
||||
@@ -181,18 +164,14 @@ impl Line {
|
||||
/// colors reversed.
|
||||
#[inline]
|
||||
pub fn is_reverse(&self) -> bool {
|
||||
(self.bits & LineBits::REVERSE) == LineBits::REVERSE
|
||||
self.bits.contains(LineBits::REVERSE)
|
||||
}
|
||||
|
||||
/// Force the reverse bit set. This also implicitly sets dirty.
|
||||
#[inline]
|
||||
pub fn set_reverse(&mut self, reverse: bool) {
|
||||
if reverse {
|
||||
self.bits |= LineBits::REVERSE;
|
||||
} else {
|
||||
self.bits &= !LineBits::REVERSE;
|
||||
}
|
||||
self.bits |= LineBits::DIRTY;
|
||||
self.bits.set(LineBits::REVERSE, reverse);
|
||||
self.bits.insert(LineBits::DIRTY);
|
||||
}
|
||||
|
||||
/// Check whether the line is single-width.
|
||||
@@ -209,8 +188,8 @@ impl Line {
|
||||
/// double-height-(top/bottom) and dirty.
|
||||
#[inline]
|
||||
pub fn set_single_width(&mut self) {
|
||||
self.bits &= !LineBits::DOUBLE_WIDTH_HEIGHT_MASK;
|
||||
self.bits |= LineBits::DIRTY;
|
||||
self.bits.remove(LineBits::DOUBLE_WIDTH_HEIGHT_MASK);
|
||||
self.bits.insert(LineBits::DIRTY);
|
||||
}
|
||||
|
||||
/// Check whether the line is double-width and not double-height.
|
||||
@@ -223,10 +202,9 @@ impl Line {
|
||||
/// double-height-(top/bottom) and dirty.
|
||||
#[inline]
|
||||
pub fn set_double_width(&mut self) {
|
||||
self.bits |= LineBits::DOUBLE_WIDTH;
|
||||
self.bits &= !LineBits::DOUBLE_HEIGHT_TOP;
|
||||
self.bits &= !LineBits::DOUBLE_HEIGHT_BOTTOM;
|
||||
self.bits |= LineBits::DIRTY;
|
||||
self.bits
|
||||
.remove(LineBits::DOUBLE_HEIGHT_TOP | LineBits::DOUBLE_HEIGHT_BOTTOM);
|
||||
self.bits.insert(LineBits::DOUBLE_WIDTH | LineBits::DIRTY);
|
||||
}
|
||||
|
||||
/// Check whether the line is double-height-top.
|
||||
@@ -240,10 +218,9 @@ impl Line {
|
||||
/// double-width and dirty.
|
||||
#[inline]
|
||||
pub fn set_double_height_top(&mut self) {
|
||||
self.bits |= LineBits::DOUBLE_WIDTH;
|
||||
self.bits |= LineBits::DOUBLE_HEIGHT_TOP;
|
||||
self.bits &= !LineBits::DOUBLE_HEIGHT_BOTTOM;
|
||||
self.bits |= LineBits::DIRTY;
|
||||
self.bits.remove(LineBits::DOUBLE_HEIGHT_BOTTOM);
|
||||
self.bits
|
||||
.insert(LineBits::DOUBLE_WIDTH | LineBits::DOUBLE_HEIGHT_TOP | LineBits::DIRTY);
|
||||
}
|
||||
|
||||
/// Check whether the line is double-height-bottom.
|
||||
@@ -257,10 +234,9 @@ impl Line {
|
||||
/// double-width and dirty.
|
||||
#[inline]
|
||||
pub fn set_double_height_bottom(&mut self) {
|
||||
self.bits |= LineBits::DOUBLE_WIDTH;
|
||||
self.bits &= !LineBits::DOUBLE_HEIGHT_TOP;
|
||||
self.bits |= LineBits::DOUBLE_HEIGHT_BOTTOM;
|
||||
self.bits |= LineBits::DIRTY;
|
||||
self.bits.remove(LineBits::DOUBLE_HEIGHT_TOP);
|
||||
self.bits
|
||||
.insert(LineBits::DOUBLE_WIDTH | LineBits::DOUBLE_HEIGHT_BOTTOM | LineBits::DIRTY);
|
||||
}
|
||||
|
||||
/// If we have any cells with an implicit hyperlink, remove the hyperlink
|
||||
|
||||
Reference in new issue
Block a user