mod(terminal): write tui to stdout; log messages to stderr

This commit is contained in:
2024-11-06 17:10:24 +01:00
parent 4ded0210ee
commit 7cfe632c33

View File

@@ -26,32 +26,32 @@ pub const ReportMode = enum {
/// Gets number of rows and columns in the terminal
pub fn getTerminalSize() Size {
var ws: std.posix.winsize = undefined;
_ = std.posix.system.ioctl(std.posix.STDERR_FILENO, std.posix.T.IOCGWINSZ, &ws);
_ = std.posix.system.ioctl(std.posix.STDIN_FILENO, std.posix.T.IOCGWINSZ, &ws);
return .{ .cols = ws.ws_col, .rows = ws.ws_row };
}
pub fn saveScreen() !void {
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[?47h");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[?47h");
}
pub fn restoreScreen() !void {
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[?47l");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[?47l");
}
pub fn enterAltScreen() !void {
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[?1049h");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[?1049h");
}
pub fn existAltScreen() !void {
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[?1049l");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[?1049l");
}
pub fn clearScreen() !void {
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[2J");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[2J");
}
pub fn setCursorPositionHome() !void {
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[H");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[H");
}
pub fn read(buf: []u8) !usize {
@@ -59,13 +59,13 @@ pub fn read(buf: []u8) !usize {
}
pub fn write(buf: []const u8) !usize {
return try std.posix.write(std.posix.STDERR_FILENO, buf);
return try std.posix.write(std.posix.STDIN_FILENO, buf);
}
pub fn getCursorPosition() !Position {
// Needs Raw mode (no wait for \n) to work properly cause
// control sequence will not be written without it.
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[6n");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[6n");
var buf: [64]u8 = undefined;
@@ -165,7 +165,7 @@ pub fn disableRawMode(bak: *std.posix.termios) !void {
pub fn canSynchornizeOutput() !bool {
// Needs Raw mode (no wait for \n) to work properly cause
// control sequence will not be written without it.
_ = try std.posix.write(std.posix.STDERR_FILENO, "\x1b[?2026$p");
_ = try std.posix.write(std.posix.STDIN_FILENO, "\x1b[?2026$p");
var buf: [64]u8 = undefined;