mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
terminal: pass intermediates through to CSI, ignore NUL
This commit is contained in:
@ -64,6 +64,7 @@ pub const Action = union(enum) {
|
|||||||
csi_dispatch: CSI,
|
csi_dispatch: CSI,
|
||||||
|
|
||||||
pub const CSI = struct {
|
pub const CSI = struct {
|
||||||
|
intermediates: []u8,
|
||||||
params: []u16,
|
params: []u16,
|
||||||
final: u8,
|
final: u8,
|
||||||
};
|
};
|
||||||
@ -77,8 +78,8 @@ const MAX_PARAMS = 16;
|
|||||||
state: State = .ground,
|
state: State = .ground,
|
||||||
|
|
||||||
/// Intermediate tracking.
|
/// Intermediate tracking.
|
||||||
intermediate: [MAX_INTERMEDIATE]u8 = undefined,
|
intermediates: [MAX_INTERMEDIATE]u8 = undefined,
|
||||||
intermediate_idx: u8 = 0,
|
intermediates_idx: u8 = 0,
|
||||||
|
|
||||||
/// Param tracking, building
|
/// Param tracking, building
|
||||||
params: [MAX_PARAMS]u16 = undefined,
|
params: [MAX_PARAMS]u16 = undefined,
|
||||||
@ -144,7 +145,7 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
|
|||||||
.print => Action{ .print = c },
|
.print => Action{ .print = c },
|
||||||
.execute => Action{ .execute = c },
|
.execute => Action{ .execute = c },
|
||||||
.collect => collect: {
|
.collect => collect: {
|
||||||
self.intermediate[self.intermediate_idx] = c;
|
self.intermediates[self.intermediates_idx] = c;
|
||||||
// TODO: incr, bounds check
|
// TODO: incr, bounds check
|
||||||
|
|
||||||
// The client is expected to perform no action.
|
// The client is expected to perform no action.
|
||||||
@ -185,6 +186,7 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
|
|||||||
|
|
||||||
break :csi_dispatch Action{
|
break :csi_dispatch Action{
|
||||||
.csi_dispatch = .{
|
.csi_dispatch = .{
|
||||||
|
.intermediates = self.intermediates[0..self.intermediates_idx],
|
||||||
.params = self.params[0..self.params_idx],
|
.params = self.params[0..self.params_idx],
|
||||||
.final = c,
|
.final = c,
|
||||||
},
|
},
|
||||||
@ -198,7 +200,7 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear(self: *Parser) void {
|
fn clear(self: *Parser) void {
|
||||||
self.intermediate_idx = 0;
|
self.intermediates_idx = 0;
|
||||||
self.params_idx = 0;
|
self.params_idx = 0;
|
||||||
self.param_acc = 0;
|
self.param_acc = 0;
|
||||||
self.param_acc_idx = 0;
|
self.param_acc_idx = 0;
|
||||||
@ -253,7 +255,7 @@ test "csi: ESC [ 1 ; 4 H" {
|
|||||||
_ = p.next(0x31); // 1
|
_ = p.next(0x31); // 1
|
||||||
_ = p.next(0x3B); // ;
|
_ = p.next(0x3B); // ;
|
||||||
_ = p.next(0x34); // 4
|
_ = p.next(0x34); // 4
|
||||||
//
|
|
||||||
{
|
{
|
||||||
const a = p.next(0x48); // H
|
const a = p.next(0x48); // H
|
||||||
try testing.expect(p.state == .ground);
|
try testing.expect(p.state == .ground);
|
||||||
|
@ -127,6 +127,7 @@ pub fn appendChar(self: *Terminal, alloc: Allocator, c: u8) !void {
|
|||||||
switch (action_opt orelse continue) {
|
switch (action_opt orelse continue) {
|
||||||
.print => |p| try self.print(alloc, p),
|
.print => |p| try self.print(alloc, p),
|
||||||
.execute => |code| try self.execute(alloc, code),
|
.execute => |code| try self.execute(alloc, code),
|
||||||
|
.csi_dispatch => |csi| log.warn("CSI: {}", .{csi}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,6 +156,7 @@ fn execute(self: *Terminal, alloc: Allocator, c: u8) !void {
|
|||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
switch (@intToEnum(ansi.C0, c)) {
|
switch (@intToEnum(ansi.C0, c)) {
|
||||||
|
.NUL => {},
|
||||||
.BEL => self.bell(),
|
.BEL => self.bell(),
|
||||||
.BS => self.backspace(),
|
.BS => self.backspace(),
|
||||||
.HT => try self.horizontal_tab(alloc),
|
.HT => try self.horizontal_tab(alloc),
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
/// This is not complete, control characters are only added to this
|
/// This is not complete, control characters are only added to this
|
||||||
/// as the terminal emulator handles them.
|
/// as the terminal emulator handles them.
|
||||||
pub const C0 = enum(u7) {
|
pub const C0 = enum(u7) {
|
||||||
|
/// Null
|
||||||
|
NUL = 0x00,
|
||||||
/// Bell
|
/// Bell
|
||||||
BEL = 0x07,
|
BEL = 0x07,
|
||||||
/// Backspace
|
/// Backspace
|
||||||
|
Reference in New Issue
Block a user