Skip to content

Commit

Permalink
#133 blinking text 50%
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 c19f330 commit d8cacee
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
26 changes: 26 additions & 0 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,24 @@ pub struct Config {
#[serde(default)]
pub default_cursor_style: DefaultCursorStyle,

/// Specifies how often blinking text (normal speed) transitions
/// between visible and invisible, expressed in milliseconds.
/// Setting this to 0 disables slow text blinking. Note that this
/// value is approximate due to the way that the system event loop
/// schedulers manage timers; non-zero values will be at least the
/// interval specified with some degree of slop.
#[serde(default = "default_text_blink_rate")]
pub text_blink_rate: u64,

/// Specifies how often blinking text (rapid speed) transitions
/// between visible and invisible, expressed in milliseconds.
/// Setting this to 0 disables rapid text blinking. Note that this
/// value is approximate due to the way that the system event loop
/// schedulers manage timers; non-zero values will be at least the
/// interval specified with some degree of slop.
#[serde(default = "default_text_blink_rate_rapid")]
pub text_blink_rate_rapid: u64,

/// If non-zero, specifies the period (in seconds) at which various
/// statistics are logged. Note that there is a minimum period of
/// 10 seconds.
Expand Down Expand Up @@ -1742,6 +1760,14 @@ fn default_cursor_blink_rate() -> u64 {
800
}

fn default_text_blink_rate() -> u64 {
500
}

fn default_text_blink_rate_rapid() -> u64 {
250
}

fn default_swap_backspace_and_delete() -> bool {
// cfg!(target_os = "macos")
// See: https://github.com/wez/wezterm/issues/88
Expand Down
4 changes: 4 additions & 0 deletions wezterm-gui/src/termwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ pub struct TermWindow {

next_blink_paint: RefCell<Instant>,
last_status_call: Instant,
last_text_blink_paint: Instant,
last_text_blink_paint_rapid: Instant,

palette: Option<ColorPalette>,

Expand Down Expand Up @@ -482,6 +484,8 @@ impl TermWindow {
)),
next_blink_paint: RefCell::new(Instant::now()),
last_status_call: Instant::now(),
last_text_blink_paint: Instant::now(),
last_text_blink_paint_rapid: Instant::now(),
event_states: HashMap::new(),
has_animation: RefCell::new(None),
scheduled_animation: RefCell::new(None),
Expand Down
26 changes: 24 additions & 2 deletions wezterm-gui/src/termwindow/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use mux::tab::{PositionedPane, PositionedSplit, SplitDirection};
use smol::Timer;
use std::ops::Range;
use std::rc::Rc;
use std::time::Duration;
use std::time::Instant;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use termwiz::cell::Blink;
use termwiz::cellcluster::CellCluster;
use termwiz::surface::{CursorShape, CursorVisibility};
use wezterm_font::units::PixelLength;
Expand Down Expand Up @@ -745,6 +745,28 @@ impl super::TermWindow {
std::mem::swap(&mut fg, &mut bg);
bg_default = false;
}
// Check for blink, and if this is the "not-blink"
// 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::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 d8cacee

Please sign in to comment.