Skip to content

Commit

Permalink
core: reset cursor and sgr in resetState
Browse files Browse the repository at this point in the history
Move code to reset cursor and sgr state into `resetState` from `deinit`.

Fixes: #98
  • Loading branch information
rockorager committed Oct 30, 2024
1 parent a228e3e commit 7fa0482
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Vaxis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ pub fn init(alloc: std.mem.Allocator, opts: Options) !Vaxis {
pub fn deinit(self: *Vaxis, alloc: ?std.mem.Allocator, tty: AnyWriter) void {
self.resetState(tty) catch {};

// always show the cursor on exit
tty.writeAll(ctlseqs.show_cursor) catch {};
tty.writeAll(ctlseqs.sgr_reset) catch {};
if (self.screen.cursor_shape != .default) {
// In many terminals, `.default` will set to the configured cursor shape. Others, it will
// change to a blinking block.
tty.print(ctlseqs.cursor_shape, .{@intFromEnum(Cell.CursorShape.default)}) catch {};
}
if (alloc) |a| {
self.screen.deinit(a);
self.screen_last.deinit(a);
Expand All @@ -125,6 +117,14 @@ pub fn deinit(self: *Vaxis, alloc: ?std.mem.Allocator, tty: AnyWriter) void {

/// resets enabled features, sends cursor to home and clears below cursor
pub fn resetState(self: *Vaxis, tty: AnyWriter) !void {
// always show the cursor on state reset
tty.writeAll(ctlseqs.show_cursor) catch {};
tty.writeAll(ctlseqs.sgr_reset) catch {};
if (self.screen.cursor_shape != .default) {
// In many terminals, `.default` will set to the configured cursor shape. Others, it will
// change to a blinking block.
tty.print(ctlseqs.cursor_shape, .{@intFromEnum(Cell.CursorShape.default)}) catch {};
}
if (self.state.kitty_keyboard) {
try tty.writeAll(ctlseqs.csi_u_pop);
self.state.kitty_keyboard = false;
Expand Down

0 comments on commit 7fa0482

Please sign in to comment.