various tests to ensure we parse curly underlines correctly

This commit is contained in:
Mitchell Hashimoto
2023-06-20 09:24:07 -07:00
parent 0044776700
commit 28a22fc07f
4 changed files with 66 additions and 2 deletions

View File

@ -524,12 +524,67 @@ test "csi: SGR ESC [ 38 : 2 m" {
const d = a[1].?.csi_dispatch; const d = a[1].?.csi_dispatch;
try testing.expect(d.final == 'm'); try testing.expect(d.final == 'm');
try testing.expect(d.sep == .colon);
try testing.expect(d.params.len == 2); try testing.expect(d.params.len == 2);
try testing.expectEqual(@as(u16, 38), d.params[0]); try testing.expectEqual(@as(u16, 38), d.params[0]);
try testing.expectEqual(@as(u16, 2), d.params[1]); try testing.expectEqual(@as(u16, 2), d.params[1]);
} }
} }
test "csi: SGR ESC [4:3m colon" {
var p = init();
_ = p.next(0x1B);
_ = p.next('[');
_ = p.next('4');
_ = p.next(':');
_ = p.next('3');
{
const a = p.next('m');
try testing.expect(p.state == .ground);
try testing.expect(a[0] == null);
try testing.expect(a[1].? == .csi_dispatch);
try testing.expect(a[2] == null);
const d = a[1].?.csi_dispatch;
try testing.expect(d.final == 'm');
try testing.expect(d.sep == .colon);
try testing.expect(d.params.len == 2);
try testing.expectEqual(@as(u16, 4), d.params[0]);
try testing.expectEqual(@as(u16, 3), d.params[1]);
}
}
test "csi: SGR with many blank and colon" {
var p = init();
_ = p.next(0x1B);
for ("[58:2::240:143:104") |c| {
const a = p.next(c);
try testing.expect(a[0] == null);
try testing.expect(a[1] == null);
try testing.expect(a[2] == null);
}
{
const a = p.next('m');
try testing.expect(p.state == .ground);
try testing.expect(a[0] == null);
try testing.expect(a[1].? == .csi_dispatch);
try testing.expect(a[2] == null);
const d = a[1].?.csi_dispatch;
try testing.expect(d.final == 'm');
try testing.expect(d.sep == .colon);
try testing.expect(d.params.len == 6);
try testing.expectEqual(@as(u16, 58), d.params[0]);
try testing.expectEqual(@as(u16, 2), d.params[1]);
try testing.expectEqual(@as(u16, 0), d.params[2]);
try testing.expectEqual(@as(u16, 240), d.params[3]);
try testing.expectEqual(@as(u16, 143), d.params[4]);
try testing.expectEqual(@as(u16, 104), d.params[5]);
}
}
test "csi: mixing semicolon/colon" { test "csi: mixing semicolon/colon" {
var p = init(); var p = init();
_ = p.next(0x1B); _ = p.next(0x1B);

View File

@ -344,6 +344,12 @@ test "sgr: underline styles" {
try testing.expect(v.underline == .single); try testing.expect(v.underline == .single);
} }
{
const v = testParseColon(&[_]u16{ 4, 3 });
try testing.expect(v == .underline);
try testing.expect(v.underline == .curly);
}
{ {
const v = testParseColon(&[_]u16{ 4, 4 }); const v = testParseColon(&[_]u16{ 4, 4 });
try testing.expect(v == .underline); try testing.expect(v == .underline);

View File

@ -385,7 +385,10 @@ pub fn Stream(comptime Handler: type) type {
// SGR - Select Graphic Rendition // SGR - Select Graphic Rendition
'm' => if (@hasDecl(T, "setAttribute")) { 'm' => if (@hasDecl(T, "setAttribute")) {
var p: sgr.Parser = .{ .params = action.params, .colon = action.sep == .colon }; var p: sgr.Parser = .{ .params = action.params, .colon = action.sep == .colon };
while (p.next()) |attr| try self.handler.setAttribute(attr); while (p.next()) |attr| {
//log.info("SGR attribute: {}", .{attr});
try self.handler.setAttribute(attr);
}
} else log.warn("unimplemented CSI callback: {}", .{action}), } else log.warn("unimplemented CSI callback: {}", .{action}),
// CPR - Request Cursor Postion Report // CPR - Request Cursor Postion Report

View File

@ -1081,7 +1081,7 @@ const StreamHandler = struct {
pub fn setAttribute(self: *StreamHandler, attr: terminal.Attribute) !void { pub fn setAttribute(self: *StreamHandler, attr: terminal.Attribute) !void {
switch (attr) { switch (attr) {
.unknown => |unk| log.warn("unimplemented or unknown attribute: {any}", .{unk}), .unknown => |unk| log.warn("unimplemented or unknown SGR attribute: {any}", .{unk}),
else => self.terminal.setAttribute(attr) catch |err| else => self.terminal.setAttribute(attr) catch |err|
log.warn("error setting attribute {}: {}", .{ attr, err }), log.warn("error setting attribute {}: {}", .{ attr, err }),