Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 1c841a3

Browse files
authored
enable ENABLE_VIRTUAL_TERMINAL_PROCESSING (#178)
1 parent 091d668 commit 1c841a3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Display.zig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ const uri = @import("uri");
55

66
const assert = std.debug.assert;
77

8+
const is_windows = builtin.os.tag == .windows;
9+
10+
const w32 = if (is_windows) struct {
11+
extern "kernel32" fn SetConsoleMode(console: ?*anyopaque, mode: std.os.windows.DWORD) callconv(std.os.windows.WINAPI) u32;
12+
} else undefined;
13+
14+
var w32_mode: if (is_windows) std.os.windows.DWORD else void = undefined;
15+
816
pub const Size = struct {
917
rows: usize,
1018
cols: usize,
@@ -131,6 +139,12 @@ pub fn init(location: *Self, allocator: std.mem.Allocator) !void {
131139

132140
size.rows = @intCast(usize, csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
133141
size.cols = @intCast(usize, csbi.srWindow.Right - csbi.srWindow.Left + 1);
142+
143+
const h = c.GetStdHandle(c.STD_OUTPUT_HANDLE);
144+
if (c.GetConsoleMode(h, &w32_mode) != 0) {
145+
w32_mode |= c.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
146+
w32_mode = w32.SetConsoleMode(h, w32_mode);
147+
}
134148
},
135149
else => {
136150
const c = @cImport({
@@ -208,6 +222,14 @@ pub fn deinit(self: *Self) void {
208222
ansi.arena.deinit();
209223
},
210224
}
225+
226+
if (builtin.os.tag == .windows) {
227+
const c = @cImport({
228+
@cInclude("windows.h");
229+
});
230+
const h = c.GetStdHandle(c.STD_OUTPUT_HANDLE);
231+
_ = w32.SetConsoleMode(h, w32_mode);
232+
}
211233
}
212234

213235
pub fn log(

0 commit comments

Comments
 (0)