feat: set terminal background to match editor

This commit is contained in:
CJ van den Berg 2024-08-12 23:24:10 +02:00
parent 953fc8535c
commit 7f0f8c9ed3
3 changed files with 16 additions and 2 deletions

View file

@ -29,8 +29,8 @@
.hash = "122019f077d09686b1ec47928ca2b4bf264422f3a27afc5b49dafb0129a4ceca0d01",
},
.vaxis = .{
.url = "https://github.com/rockorager/libvaxis/archive/22516a971c0c391c6464d1c39e114c286adb02de.tar.gz",
.hash = "12203ae4ac20a34f45bace1e73c16a7779cae45d53e8f168909bb6f6e224408a6884",
.url = "https://github.com/neurocyte/libvaxis/archive/6a40aa02c8130b34ded52f5ea7e636eb52e589b7.tar.gz",
.hash = "122053de0d1b7692e0eb01768abace0d512a4a23285cc0abc38b74f121ecad64f00d",
},
},
.paths = .{

View file

@ -322,6 +322,17 @@ pub fn set_terminal_title(self: *Self, text: []const u8) void {
self.vx.setTitle(self.tty.anyWriter(), text) catch {};
}
pub fn set_terminal_style(self: *Self, style_: Style) void {
if (style_.fg) |color|
self.vx.setTerminalForegroundColor(self.tty.anyWriter(), vaxis.Cell.Color.rgbFromUint(@intCast(color)).rgb) catch {};
if (style_.bg) |color|
self.vx.setTerminalBackgroundColor(self.tty.anyWriter(), vaxis.Cell.Color.rgbFromUint(@intCast(color)).rgb) catch {};
const bg = vaxis.Cell.Color.rgbFromUint(@intCast(style_.bg.?)).rgb;
self.logger.print(vaxis.ctlseqs.osc11_set, .{ bg[0], bg[0], bg[1], bg[1], bg[2], bg[2] });
self.logger.print("bg: {any}", .{style_.bg.?});
self.vx.state.changed_default_bg = false;
}
pub fn copy_to_system_clipboard(self: *Self, text: []const u8) void {
var bufferedWriter = self.tty.bufferedWriter();
self.vx.copyToSystemClipboard(bufferedWriter.writer().any(), text, self.a) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e);

View file

@ -134,6 +134,7 @@ fn init(a: Allocator) !*Self {
}
self.mainview = try mainview.create(a, n);
self.resize();
self.rdr.set_terminal_style(self.theme.editor);
try self.rdr.render();
try self.save_config();
if (tp.env.get().is("restore-session")) {
@ -523,6 +524,7 @@ const cmds = struct {
pub fn theme_next(self: *Self, _: Ctx) Result {
self.theme = get_next_theme_by_name(self.theme.name);
self.config.theme = self.theme.name;
self.rdr.set_terminal_style(self.theme.editor);
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}
@ -530,6 +532,7 @@ const cmds = struct {
pub fn theme_prev(self: *Self, _: Ctx) Result {
self.theme = get_prev_theme_by_name(self.theme.name);
self.config.theme = self.theme.name;
self.rdr.set_terminal_style(self.theme.editor);
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}