From 22badde8c04a29522d9948d0a60207d228816876 Mon Sep 17 00:00:00 2001 From: z1fire Date: Sat, 30 Nov 2024 07:18:06 -0500 Subject: [PATCH 1/4] Jetzigg init direction update --- cli/commands/init.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/commands/init.zig b/cli/commands/init.zig index 054f313..292d9f0 100644 --- a/cli/commands/init.zig +++ b/cli/commands/init.zig @@ -217,7 +217,7 @@ pub fn run( \\ \\ $ cd {s} \\ - \\ $ zig build run + \\ $ zig build run or jetzig server \\ \\And then browse to http://localhost:8080/ \\ From f9d8ef3776596c76dc17317b1faae22a5e6151f8 Mon Sep 17 00:00:00 2001 From: z1fire Date: Sat, 30 Nov 2024 15:13:02 -0500 Subject: [PATCH 2/4] update allow unicode images in windows terminal --- cli/commands/init.zig | 4 ++-- cli/commands/unicodeprint.zig | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 cli/commands/unicodeprint.zig diff --git a/cli/commands/init.zig b/cli/commands/init.zig index 292d9f0..53e11be 100644 --- a/cli/commands/init.zig +++ b/cli/commands/init.zig @@ -3,7 +3,7 @@ const args = @import("args"); const util = @import("../util.zig"); const cli = @import("../cli.zig"); - +const uPrint = @import("unicodeprint.zig"); const init_data = @import("init_data").init_data; /// Command line options for the `init` command. @@ -209,7 +209,7 @@ pub fn run( // const git_setup = false; // if (git_setup) try gitSetup(allocator, install_dir); - std.debug.print( + try uPrint.unicodePrint( \\ \\Setup complete! ✈️ 🦎 \\ diff --git a/cli/commands/unicodeprint.zig b/cli/commands/unicodeprint.zig new file mode 100644 index 0000000..2382c4e --- /dev/null +++ b/cli/commands/unicodeprint.zig @@ -0,0 +1,41 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +pub fn unicodePrint(comptime fmt: []const u8, args: anytype) !void { + if (builtin.os.tag == .windows) { + // Windows-specific code + const cp_out = try UTF8ConsoleOutput.init(); + defer cp_out.deinit(); + + std.debug.print(comptime fmt, args); + } else { + // Non-Windows platforms just print normally + std.debug.print(fmt, args); + } +} +const UTF8ConsoleOutput = struct { + original: if (builtin.os.tag == .windows) c_uint else void, + + fn init() !UTF8ConsoleOutput { + if (builtin.os.tag == .windows) { + const original = std.os.windows.kernel32.GetConsoleOutputCP(); + if (original == 0) { + return error.FailedToGetConsoleOutputCP; + } + const result = std.os.windows.kernel32.SetConsoleOutputCP(65001); // UTF-8 code page + if (result == 0) { + return error.FailedToSetConsoleOutputCP; + } + return .{ .original = original }; + } + // For non-Windows, return an empty struct + return .{ .original = {} }; + } + + fn deinit(self: UTF8ConsoleOutput) void { + if (builtin.os.tag == .windows) { + // Restore the original code page + _ = std.os.windows.kernel32.SetConsoleOutputCP(self.original); + } + } +}; From 6cabafc63fbb88052e160f6045f3fe3d6486b657 Mon Sep 17 00:00:00 2001 From: z1fire Date: Sat, 30 Nov 2024 15:31:36 -0500 Subject: [PATCH 3/4] unicode for windows --- cli/commands/init.zig | 2 +- cli/commands/{ => library}/unicodeprint.zig | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename cli/commands/{ => library}/unicodeprint.zig (100%) diff --git a/cli/commands/init.zig b/cli/commands/init.zig index 53e11be..85c30a7 100644 --- a/cli/commands/init.zig +++ b/cli/commands/init.zig @@ -3,7 +3,7 @@ const args = @import("args"); const util = @import("../util.zig"); const cli = @import("../cli.zig"); -const uPrint = @import("unicodeprint.zig"); +const uPrint = @import("library/unicodeprint.zig"); const init_data = @import("init_data").init_data; /// Command line options for the `init` command. diff --git a/cli/commands/unicodeprint.zig b/cli/commands/library/unicodeprint.zig similarity index 100% rename from cli/commands/unicodeprint.zig rename to cli/commands/library/unicodeprint.zig From be8e517a06c850715c2a60676fd56dc1b6aa017d Mon Sep 17 00:00:00 2001 From: z1fire Date: Sat, 30 Nov 2024 16:25:31 -0500 Subject: [PATCH 4/4] unicode for windows --- cli/commands/init.zig | 3 +- cli/commands/library/unicodeprint.zig | 41 --------------------------- cli/util.zig | 34 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 43 deletions(-) delete mode 100644 cli/commands/library/unicodeprint.zig diff --git a/cli/commands/init.zig b/cli/commands/init.zig index 85c30a7..9556661 100644 --- a/cli/commands/init.zig +++ b/cli/commands/init.zig @@ -3,7 +3,6 @@ const args = @import("args"); const util = @import("../util.zig"); const cli = @import("../cli.zig"); -const uPrint = @import("library/unicodeprint.zig"); const init_data = @import("init_data").init_data; /// Command line options for the `init` command. @@ -209,7 +208,7 @@ pub fn run( // const git_setup = false; // if (git_setup) try gitSetup(allocator, install_dir); - try uPrint.unicodePrint( + try util.unicodePrint( \\ \\Setup complete! ✈️ 🦎 \\ diff --git a/cli/commands/library/unicodeprint.zig b/cli/commands/library/unicodeprint.zig deleted file mode 100644 index 2382c4e..0000000 --- a/cli/commands/library/unicodeprint.zig +++ /dev/null @@ -1,41 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); - -pub fn unicodePrint(comptime fmt: []const u8, args: anytype) !void { - if (builtin.os.tag == .windows) { - // Windows-specific code - const cp_out = try UTF8ConsoleOutput.init(); - defer cp_out.deinit(); - - std.debug.print(comptime fmt, args); - } else { - // Non-Windows platforms just print normally - std.debug.print(fmt, args); - } -} -const UTF8ConsoleOutput = struct { - original: if (builtin.os.tag == .windows) c_uint else void, - - fn init() !UTF8ConsoleOutput { - if (builtin.os.tag == .windows) { - const original = std.os.windows.kernel32.GetConsoleOutputCP(); - if (original == 0) { - return error.FailedToGetConsoleOutputCP; - } - const result = std.os.windows.kernel32.SetConsoleOutputCP(65001); // UTF-8 code page - if (result == 0) { - return error.FailedToSetConsoleOutputCP; - } - return .{ .original = original }; - } - // For non-Windows, return an empty struct - return .{ .original = {} }; - } - - fn deinit(self: UTF8ConsoleOutput) void { - if (builtin.os.tag == .windows) { - // Restore the original code page - _ = std.os.windows.kernel32.SetConsoleOutputCP(self.original); - } - } -}; diff --git a/cli/util.zig b/cli/util.zig index fb37f16..c4cb30f 100644 --- a/cli/util.zig +++ b/cli/util.zig @@ -289,3 +289,37 @@ pub fn environmentBuildOption(environment: cli.Environment) []const u8 { inline else => |tag| "-Denvironment=" ++ @tagName(tag), }; } + + + +pub fn unicodePrint(comptime fmt: []const u8, args: anytype) !void { + if (builtin.os.tag == .windows) { + // Windows-specific code + const cp_out = try UTF8ConsoleOutput.init(); + defer cp_out.deinit(); + + std.debug.print(comptime fmt, args); + } else { + // Non-Windows platforms just print normally + std.debug.print(fmt, args); + } +} +const UTF8ConsoleOutput = struct { + original: c_uint, + + fn init() !UTF8ConsoleOutput { + const original = std.os.windows.kernel32.GetConsoleOutputCP(); + if (original == 0) { + return error.FailedToGetConsoleOutputCP; + } + const result = std.os.windows.kernel32.SetConsoleOutputCP(65001); // UTF-8 code page + if (result == 0) { + return error.FailedToSetConsoleOutputCP; + } + return .{ .original = original }; + } + + fn deinit(self: UTF8ConsoleOutput) void { + _ = std.os.windows.kernel32.SetConsoleOutputCP(self.original); + } +}; \ No newline at end of file