-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New custom print function to handle windows unicode #131
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
22badde
Jetzigg init direction update
z1fire 2f7687a
Merge branch 'jetzig-framework:main' into wip
z1fire f9d8ef3
update allow unicode images in windows terminal
z1fire 63cd638
Merge branch 'wip' of https://github.com/z1fire/jetzig into wip
z1fire 6cabafc
unicode for windows
z1fire be8e517
unicode for windows
z1fire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you flip this around you can use a guard clause to remove some indentation: if (builtin.os.tag != .windows) return .{ .original = {} };
// ... windows logic |
||
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); | ||
} | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this belongs in
cli/util.zig
- we already import this incli/commands/init.zig
.