apprt: rename set_bg/fg to "color_change" to report all color changes

This commit is contained in:
Mitchell Hashimoto
2024-10-30 16:31:59 -04:00
parent a2a1d93d5c
commit 1065359b9a
8 changed files with 55 additions and 50 deletions

View File

@ -512,19 +512,20 @@ typedef struct {
ghostty_input_trigger_s trigger; ghostty_input_trigger_s trigger;
} ghostty_action_key_sequence_s; } ghostty_action_key_sequence_s;
// apprt.action.SetBackground // apprt.action.ColorKind
typedef struct { typedef enum {
uint8_t r; GHOSTTY_ACTION_COLOR_KIND_FOREGROUND = -1,
uint8_t g; GHOSTTY_ACTION_COLOR_KIND_BACKGROUND = -2,
uint8_t b; GHOSTTY_ACTION_COLOR_KIND_CURSOR = -3,
} ghostty_action_set_background_s; } ghostty_action_color_kind_e;
// apprt.action.SetForeground // apprt.action.ColorChange
typedef struct { typedef struct {
ghostty_action_color_kind_e kind;
uint8_t r; uint8_t r;
uint8_t g; uint8_t g;
uint8_t b; uint8_t b;
} ghostty_action_set_foreground_s; } ghostty_action_color_change_s;
// apprt.Action.Key // apprt.Action.Key
typedef enum { typedef enum {
@ -559,8 +560,7 @@ typedef enum {
GHOSTTY_ACTION_QUIT_TIMER, GHOSTTY_ACTION_QUIT_TIMER,
GHOSTTY_ACTION_SECURE_INPUT, GHOSTTY_ACTION_SECURE_INPUT,
GHOSTTY_ACTION_KEY_SEQUENCE, GHOSTTY_ACTION_KEY_SEQUENCE,
GHOSTTY_ACTION_SET_BACKGROUND, GHOSTTY_ACTION_COLOR_CHANGE,
GHOSTTY_ACTION_SET_FOREGROUND,
} ghostty_action_tag_e; } ghostty_action_tag_e;
typedef union { typedef union {
@ -583,8 +583,7 @@ typedef union {
ghostty_action_quit_timer_e quit_timer; ghostty_action_quit_timer_e quit_timer;
ghostty_action_secure_input_e secure_input; ghostty_action_secure_input_e secure_input;
ghostty_action_key_sequence_s key_sequence; ghostty_action_key_sequence_s key_sequence;
ghostty_action_set_background_s set_background; ghostty_action_color_change_s color_change;
ghostty_action_set_foreground_s set_foreground;
} ghostty_action_u; } ghostty_action_u;
typedef struct { typedef struct {

View File

@ -521,6 +521,8 @@ extension Ghostty {
case GHOSTTY_ACTION_KEY_SEQUENCE: case GHOSTTY_ACTION_KEY_SEQUENCE:
keySequence(app, target: target, v: action.action.key_sequence) keySequence(app, target: target, v: action.action.key_sequence)
case GHOSTTY_ACTION_COLOR_CHANGE:
fallthrough
case GHOSTTY_ACTION_CLOSE_ALL_WINDOWS: case GHOSTTY_ACTION_CLOSE_ALL_WINDOWS:
fallthrough fallthrough
case GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW: case GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW:

View File

@ -799,21 +799,21 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
}, .unlocked); }, .unlocked);
}, },
.set_background => |color| { .color_change => |change| try self.rt_app.performAction(
try self.rt_app.performAction( .{ .surface = self },
.{ .surface = self }, .color_change,
.set_background, .{
.{ .r = color.r, .g = color.g, .b = color.b }, .kind = switch (change.kind) {
); .background => .background,
}, .foreground => .foreground,
.cursor => .cursor,
.set_foreground => |color| { .palette => |v| @enumFromInt(v),
try self.rt_app.performAction( },
.{ .surface = self }, .r = change.color.r,
.set_background, .g = change.color.g,
.{ .r = color.r, .g = color.g, .b = color.b }, .b = change.color.b,
); },
}, ),
.set_mouse_shape => |shape| { .set_mouse_shape => |shape| {
log.debug("changing mouse shape: {}", .{shape}); log.debug("changing mouse shape: {}", .{shape});

View File

@ -186,11 +186,9 @@ pub const Action = union(Key) {
/// key mode because other input may be ignored. /// key mode because other input may be ignored.
key_sequence: KeySequence, key_sequence: KeySequence,
/// The terminal background color was changed. /// A terminal color was changed programmatically through things
set_background: SetBackground, /// such as OSC 10/11.
color_change: ColorChange,
/// The terminal foreground color was changed.
set_foreground: SetForeground,
/// Sync with: ghostty_action_tag_e /// Sync with: ghostty_action_tag_e
pub const Key = enum(c_int) { pub const Key = enum(c_int) {
@ -225,8 +223,7 @@ pub const Action = union(Key) {
quit_timer, quit_timer,
secure_input, secure_input,
key_sequence, key_sequence,
set_background, color_change,
set_foreground,
}; };
/// Sync with: ghostty_action_u /// Sync with: ghostty_action_u
@ -457,14 +454,19 @@ pub const KeySequence = union(enum) {
} }
}; };
pub const SetBackground = extern struct { pub const ColorChange = extern struct {
kind: ColorKind,
r: u8, r: u8,
g: u8, g: u8,
b: u8, b: u8,
}; };
pub const SetForeground = extern struct { pub const ColorKind = enum(c_int) {
r: u8, // Negative numbers indicate some named kind
g: u8, foreground = -1,
b: u8, background = -2,
cursor = -3,
// 0+ values indicate a palette index
_,
}; };

View File

@ -223,8 +223,7 @@ pub const App = struct {
.mouse_over_link, .mouse_over_link,
.cell_size, .cell_size,
.renderer_health, .renderer_health,
.set_foreground, .color_change,
.set_background,
=> log.info("unimplemented action={}", .{action}), => log.info("unimplemented action={}", .{action}),
} }
} }

