diff --git a/src/config.zig b/src/config.zig index d9a0291d3..8a4d64fae 100644 --- a/src/config.zig +++ b/src/config.zig @@ -36,6 +36,16 @@ pub const Config = struct { /// Foreground color for the window. foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF }, + /// Color palette for the 256 color form that many terminal applications + /// use. The syntax of this configuration is "N=HEXCODE" where "n" + /// is 0 to 255 (for the 256 colors) and HEXCODE is a typical RGB + /// color code such as "#AABBCC". The 0 to 255 correspond to the + /// terminal color table. + /// + /// For definitions on all the codes: + /// https://www.ditig.com/256-colors-cheat-sheet + palette: Palette = .{}, + /// The command to run, usually a shell. If this is not an absolute path, /// it'll be looked up in the PATH. If this is not set, a default will /// be looked up from your system. The rules for the default lookup are: diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 738e876e9..91b1ac21d 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -60,6 +60,9 @@ scrolling_region: ScrollingRegion, /// The charset state charset: CharsetState = .{}, +/// The color palette to use +color_palette: color.Palette = color.default, + /// The previous printed character. This is used for the repeat previous /// char CSI (ESC [ b). previous_char: ?u21 = null, @@ -429,12 +432,12 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void { .@"8_fg" => |n| { self.screen.cursor.pen.attrs.has_fg = true; - self.screen.cursor.pen.fg = color.default[@enumToInt(n)]; + self.screen.cursor.pen.fg = self.color_palette[@enumToInt(n)]; }, .@"8_bg" => |n| { self.screen.cursor.pen.attrs.has_bg = true; - self.screen.cursor.pen.bg = color.default[@enumToInt(n)]; + self.screen.cursor.pen.bg = self.color_palette[@enumToInt(n)]; }, .reset_fg => self.screen.cursor.pen.attrs.has_fg = false, @@ -443,22 +446,22 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void { .@"8_bright_fg" => |n| { self.screen.cursor.pen.attrs.has_fg = true; - self.screen.cursor.pen.fg = color.default[@enumToInt(n)]; + self.screen.cursor.pen.fg = self.color_palette[@enumToInt(n)]; }, .@"8_bright_bg" => |n| { self.screen.cursor.pen.attrs.has_bg = true; - self.screen.cursor.pen.bg = color.default[@enumToInt(n)]; + self.screen.cursor.pen.bg = self.color_palette[@enumToInt(n)]; }, .@"256_fg" => |idx| { self.screen.cursor.pen.attrs.has_fg = true; - self.screen.cursor.pen.fg = color.default[idx]; + self.screen.cursor.pen.fg = self.color_palette[idx]; }, .@"256_bg" => |idx| { self.screen.cursor.pen.attrs.has_bg = true; - self.screen.cursor.pen.bg = color.default[idx]; + self.screen.cursor.pen.bg = self.color_palette[idx]; }, .unknown => return error.InvalidAttribute, diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index e8828fd56..deea06466 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -107,8 +107,13 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec { log.info("started subcommand path={s} pid={?}", .{ path, cmd.pid }); // Create our terminal - var term = try terminal.Terminal.init(alloc, opts.grid_size.columns, opts.grid_size.rows); + var term = try terminal.Terminal.init( + alloc, + opts.grid_size.columns, + opts.grid_size.rows, + ); errdefer term.deinit(alloc); + term.color_palette = opts.config.palette.value; return Exec{ .alloc = alloc,