From c19f330194120cb4707136f54a47e902c7429c11 Mon Sep 17 00:00:00 2001 From: Autumn Lamonte Date: Fri, 25 Jun 2021 10:34:24 -0500 Subject: [PATCH] #133 parse out double-width/double-height, but do not render --- term/src/terminalstate.rs | 17 ++++++++ termwiz/src/escape/esc.rs | 9 ++++ termwiz/src/surface/line.rs | 85 +++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index f9bf9a203..c2bc3d59e 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -3579,6 +3579,23 @@ impl<'a> Performer<'a> { Esc::Code(EscCode::DecSaveCursorPosition) => self.dec_save_cursor(), Esc::Code(EscCode::DecRestoreCursorPosition) => self.dec_restore_cursor(), + Esc::Code(EscCode::DecDoubleHeightTopHalfLine) => { + let idx = self.screen.phys_row(self.cursor.y); + self.screen.line_mut(idx).set_double_height_top(); + } + Esc::Code(EscCode::DecDoubleHeightBottomHalfLine) => { + let idx = self.screen.phys_row(self.cursor.y); + self.screen.line_mut(idx).set_double_height_bottom(); + } + Esc::Code(EscCode::DecDoubleWidthLine) => { + let idx = self.screen.phys_row(self.cursor.y); + self.screen.line_mut(idx).set_double_width(); + } + Esc::Code(EscCode::DecSingleWidthLine) => { + let idx = self.screen.phys_row(self.cursor.y); + self.screen.line_mut(idx).set_single_width(); + } + Esc::Code(EscCode::DecScreenAlignmentDisplay) => { // This one is just to make vttest happy; // its original purpose was for aligning the CRT. diff --git a/termwiz/src/escape/esc.rs b/termwiz/src/escape/esc.rs index 3d8a943d4..f18d31ed9 100644 --- a/termwiz/src/escape/esc.rs +++ b/termwiz/src/escape/esc.rs @@ -85,6 +85,15 @@ pub enum EscCode { /// https://vt100.net/docs/vt510-rm/DECALN.html DecScreenAlignmentDisplay = esc!('#', '8'), + /// DECDHL - DEC double-height line, top half + DecDoubleHeightTopHalfLine = esc!('#', '3'), + /// DECDHL - DEC double-height line, bottom half + DecDoubleHeightBottomHalfLine = esc!('#', '4'), + /// DECSWL - DEC single-width line + DecSingleWidthLine = esc!('#', '5'), + /// DECDWL - DEC double-width line + DecDoubleWidthLine = esc!('#', '6'), + /// These are typically sent by the terminal when keys are pressed ApplicationModeArrowUpPress = esc!('O', 'A'), ApplicationModeArrowDownPress = esc!('O', 'B'), diff --git a/termwiz/src/surface/line.rs b/termwiz/src/surface/line.rs index 7ae12f70f..9c643236b 100644 --- a/termwiz/src/surface/line.rs +++ b/termwiz/src/surface/line.rs @@ -26,6 +26,19 @@ bitflags! { /// true if this line should be displayed with /// foreground/background colors reversed const REVERSE = 1<<4; + + /// true if this line should be displayed with + /// in double-width + const DOUBLE_WIDTH = 1<<5; + + /// true if this line should be displayed + /// as double-height top-half + const DOUBLE_HEIGHT_TOP = 1<<6; + + /// true if this line should be displayed + /// as double-height bottom-half + const DOUBLE_HEIGHT_BOTTOM = 1<<7; + } } @@ -177,6 +190,78 @@ impl Line { self.bits |= LineBits::DIRTY; } + /// Check whether the line is single-width. + #[inline] + pub fn is_single_width(&self) -> bool { + ((self.bits & LineBits::DOUBLE_WIDTH) != LineBits::DOUBLE_WIDTH) + && ((self.bits & LineBits::DOUBLE_HEIGHT_TOP) != LineBits::DOUBLE_HEIGHT_TOP) + && ((self.bits & LineBits::DOUBLE_HEIGHT_BOTTOM) != LineBits::DOUBLE_HEIGHT_BOTTOM) + } + + /// Force single-width. This also implicitly sets + /// double-height-(top/bottom) and dirty. + #[inline] + pub fn set_single_width(&mut self) { + self.bits &= !LineBits::DOUBLE_WIDTH; + self.bits &= !LineBits::DOUBLE_HEIGHT_TOP; + self.bits &= !LineBits::DOUBLE_HEIGHT_BOTTOM; + self.bits |= LineBits::DIRTY; + } + + /// Check whether the line is double-width and not double-height. + #[inline] + pub fn is_double_width(&self) -> bool { + ((self.bits & LineBits::DOUBLE_WIDTH) == LineBits::DOUBLE_WIDTH) + && ((self.bits & LineBits::DOUBLE_HEIGHT_TOP) != LineBits::DOUBLE_HEIGHT_TOP) + && ((self.bits & LineBits::DOUBLE_HEIGHT_BOTTOM) != LineBits::DOUBLE_HEIGHT_BOTTOM) + } + + /// Force double-width. This also implicitly sets + /// 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; + } + + /// Check whether the line is double-height-top. + #[inline] + pub fn is_double_height_top(&self) -> bool { + ((self.bits & LineBits::DOUBLE_WIDTH) == LineBits::DOUBLE_WIDTH) + && ((self.bits & LineBits::DOUBLE_HEIGHT_TOP) == LineBits::DOUBLE_HEIGHT_TOP) + && ((self.bits & LineBits::DOUBLE_HEIGHT_BOTTOM) != LineBits::DOUBLE_HEIGHT_BOTTOM) + } + + /// Force double-height top-half. This also implicitly sets + /// 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; + } + + /// Check whether the line is double-height-bottom. + #[inline] + pub fn is_double_height_bottom(&self) -> bool { + ((self.bits & LineBits::DOUBLE_WIDTH) == LineBits::DOUBLE_WIDTH) + && ((self.bits & LineBits::DOUBLE_HEIGHT_TOP) != LineBits::DOUBLE_HEIGHT_TOP) + && ((self.bits & LineBits::DOUBLE_HEIGHT_BOTTOM) == LineBits::DOUBLE_HEIGHT_BOTTOM) + } + + /// Force double-height bottom-half. This also implicitly sets + /// 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; + } + /// If we have any cells with an implicit hyperlink, remove the hyperlink /// from the cell attributes but leave the remainder of the attributes alone. pub fn invalidate_implicit_hyperlinks(&mut self) {