mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
config: make blink interval configurable
This commit is contained in:
@ -346,12 +346,40 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF },
|
|||||||
/// This value does not apply to Emoji or images.
|
/// This value does not apply to Emoji or images.
|
||||||
@"minimum-contrast": f64 = 1,
|
@"minimum-contrast": f64 = 1,
|
||||||
|
|
||||||
/// Whether to enable blinking text.
|
/// The amount of time it takes for blinking text and cursors to toggle between
|
||||||
/// Text can be made to blink via a SGR sequence, which is synchronized with
|
/// being invisible and visible.
|
||||||
/// cursor blinking when that is enabled. Text blinking and cursor blinking
|
/// Any cell on the screen could be set to blink by setting SGR attribute 5,
|
||||||
/// can be independently toggled on or off without interfering with each other:
|
/// while cursor blinking is controlled by the `cursor-style-blink` setting.
|
||||||
/// to adjust cursor blinking settings, see `cursor-style-blink`.
|
///
|
||||||
@"text-blink": bool = true,
|
/// The interval is specified as a series of numbers followed by time units.
|
||||||
|
/// Whitespace is allowed between numbers and units. Each number and unit will
|
||||||
|
/// be added together to form the total interval.
|
||||||
|
///
|
||||||
|
/// Blinking is disabled when the interval is set to zero.
|
||||||
|
///
|
||||||
|
/// The allowed time units are as follows:
|
||||||
|
///
|
||||||
|
/// * `y` - 365 SI days, or 8760 hours, or 31536000 seconds. No adjustments
|
||||||
|
/// are made for leap years or leap seconds.
|
||||||
|
/// * `d` - one SI day, or 86400 seconds.
|
||||||
|
/// * `h` - one hour, or 3600 seconds.
|
||||||
|
/// * `m` - one minute, or 60 seconds.
|
||||||
|
/// * `s` - one second.
|
||||||
|
/// * `ms` - one millisecond, or 0.001 second.
|
||||||
|
/// * `us` or `µs` - one microsecond, or 0.000001 second.
|
||||||
|
/// * `ns` - one nanosecond, or 0.000000001 second.
|
||||||
|
///
|
||||||
|
/// Examples:
|
||||||
|
/// * `1h30m`
|
||||||
|
/// * `45s`
|
||||||
|
///
|
||||||
|
/// Units can be repeated and will be added together. This means that
|
||||||
|
/// `1h1h` is equivalent to `2h`. This is confusing and should be avoided.
|
||||||
|
/// A future update may disallow this.
|
||||||
|
///
|
||||||
|
/// The maximum value is `584y 49w 23h 34m 33s 709ms 551µs 615ns`. Any
|
||||||
|
/// value larger than this will be clamped to the maximum value.
|
||||||
|
@"blink-interval": Duration = .{ .duration = 600 * std.time.ns_per_ms },
|
||||||
|
|
||||||
/// Color palette for the 256 color form that many terminal applications use.
|
/// Color palette for the 256 color form that many terminal applications use.
|
||||||
/// The syntax of this configuration is `N=HEXCODE` where `N` is 0 to 255 (for
|
/// The syntax of this configuration is `N=HEXCODE` where `N` is 0 to 255 (for
|
||||||
|
@ -16,7 +16,6 @@ const Allocator = std.mem.Allocator;
|
|||||||
const log = std.log.scoped(.renderer_thread);
|
const log = std.log.scoped(.renderer_thread);
|
||||||
|
|
||||||
const DRAW_INTERVAL = 8; // 120 FPS
|
const DRAW_INTERVAL = 8; // 120 FPS
|
||||||
const BLINK_INTERVAL = 600;
|
|
||||||
|
|
||||||
/// The type used for sending messages to the IO thread. For now this is
|
/// The type used for sending messages to the IO thread. For now this is
|
||||||
/// hardcoded with a capacity. We can make this a comptime parameter in
|
/// hardcoded with a capacity. We can make this a comptime parameter in
|
||||||
@ -109,12 +108,18 @@ flags: packed struct {
|
|||||||
|
|
||||||
pub const DerivedConfig = struct {
|
pub const DerivedConfig = struct {
|
||||||
custom_shader_animation: configpkg.CustomShaderAnimation,
|
custom_shader_animation: configpkg.CustomShaderAnimation,
|
||||||
text_blink: bool,
|
blink_interval: u64,
|
||||||
|
|
||||||
pub fn init(config: *const configpkg.Config) DerivedConfig {
|
pub fn init(config: *const configpkg.Config) DerivedConfig {
|
||||||
|
const blink_interval = std.math.divTrunc(
|
||||||
|
u64,
|
||||||
|
config.@"blink-interval".duration,
|
||||||
|
std.time.ns_per_ms,
|
||||||
|
) catch std.math.maxInt(u64);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.custom_shader_animation = config.@"custom-shader-animation",
|
.custom_shader_animation = config.@"custom-shader-animation",
|
||||||
.text_blink = config.@"text-blink",
|
.blink_interval = blink_interval,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -240,14 +245,16 @@ fn threadMain_(self: *Thread) !void {
|
|||||||
try self.wakeup.notify();
|
try self.wakeup.notify();
|
||||||
|
|
||||||
// Start blinking the cursor and the text on screen.
|
// Start blinking the cursor and the text on screen.
|
||||||
self.blink_h.run(
|
if (self.config.blink_interval > 0) {
|
||||||
&self.loop,
|
self.blink_h.run(
|
||||||
&self.blink_c,
|
&self.loop,
|
||||||
BLINK_INTERVAL,
|
&self.blink_c,
|
||||||
Thread,
|
self.config.blink_interval,
|
||||||
self,
|
Thread,
|
||||||
blinkTimerCallback,
|
self,
|
||||||
);
|
blinkTimerCallback,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Start the draw timer
|
// Start the draw timer
|
||||||
self.startDrawTimer();
|
self.startDrawTimer();
|
||||||
@ -343,12 +350,12 @@ fn drainMailbox(self: *Thread) !void {
|
|||||||
|
|
||||||
// If we're focused, we immediately make blinking cells visible
|
// If we're focused, we immediately make blinking cells visible
|
||||||
// again and then restart the timer.
|
// again and then restart the timer.
|
||||||
if (self.blink_c.state() != .active) {
|
if (self.blink_c.state() != .active and self.config.blink_interval > 0) {
|
||||||
self.flags.blink_visible = true;
|
self.flags.blink_visible = true;
|
||||||
self.blink_h.run(
|
self.blink_h.run(
|
||||||
&self.loop,
|
&self.loop,
|
||||||
&self.blink_c,
|
&self.blink_c,
|
||||||
BLINK_INTERVAL,
|
self.config.blink_interval,
|
||||||
Thread,
|
Thread,
|
||||||
self,
|
self,
|
||||||
blinkTimerCallback,
|
blinkTimerCallback,
|
||||||
@ -360,15 +367,17 @@ fn drainMailbox(self: *Thread) !void {
|
|||||||
.reset_cursor_blink => {
|
.reset_cursor_blink => {
|
||||||
self.flags.cursor_always_visible = true;
|
self.flags.cursor_always_visible = true;
|
||||||
|
|
||||||
self.cursor_h.reset(
|
if (self.config.blink_interval > 0) {
|
||||||
&self.loop,
|
self.cursor_h.reset(
|
||||||
&self.cursor_c,
|
&self.loop,
|
||||||
&self.cursor_c_cancel,
|
&self.cursor_c,
|
||||||
BLINK_INTERVAL,
|
&self.cursor_c_cancel,
|
||||||
Thread,
|
self.config.blink_interval,
|
||||||
self,
|
Thread,
|
||||||
resetCursorBlinkCallback,
|
self,
|
||||||
);
|
resetCursorBlinkCallback,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
.font_grid => |grid| {
|
.font_grid => |grid| {
|
||||||
@ -549,7 +558,7 @@ fn renderCallback(
|
|||||||
t.renderer.updateFrame(
|
t.renderer.updateFrame(
|
||||||
t.surface,
|
t.surface,
|
||||||
t.state,
|
t.state,
|
||||||
!t.config.text_blink or t.flags.blink_visible,
|
t.flags.blink_visible,
|
||||||
t.flags.cursor_always_visible or t.flags.blink_visible,
|
t.flags.cursor_always_visible or t.flags.blink_visible,
|
||||||
) catch |err|
|
) catch |err|
|
||||||
log.warn("error rendering err={}", .{err});
|
log.warn("error rendering err={}", .{err});
|
||||||
@ -584,7 +593,7 @@ fn blinkTimerCallback(
|
|||||||
|
|
||||||
t.flags.blink_visible = !t.flags.blink_visible;
|
t.flags.blink_visible = !t.flags.blink_visible;
|
||||||
t.wakeup.notify() catch {};
|
t.wakeup.notify() catch {};
|
||||||
t.blink_h.run(&t.loop, &t.blink_c, BLINK_INTERVAL, Thread, t, blinkTimerCallback);
|
t.blink_h.run(&t.loop, &t.blink_c, t.config.blink_interval, Thread, t, blinkTimerCallback);
|
||||||
|
|
||||||
return .disarm;
|
return .disarm;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user