Shift Out/Shift In (invoke charset into GL)

This commit is contained in:
Mitchell Hashimoto
2022-08-27 10:08:01 -07:00
parent 7626f194e9
commit bee82d58dc
5 changed files with 60 additions and 3 deletions

View File

@ -1552,7 +1552,8 @@ pub fn deviceAttributes(
_ = params;
switch (req) {
.primary => self.queueWrite("\x1B[?6c") catch |err|
// VT220
.primary => self.queueWrite("\x1B[?62;c") catch |err|
log.warn("error queueing device attr response: {}", .{err}),
else => log.warn("unimplemented device attributes req: {}", .{req}),
}
@ -1640,3 +1641,12 @@ pub fn configureCharset(
) !void {
self.terminal.configureCharset(slot, set);
}
pub fn invokeCharset(
self: *Window,
active: terminal.CharsetActiveSlot,
slot: terminal.CharsetSlot,
single: bool,
) !void {
self.terminal.invokeCharset(active, slot, single);
}

View File

@ -399,6 +399,22 @@ pub fn configureCharset(self: *Terminal, slot: charsets.Slots, set: charsets.Cha
self.charset.charsets.set(slot, set);
}
/// Invoke the charset in slot into the active slot. If single is true,
/// then this will only be invoked for a single character.
pub fn invokeCharset(
self: *Terminal,
active: charsets.ActiveSlot,
slot: charsets.Slots,
single: bool,
) void {
assert(!single); // TODO
switch (active) {
.GL => self.charset.gl = slot,
.GR => self.charset.gr = slot,
}
}
pub fn print(self: *Terminal, c: u21) !void {
const tracy = trace(@src());
defer tracy.end();
@ -1306,6 +1322,26 @@ test "Terminal: print charset" {
}
}
test "Terminal: print invoke charset" {
var t = try init(testing.allocator, 80, 80);
defer t.deinit(testing.allocator);
t.configureCharset(.G1, .dec_special);
// Basic grid writing
try t.print('`');
t.invokeCharset(.GL, .G1, false);
try t.print('`');
try t.print('`');
t.invokeCharset(.GL, .G0, false);
try t.print('`');
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("`◆◆`", str);
}
}
test "Terminal: linefeed and carriage return" {
var t = try init(testing.allocator, 80, 80);
defer t.deinit(testing.allocator);

View File

@ -9,6 +9,9 @@ pub const Slots = enum(u3) {
G3 = 3,
};
/// The name of the active slots.
pub const ActiveSlot = enum { GL, GR };
/// The list of supported character sets and their associated tables.
pub const Charset = enum {
utf8,

View File

@ -10,6 +10,7 @@ pub const color = @import("color.zig");
pub const Charset = charsets.Charset;
pub const CharsetSlot = charsets.Slots;
pub const CharsetActiveSlot = charsets.ActiveSlot;
pub const Terminal = @import("Terminal.zig");
pub const Parser = @import("Parser.zig");
pub const Selection = @import("Selection.zig");

View File

@ -109,8 +109,15 @@ pub fn Stream(comptime Handler: type) type {
else
log.warn("unimplemented execute: {x}", .{c}),
// TODO
.SO, .SI => log.warn("TODO: Shift out/Shift in", .{}),
.SO => if (@hasDecl(T, "invokeCharset"))
try self.handler.invokeCharset(.GL, .G1, false)
else
log.warn("unimplemented invokeCharset: {x}", .{c}),
.SI => if (@hasDecl(T, "invokeCharset"))
try self.handler.invokeCharset(.GL, .G0, false)
else
log.warn("unimplemented invokeCharset: {x}", .{c}),
}
}