Windows compatibility fixes

This commit is contained in:
Bob Farrell 2024-06-01 18:05:01 +01:00
parent a6c3e77ddc
commit b304a3509b
3 changed files with 48 additions and 27 deletions

View File

@ -23,8 +23,8 @@
.hash = "1220d4f1c2472769b0d689ea878f41f0a66cb07f28569a138aea2c0a648a5c90dd4e", .hash = "1220d4f1c2472769b0d689ea878f41f0a66cb07f28569a138aea2c0a648a5c90dd4e",
}, },
.httpz = .{ .httpz = .{
.url = "https://github.com/karlseguin/http.zig/archive/f3ad561fd23262c3f9b8081ff7bb8a5ded0e74bd.tar.gz", .url = "https://github.com/karlseguin/http.zig/archive/12764925eb6a7929004c1be9032b04f97f4e43e2.tar.gz",
.hash = "1220ea0d5860657d59cf1ca0fe0e553bfabc7d9cd467005488155baffb1ddf65ecf2", .hash = "1220ffb589c6cd1a040bfd4446c74c38b5e873ba82e737cb33c98711c95787b92c81",
}, },
}, },

View File

@ -31,7 +31,8 @@ pub const codes = .{
/// Map color codes generated by `std.io.tty.Config.setColor` back to `std.io.tty.Color`. Used by /// Map color codes generated by `std.io.tty.Config.setColor` back to `std.io.tty.Color`. Used by
/// `jetzig.loggers.LogQueue.writeWindows` to parse escape codes so they can be passed to /// `jetzig.loggers.LogQueue.writeWindows` to parse escape codes so they can be passed to
/// `std.io.tty.Config.setColor` (using Windows API to set console color mode). /// `std.io.tty.Config.setColor` (using Windows API to set console color mode).
pub const codes_map = std.StaticStringMap(std.io.tty.Color).initComptime(.{ const codes_map = if (@hasDecl(std, "ComptimeStringMap"))
std.ComptimeStringMap(std.io.tty.Color, .{
.{ "30", .black }, .{ "30", .black },
.{ "31", .red }, .{ "31", .red },
.{ "32", .green }, .{ "32", .green },
@ -51,7 +52,31 @@ pub const codes_map = std.StaticStringMap(std.io.tty.Color).initComptime(.{
.{ "1", .bold }, .{ "1", .bold },
.{ "2", .dim }, .{ "2", .dim },
.{ "0", .reset }, .{ "0", .reset },
}); })
else if (@hasDecl(std, "StaticStringMap"))
std.StaticStringMap(std.io.tty.Color).initComptime(.{
.{ "30", .black },
.{ "31", .red },
.{ "32", .green },
.{ "33", .yellow },
.{ "34", .blue },
.{ "35", .magenta },
.{ "36", .cyan },
.{ "37", .white },
.{ "90", .bright_black },
.{ "91", .bright_red },
.{ "92", .bright_green },
.{ "93", .bright_yellow },
.{ "94", .bright_blue },
.{ "95", .bright_magenta },
.{ "96", .bright_cyan },
.{ "97", .bright_white },
.{ "1", .bold },
.{ "2", .dim },
.{ "0", .reset },
})
else
unreachable;
/// Colorize a log message. Note that we force `.escape_codes` when we are a TTY even on Windows. /// Colorize a log message. Note that we force `.escape_codes` when we are a TTY even on Windows.
/// `jetzig.loggers.LogQueue` parses the ANSI codes and uses `std.io.tty.Config.setColor` to /// `jetzig.loggers.LogQueue` parses the ANSI codes and uses `std.io.tty.Config.setColor` to

View File

@ -70,7 +70,3 @@ pub fn generateSecret(allocator: std.mem.Allocator, comptime len: u10) ![]const
pub fn duration(start_time: i128) i64 { pub fn duration(start_time: i128) i64 {
return @intCast(std.time.nanoTimestamp() - start_time); return @intCast(std.time.nanoTimestamp() - start_time);
} }
pub inline fn strip(string: []const u8) []const u8 {
return std.mem.trim(u8, string, &std.ascii.whitespace);
}