mirror of
https://github.com/wez/wezterm.git
synced 2024-11-10 15:04:32 +03:00
blinking text is now eased between bg and fg color
This commit is contained in:
parent
7b4c3d0397
commit
842e4800b5
@ -1,5 +1,5 @@
|
||||
use crate::background::Gradient;
|
||||
use crate::bell::{AudibleBell, VisualBell};
|
||||
use crate::bell::{AudibleBell, EasingFunction, VisualBell};
|
||||
use crate::color::{ColorSchemeFile, HsbTransform, Palette, TabBarStyle, WindowFrameConfig};
|
||||
use crate::daemon::DaemonOptions;
|
||||
use crate::font::{
|
||||
@ -451,6 +451,10 @@ pub struct Config {
|
||||
/// interval specified with some degree of slop.
|
||||
#[serde(default = "default_text_blink_rate")]
|
||||
pub text_blink_rate: u64,
|
||||
#[serde(default)]
|
||||
pub text_blink_ease_in: EasingFunction,
|
||||
#[serde(default)]
|
||||
pub text_blink_ease_out: EasingFunction,
|
||||
|
||||
/// Specifies how often blinking text (rapid speed) transitions
|
||||
/// between visible and invisible, expressed in milliseconds.
|
||||
@ -460,6 +464,10 @@ pub struct Config {
|
||||
/// interval specified with some degree of slop.
|
||||
#[serde(default = "default_text_blink_rate_rapid")]
|
||||
pub text_blink_rate_rapid: u64,
|
||||
#[serde(default)]
|
||||
pub text_blink_rapid_ease_in: EasingFunction,
|
||||
#[serde(default)]
|
||||
pub text_blink_rapid_ease_out: EasingFunction,
|
||||
|
||||
/// If non-zero, specifies the period (in seconds) at which various
|
||||
/// statistics are logged. Note that there is a minimum period of
|
||||
|
@ -37,6 +37,7 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* [ScrollByPage](config/lua/keyassignment/ScrollByPage.md) now accepts fractional numbers like `0.5` to scroll by half a page at time. Thanks to [@hahuang65](https://github.com/hahuang65)! [#1534](https://github.com/wez/wezterm/pull/1534)
|
||||
* [use_ime](config/lua/config/use_ime.md) now defaults to `true` on all platforms; previously it was not enabled by default on macOS.
|
||||
* [canonicalize_pasted_newlines](config/lua/config/canonicalize_pasted_newlines.md) default has changed to be more compatible for `nano` users, and now provides more control over the text format that is pasted. [#1575](https://github.com/wez/wezterm/issues/1575)
|
||||
* Blinking text is now eased rather than binary-blinked. See [text_blink_ease_in](config/lua/config/text_blink_ease_in.md) and [text_blink_ease_out](config/lua/config/text_blink_ease_out.md), [text_blink_rapid_ease_in](config/lua/config/text_blink_rapid_ease_in.md) and [text_blink_rapid_ease_out](config/lua/config/text_blink_rapid_ease_out.md) for more information.
|
||||
|
||||
#### Updated and Improved
|
||||
|
||||
|
12
docs/config/lua/config/text_blink_ease_in.md
Normal file
12
docs/config/lua/config/text_blink_ease_in.md
Normal file
@ -0,0 +1,12 @@
|
||||
# text_blink_ease_in = "Ease"
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Specifies the *easing function* to use when computing the color
|
||||
for text that has the blinking attribute in the fading-in
|
||||
phase--when the text is fading from the background color to the
|
||||
foreground color.
|
||||
|
||||
See [visual_bell](visual_bell.md) for more information about
|
||||
easing functions.
|
||||
|
13
docs/config/lua/config/text_blink_ease_out.md
Normal file
13
docs/config/lua/config/text_blink_ease_out.md
Normal file
@ -0,0 +1,13 @@
|
||||
# text_blink_ease_out = "Ease"
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Specifies the *easing function* to use when computing the color
|
||||
for text that has the blinking attribute in the fading-out
|
||||
phase--when the text is fading from the foreground color to the
|
||||
background color.
|
||||
|
||||
See [visual_bell](visual_bell.md) for more information about
|
||||
easing functions.
|
||||
|
||||
|
11
docs/config/lua/config/text_blink_rapid_ease_in.md
Normal file
11
docs/config/lua/config/text_blink_rapid_ease_in.md
Normal file
@ -0,0 +1,11 @@
|
||||
# text_blink_rapid_ease_in = "Ease"
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Specifies the *easing function* to use when computing the color
|
||||
for text that has the rapid blinking attribute in the fading-in
|
||||
phase--when the text is fading from the background color to the
|
||||
foreground color.
|
||||
|
||||
See [visual_bell](visual_bell.md) for more information about
|
||||
easing functions.
|
12
docs/config/lua/config/text_blink_rapid_ease_out.md
Normal file
12
docs/config/lua/config/text_blink_rapid_ease_out.md
Normal file
@ -0,0 +1,12 @@
|
||||
# text_blink_rapid_ease_out = "Ease"
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Specifies the *easing function* to use when computing the color
|
||||
for text that has the rapid blinking attribute in the fading-out
|
||||
phase--when the text is fading from the foreground color to the
|
||||
background color.
|
||||
|
||||
See [visual_bell](visual_bell.md) for more information about
|
||||
easing functions.
|
||||
|
@ -13,3 +13,11 @@ return {
|
||||
text_blink_rate = 500
|
||||
}
|
||||
```
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Blinking is no longer a binary blink, but interpolates between invisible and
|
||||
visible text using an easing function. See
|
||||
[text_blink_ease_in](text_blink_ease_in.md) and
|
||||
[text_blink_ease_out](text_blink_ease_out.md) for more information.
|
||||
|
||||
|
@ -14,3 +14,10 @@ return {
|
||||
}
|
||||
```
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Blinking is no longer a binary blink, but interpolates between invisible and
|
||||
visible text using an easing function. See
|
||||
[text_blink_rapid_ease_in](text_blink_rapid_ease_in.md) and
|
||||
[text_blink_rapid_ease_out](text_blink_rapid_ease_out.md) for more information.
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
use super::renderstate::*;
|
||||
use super::utilsprites::RenderMetrics;
|
||||
use crate::cache::LruCache;
|
||||
use crate::colorease::ColorEase;
|
||||
use crate::frontend::front_end;
|
||||
use crate::glium::texture::SrgbTexture2d;
|
||||
use crate::overlay::{
|
||||
@ -333,8 +334,8 @@ pub struct TermWindow {
|
||||
|
||||
next_blink_paint: RefCell<Instant>,
|
||||
last_status_call: Instant,
|
||||
last_text_blink_paint: RefCell<Instant>,
|
||||
last_text_blink_paint_rapid: RefCell<Instant>,
|
||||
blink_state: RefCell<ColorEase>,
|
||||
rapid_blink_state: RefCell<ColorEase>,
|
||||
|
||||
palette: Option<ColorPalette>,
|
||||
|
||||
@ -725,8 +726,20 @@ impl TermWindow {
|
||||
)),
|
||||
next_blink_paint: RefCell::new(Instant::now()),
|
||||
last_status_call: Instant::now(),
|
||||
last_text_blink_paint: RefCell::new(Instant::now()),
|
||||
last_text_blink_paint_rapid: RefCell::new(Instant::now()),
|
||||
blink_state: RefCell::new(ColorEase::new(
|
||||
config.text_blink_rate,
|
||||
config.text_blink_ease_in,
|
||||
config.text_blink_rate,
|
||||
config.text_blink_ease_out,
|
||||
None,
|
||||
)),
|
||||
rapid_blink_state: RefCell::new(ColorEase::new(
|
||||
config.text_blink_rate_rapid,
|
||||
config.text_blink_rapid_ease_in,
|
||||
config.text_blink_rate_rapid,
|
||||
config.text_blink_rapid_ease_out,
|
||||
None,
|
||||
)),
|
||||
event_states: HashMap::new(),
|
||||
has_animation: RefCell::new(None),
|
||||
scheduled_animation: RefCell::new(None),
|
||||
@ -1361,6 +1374,20 @@ impl TermWindow {
|
||||
} else {
|
||||
self.show_tab_bar = config.enable_tab_bar;
|
||||
}
|
||||
*self.blink_state.borrow_mut() = ColorEase::new(
|
||||
config.text_blink_rate,
|
||||
config.text_blink_ease_in,
|
||||
config.text_blink_rate,
|
||||
config.text_blink_ease_out,
|
||||
None,
|
||||
);
|
||||
*self.rapid_blink_state.borrow_mut() = ColorEase::new(
|
||||
config.text_blink_rate_rapid,
|
||||
config.text_blink_rapid_ease_in,
|
||||
config.text_blink_rate_rapid,
|
||||
config.text_blink_rapid_ease_out,
|
||||
None,
|
||||
);
|
||||
|
||||
self.show_scroll_bar = config.enable_scroll_bar;
|
||||
self.shape_cache.borrow_mut().clear();
|
||||
|
@ -30,7 +30,7 @@ use mux::tab::{PositionedPane, PositionedSplit, SplitDirection};
|
||||
use smol::Timer;
|
||||
use std::ops::Range;
|
||||
use std::rc::Rc;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
use std::time::{Duration, Instant};
|
||||
use termwiz::cell::{unicode_column_width, Blink};
|
||||
use termwiz::cellcluster::CellCluster;
|
||||
use termwiz::surface::{CursorShape, CursorVisibility};
|
||||
@ -1578,6 +1578,8 @@ impl super::TermWindow {
|
||||
let bg_color = params.palette.resolve_bg(attrs.background());
|
||||
|
||||
let fg_color = resolve_fg_color_attr(&attrs, attrs.foreground(), ¶ms, style);
|
||||
let fg_color = rgbcolor_to_window_color(fg_color);
|
||||
let bg_color = rgbcolor_to_window_color(bg_color);
|
||||
|
||||
let (fg_color, bg_color, bg_is_default) = {
|
||||
let mut fg = fg_color;
|
||||
@ -1596,49 +1598,48 @@ impl super::TermWindow {
|
||||
// features.
|
||||
let blink_rate = match attrs.blink() {
|
||||
Blink::None => None,
|
||||
Blink::Slow => Some((
|
||||
params.config.text_blink_rate,
|
||||
self.last_text_blink_paint.borrow_mut(),
|
||||
)),
|
||||
Blink::Slow => {
|
||||
Some((params.config.text_blink_rate, self.blink_state.borrow_mut()))
|
||||
}
|
||||
Blink::Rapid => Some((
|
||||
params.config.text_blink_rate_rapid,
|
||||
self.last_text_blink_paint_rapid.borrow_mut(),
|
||||
self.rapid_blink_state.borrow_mut(),
|
||||
)),
|
||||
};
|
||||
if let Some((blink_rate, mut last_time)) = blink_rate {
|
||||
if let Some((blink_rate, mut colorease)) = blink_rate {
|
||||
if blink_rate != 0 {
|
||||
let milli_uptime = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis();
|
||||
let intensity = colorease.intensity_continuous();
|
||||
|
||||
let ticks = milli_uptime / blink_rate as u128;
|
||||
if (ticks & 1) == 0 {
|
||||
fg = bg;
|
||||
}
|
||||
let (r1, g1, b1, a) = bg.tuple();
|
||||
let (r, g, b, _a) = fg.tuple();
|
||||
fg = LinearRgba::with_components(
|
||||
r1 + (r - r1) * intensity,
|
||||
g1 + (g - g1) * intensity,
|
||||
b1 + (b - b1) * intensity,
|
||||
a,
|
||||
);
|
||||
|
||||
let interval = Duration::from_millis(blink_rate);
|
||||
if last_time.elapsed() >= interval {
|
||||
*last_time = Instant::now();
|
||||
}
|
||||
let due = *last_time + interval;
|
||||
|
||||
self.update_next_frame_time(Some(due));
|
||||
self.update_next_frame_time(Some(
|
||||
Instant::now()
|
||||
+ Duration::from_millis(1000 / self.config.max_fps as u64),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
(fg, bg, bg_default)
|
||||
};
|
||||
|
||||
let glyph_color = rgbcolor_to_window_color(fg_color);
|
||||
let glyph_color = fg_color;
|
||||
let underline_color = match attrs.underline_color() {
|
||||
ColorAttribute::Default => fg_color,
|
||||
c => resolve_fg_color_attr(&attrs, c, ¶ms, style),
|
||||
c => rgbcolor_to_window_color(resolve_fg_color_attr(&attrs, c, ¶ms, style)),
|
||||
};
|
||||
let underline_color = rgbcolor_to_window_color(underline_color);
|
||||
|
||||
let bg_color = rgbcolor_alpha_to_window_color(
|
||||
bg_color,
|
||||
let (bg_r, bg_g, bg_b, _) = bg_color.tuple();
|
||||
let bg_color = LinearRgba::with_components(
|
||||
bg_r,
|
||||
bg_g,
|
||||
bg_b,
|
||||
if params.window_is_transparent && bg_is_default {
|
||||
0.0
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user