Skip to content

Commit

Permalink
#133 cleanup, rapid blinking text
Browse files Browse the repository at this point in the history
  • Loading branch information
Autumn Lamonte authored and wez committed Jul 25, 2021
1 parent d8cacee commit 70544b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
31 changes: 16 additions & 15 deletions termwiz/src/surface/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ bitflags! {
/// as double-height bottom-half
const DOUBLE_HEIGHT_BOTTOM = 1<<7;

const DOUBLE_WIDTH_HEIGHT_MASK =
Self::DOUBLE_WIDTH.bits |
Self::DOUBLE_HEIGHT_TOP.bits |
Self::DOUBLE_HEIGHT_BOTTOM.bits;

}
}

Expand Down Expand Up @@ -193,27 +198,25 @@ impl Line {
/// 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)
(self.bits
& (LineBits::DOUBLE_WIDTH
| LineBits::DOUBLE_HEIGHT_TOP
| LineBits::DOUBLE_HEIGHT_BOTTOM))
== LineBits::NONE
}

/// 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::DOUBLE_WIDTH_HEIGHT_MASK;
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)
(self.bits & LineBits::DOUBLE_WIDTH_HEIGHT_MASK) == LineBits::DOUBLE_WIDTH
}

/// Force double-width. This also implicitly sets
Expand All @@ -229,9 +232,8 @@ impl Line {
/// 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)
(self.bits & LineBits::DOUBLE_WIDTH_HEIGHT_MASK)
== LineBits::DOUBLE_WIDTH | LineBits::DOUBLE_HEIGHT_TOP
}

/// Force double-height top-half. This also implicitly sets
Expand All @@ -247,9 +249,8 @@ impl Line {
/// 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)
(self.bits & LineBits::DOUBLE_WIDTH_HEIGHT_MASK)
== LineBits::DOUBLE_WIDTH | LineBits::DOUBLE_HEIGHT_BOTTOM
}

/// Force double-height bottom-half. This also implicitly sets
Expand Down
27 changes: 14 additions & 13 deletions wezterm-gui/src/termwindow/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ impl super::TermWindow {
Some(params.config.inactive_pane_hsb)
};

// Hang onto time to see if blinking text should not be seen.
let uptime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let milli_uptime = uptime.as_secs() as u128 * 1000 + uptime.subsec_millis() as u128;

// Clear the cells to basic blanks to avoid leaving artifacts behind.
// The easiest reproduction for the artifacts is to maximize the window and
// open a vim split horizontally. Backgrounding vim would leave
Expand Down Expand Up @@ -745,27 +749,24 @@ impl super::TermWindow {
std::mem::swap(&mut fg, &mut bg);
bg_default = false;
}
// Check for blink, and if this is the "not-blink"

// TODO: maintain/update last_text_blink_paint here
// Check for blink, and if this is the "not-visible"
// part of blinking then set fg = bg. This is a cheap
// means of getting it done without impacting other
// features.
if attrs.blink() != Blink::None
&& (self.config.text_blink_rate != 0
|| self.config.text_blink_rate_rapid != 0)
let blink_rate = match attrs.blink() {
Blink::None => 0,
Blink::Slow => params.config.text_blink_rate,
Blink::Rapid => params.config.text_blink_rate_rapid,
};
if blink_rate != 0
&& (self.config.text_blink_rate != 0 || self.config.text_blink_rate_rapid != 0)
{
let blink_rate = match attrs.blink() {
Blink::Rapid => params.config.text_blink_rate_rapid,
_ => params.config.text_blink_rate,
};
let uptime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let milli_uptime =
uptime.as_secs() as u128 * 1000 + uptime.subsec_millis() as u128;
let ticks = milli_uptime / blink_rate as u128;
if (ticks & 1) == 0 {
fg = bg;
}

// TODO: maintain/update last_text_blink_paint here
}

(fg, bg, bg_default)
Expand Down

0 comments on commit 70544b7

Please sign in to comment.