View File

@ -485,8 +485,7 @@ pub fn performAction(
.key_sequence, .key_sequence,
.render_inspector, .render_inspector,
.renderer_health, .renderer_health,
.set_foreground, .color_change,
.set_background,
=> log.warn("unimplemented action={}", .{action}), => log.warn("unimplemented action={}", .{action}),
} }
} }

View File

@ -70,11 +70,11 @@ pub const Message = union(enum) {
/// unless the surface exits. /// unless the surface exits.
password_input: bool, password_input: bool,
/// The terminal background color was changed. /// A terminal color was changed using OSC sequences.
set_background: terminal.color.RGB, color_change: struct {
kind: terminal.osc.Command.ColorKind,
/// The terminal foreground color was changed. color: terminal.color.RGB,
set_foreground: terminal.color.RGB, },
pub const ReportTitleStyle = enum { pub const ReportTitleStyle = enum {
csi_21_t, csi_21_t,

View File

@ -1215,14 +1215,12 @@ pub const StreamHandler = struct {
_ = self.renderer_mailbox.push(.{ _ = self.renderer_mailbox.push(.{
.foreground_color = color, .foreground_color = color,
}, .{ .forever = {} }); }, .{ .forever = {} });
self.surfaceMessageWriter(.{ .set_background = color });
}, },
.background => { .background => {
self.background_color = color; self.background_color = color;
_ = self.renderer_mailbox.push(.{ _ = self.renderer_mailbox.push(.{
.background_color = color, .background_color = color,
}, .{ .forever = {} }); }, .{ .forever = {} });
self.surfaceMessageWriter(.{ .set_background = color });
}, },
.cursor => { .cursor => {
self.cursor_color = color; self.cursor_color = color;
@ -1231,6 +1229,12 @@ pub const StreamHandler = struct {
}, .{ .forever = {} }); }, .{ .forever = {} });
}, },
} }
// Notify the surface of the color change
self.surfaceMessageWriter(.{ .color_change = .{
.kind = kind,
.color = color,
} });
} }
pub fn resetColor( pub fn resetColor(