Merge pull request #2514 from neurocyte/apprt-osc10-osc11

apprt: propagate OSC10/11 (set term fore/background color) to apprt
This commit is contained in:
Mitchell Hashimoto
2024-10-30 16:38:52 -04:00
committed by GitHub
8 changed files with 71 additions and 0 deletions

View File

@ -512,6 +512,21 @@ typedef struct {
ghostty_input_trigger_s trigger;
} ghostty_action_key_sequence_s;
// apprt.action.ColorKind
typedef enum {
GHOSTTY_ACTION_COLOR_KIND_FOREGROUND = -1,
GHOSTTY_ACTION_COLOR_KIND_BACKGROUND = -2,
GHOSTTY_ACTION_COLOR_KIND_CURSOR = -3,
} ghostty_action_color_kind_e;
// apprt.action.ColorChange
typedef struct {
ghostty_action_color_kind_e kind;
uint8_t r;
uint8_t g;
uint8_t b;
} ghostty_action_color_change_s;
// apprt.Action.Key
typedef enum {
GHOSTTY_ACTION_NEW_WINDOW,
@ -545,6 +560,7 @@ typedef enum {
GHOSTTY_ACTION_QUIT_TIMER,
GHOSTTY_ACTION_SECURE_INPUT,
GHOSTTY_ACTION_KEY_SEQUENCE,
GHOSTTY_ACTION_COLOR_CHANGE,
} ghostty_action_tag_e;
typedef union {
@ -567,6 +583,7 @@ typedef union {
ghostty_action_quit_timer_e quit_timer;
ghostty_action_secure_input_e secure_input;
ghostty_action_key_sequence_s key_sequence;
ghostty_action_color_change_s color_change;
} ghostty_action_u;
typedef struct {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1229,6 +1229,12 @@ pub const StreamHandler = struct {
}, .{ .forever = {} });
},
}
// Notify the surface of the color change
self.surfaceMessageWriter(.{ .color_change = .{
.kind = kind,
.color = color,
} });
}
pub fn resetColor(