mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
terminal: XTSHIFTESCAPE
This commit is contained in:
@ -1516,6 +1516,12 @@ fn mouseShiftCapture(self: *const Surface, lock: bool) bool {
|
||||
|
||||
if (lock) self.renderer_state.mutex.lock();
|
||||
defer if (lock) self.renderer_state.mutex.unlock();
|
||||
|
||||
// If thet terminal explicitly requests it then we always allow it
|
||||
// since we processed never/always at this point.
|
||||
if (self.io.terminal.flags.mouse_shift_capture) return true;
|
||||
|
||||
// Otherwise, go with the user's preference
|
||||
return switch (self.config.mouse_shift_capture) {
|
||||
.false => false,
|
||||
.true => true,
|
||||
|
@ -102,6 +102,11 @@ flags: packed struct {
|
||||
/// this was called so we have to track it separately.
|
||||
mouse_event: MouseEvents = .none,
|
||||
mouse_format: MouseFormat = .x10,
|
||||
|
||||
/// Set via the XTSHIFTESCAPE sequence. If true (XTSHIFTESCAPE = 1)
|
||||
/// then we want to capture the shift key for the mouse protocol
|
||||
/// if the configuration allows it.
|
||||
mouse_shift_capture: bool = false,
|
||||
} = .{},
|
||||
|
||||
/// The event types that can be reported for mouse-related activities.
|
||||
|
@ -815,6 +815,30 @@ pub fn Stream(comptime Handler: type) type {
|
||||
}
|
||||
},
|
||||
|
||||
// XTSHIFTESCAPE
|
||||
'>' => if (@hasDecl(T, "setMouseShiftCapture")) capture: {
|
||||
const capture = switch (action.params.len) {
|
||||
0 => false,
|
||||
1 => switch (action.params[0]) {
|
||||
0 => false,
|
||||
1 => true,
|
||||
else => {
|
||||
log.warn("invalid XTSHIFTESCAPE command: {}", .{action});
|
||||
break :capture;
|
||||
},
|
||||
},
|
||||
else => {
|
||||
log.warn("invalid XTSHIFTESCAPE command: {}", .{action});
|
||||
break :capture;
|
||||
},
|
||||
};
|
||||
|
||||
try self.handler.setMouseShiftCapture(capture);
|
||||
} else log.warn(
|
||||
"unimplemented CSI callback: {}",
|
||||
.{action},
|
||||
),
|
||||
|
||||
else => log.warn(
|
||||
"unknown CSI s with intermediate: {}",
|
||||
.{action},
|
||||
@ -1521,3 +1545,26 @@ test "stream: DECSCUSR without space" {
|
||||
try s.nextSlice("\x1B[1q");
|
||||
try testing.expect(s.handler.style == null);
|
||||
}
|
||||
|
||||
test "stream: XTSHIFTESCAPE" {
|
||||
const H = struct {
|
||||
escape: ?bool = null,
|
||||
|
||||
pub fn setMouseShiftCapture(self: *@This(), v: bool) !void {
|
||||
self.escape = v;
|
||||
}
|
||||
};
|
||||
|
||||
var s: Stream(H) = .{ .handler = .{} };
|
||||
try s.nextSlice("\x1B[>2s");
|
||||
try testing.expect(s.handler.escape == null);
|
||||
|
||||
try s.nextSlice("\x1B[>s");
|
||||
try testing.expect(s.handler.escape.? == false);
|
||||
|
||||
try s.nextSlice("\x1B[>0s");
|
||||
try testing.expect(s.handler.escape.? == false);
|
||||
|
||||
try s.nextSlice("\x1B[>1s");
|
||||
try testing.expect(s.handler.escape.? == true);
|
||||
}
|
||||
|
@ -1521,6 +1521,10 @@ const StreamHandler = struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setMouseShiftCapture(self: *StreamHandler, v: bool) !void {
|
||||
self.terminal.flags.mouse_shift_capture = v;
|
||||
}
|
||||
|
||||
pub fn setAttribute(self: *StreamHandler, attr: terminal.Attribute) !void {
|
||||
switch (attr) {
|
||||
.unknown => |unk| log.warn("unimplemented or unknown SGR attribute: {any}", .{unk}),
|
||||
|
Reference in New Issue
Block a user