From 37f621bc19d0738cffb08230056e2c22afdc6705 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 May 2022 21:43:30 -0700 Subject: [PATCH] plumb CSI to set cursor style, but haven't implemented any styles --- src/Window.zig | 11 +++++++++++ src/terminal/ansi.zig | 14 ++++++++++++++ src/terminal/main.zig | 1 + src/terminal/stream.zig | 13 +++++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/Window.zig b/src/Window.zig index d073d56cf..a0a8c0fab 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -669,3 +669,14 @@ pub fn deviceStatusReport( else => log.warn("unimplemented device status req: {}", .{req}), } } + +pub fn setCursorStyle( + self: *Window, + style: terminal.CursorStyle, +) !void { + _ = self; + + switch (style) { + else => log.warn("unimplemented cursor style: {}", .{style}), + } +} diff --git a/src/terminal/ansi.zig b/src/terminal/ansi.zig index 15097196d..acfa4e56a 100644 --- a/src/terminal/ansi.zig +++ b/src/terminal/ansi.zig @@ -58,3 +58,17 @@ pub const DeviceStatusReq = enum(u16) { // Non-exhaustive so that @intToEnum never fails for unsupported modes. _, }; + +/// Possible cursor styles (ESC [ q) +pub const CursorStyle = enum(u16) { + default = 0, + blinking_block = 1, + steady_block = 2, + blinking_underline = 3, + steady_underline = 4, + blinking_bar = 5, + steady_bar = 6, + + // Non-exhaustive so that @intToEnum never fails for unsupported modes. + _, +}; diff --git a/src/terminal/main.zig b/src/terminal/main.zig index 29c86e8b5..00e214847 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -7,6 +7,7 @@ pub const color = @import("color.zig"); pub const Terminal = @import("Terminal.zig"); pub const Parser = @import("Parser.zig"); pub const Stream = stream.Stream; +pub const CursorStyle = ansi.CursorStyle; pub const DeviceAttributeReq = ansi.DeviceAttributeReq; pub const DeviceStatusReq = ansi.DeviceStatusReq; pub const Mode = ansi.Mode; diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 5bf796a76..7dcc7e92d 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -307,6 +307,19 @@ pub fn Stream(comptime Handler: type) type { }, ) else log.warn("unimplemented CSI callback: {}", .{action}), + // DECSCUSR - Select Cursor Style + // TODO: test + 'q' => if (@hasDecl(T, "setCursorStyle")) try self.handler.setCursorStyle( + switch (action.params.len) { + 0 => ansi.CursorStyle.default, + 1 => @intToEnum(ansi.CursorStyle, action.params[0]), + else => { + log.warn("invalid set curor style command: {}", .{action}); + return; + }, + }, + ) else log.warn("unimplemented CSI callback: {}", .{action}), + // DECSTBM - Set Top and Bottom Margins // TODO: test 'r' => if (@hasDecl(T, "setTopAndBottomMargin")) switch (action.params.len) {