terminal: pass intermediates through to CSI, ignore NUL

This commit is contained in:
Mitchell Hashimoto
2022-05-08 15:02:24 -07:00
parent 468f6e2b51
commit 8e907a3522
3 changed files with 11 additions and 5 deletions

View File

@ -64,6 +64,7 @@ pub const Action = union(enum) {
csi_dispatch: CSI,
pub const CSI = struct {
intermediates: []u8,
params: []u16,
final: u8,
};
@ -77,8 +78,8 @@ const MAX_PARAMS = 16;
state: State = .ground,
/// Intermediate tracking.
intermediate: [MAX_INTERMEDIATE]u8 = undefined,
intermediate_idx: u8 = 0,
intermediates: [MAX_INTERMEDIATE]u8 = undefined,
intermediates_idx: u8 = 0,
/// Param tracking, building
params: [MAX_PARAMS]u16 = undefined,
@ -144,7 +145,7 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
.print => Action{ .print = c },
.execute => Action{ .execute = c },
.collect => collect: {
self.intermediate[self.intermediate_idx] = c;
self.intermediates[self.intermediates_idx] = c;
// TODO: incr, bounds check
// 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{
.csi_dispatch = .{
.intermediates = self.intermediates[0..self.intermediates_idx],
.params = self.params[0..self.params_idx],
.final = c,
},
@ -198,7 +200,7 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
}
fn clear(self: *Parser) void {
self.intermediate_idx = 0;
self.intermediates_idx = 0;
self.params_idx = 0;
self.param_acc = 0;
self.param_acc_idx = 0;
@ -253,7 +255,7 @@ test "csi: ESC [ 1 ; 4 H" {
_ = p.next(0x31); // 1
_ = p.next(0x3B); // ;
_ = p.next(0x34); // 4
//
{
const a = p.next(0x48); // H
try testing.expect(p.state == .ground);

View File

@ -127,6 +127,7 @@ pub fn appendChar(self: *Terminal, alloc: Allocator, c: u8) !void {
switch (action_opt orelse continue) {
.print => |p| try self.print(alloc, p),
.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();
switch (@intToEnum(ansi.C0, c)) {
.NUL => {},
.BEL => self.bell(),
.BS => self.backspace(),
.HT => try self.horizontal_tab(alloc),

View File

@ -3,6 +3,8 @@
/// This is not complete, control characters are only added to this
/// as the terminal emulator handles them.
pub const C0 = enum(u7) {
/// Null
NUL = 0x00,
/// Bell
BEL = 0x07,
/// Backspace