mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 22:16:08 +00:00
unicode for windows
This commit is contained in:
parent
6cabafc63f
commit
be8e517a06
@ -3,7 +3,6 @@ const args = @import("args");
|
|||||||
|
|
||||||
const util = @import("../util.zig");
|
const util = @import("../util.zig");
|
||||||
const cli = @import("../cli.zig");
|
const cli = @import("../cli.zig");
|
||||||
const uPrint = @import("library/unicodeprint.zig");
|
|
||||||
const init_data = @import("init_data").init_data;
|
const init_data = @import("init_data").init_data;
|
||||||
|
|
||||||
/// Command line options for the `init` command.
|
/// Command line options for the `init` command.
|
||||||
@ -209,7 +208,7 @@ pub fn run(
|
|||||||
// const git_setup = false;
|
// const git_setup = false;
|
||||||
// if (git_setup) try gitSetup(allocator, install_dir);
|
// if (git_setup) try gitSetup(allocator, install_dir);
|
||||||
|
|
||||||
try uPrint.unicodePrint(
|
try util.unicodePrint(
|
||||||
\\
|
\\
|
||||||
\\Setup complete! ✈️ 🦎
|
\\Setup complete! ✈️ 🦎
|
||||||
\\
|
\\
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
34
cli/util.zig
34
cli/util.zig
@ -289,3 +289,37 @@ pub fn environmentBuildOption(environment: cli.Environment) []const u8 {
|
|||||||
inline else => |tag| "-Denvironment=" ++ @tagName(tag),
|
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);
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user