diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 1ab9bb80c..6254f6e7d 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -654,6 +654,10 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell { // UTF-8 or ASCII is used as-is if (set == .utf8 or set == .ascii) break :c unmapped_c; + // If we're outside of ASCII range this is an invalid value in + // this table so we just return space. + if (unmapped_c > std.math.maxInt(u8)) break :c ' '; + // Get our lookup table and map it const table = set.table(); break :c @intCast(u21, table[@intCast(u8, unmapped_c)]); @@ -1502,6 +1506,26 @@ test "Terminal: print charset" { } } +test "Terminal: print charset outside of ASCII" { + var t = try init(testing.allocator, 80, 80); + defer t.deinit(testing.allocator); + + // G1 should have no effect + t.configureCharset(.G1, .dec_special); + t.configureCharset(.G2, .dec_special); + t.configureCharset(.G3, .dec_special); + + // Basic grid writing + t.configureCharset(.G0, .dec_special); + try t.print('`'); + try t.print(0x1F600); + { + var str = try t.plainString(testing.allocator); + defer testing.allocator.free(str); + try testing.expectEqualStrings("◆ ", str); + } +} + test "Terminal: print invoke charset" { var t = try init(testing.allocator, 80, 80); defer t.deinit(testing.allocator);