Skip to content

fix: UTF-8 console output on Windows (Issue #201) - #216

Merged
vmvarela merged 2 commits into
masterfrom
fix/utf8-console-windows-201
Aug 2, 2026
Merged

fix: UTF-8 console output on Windows (Issue #201)#216
vmvarela merged 2 commits into
masterfrom
fix/utf8-console-windows-201

Conversation

@vmvarela

@vmvarela vmvarela commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Implements SetConsoleOutputCP(65001) and ENABLE_VIRTUAL_TERMINAL_PROCESSING on Windows startup so --table box-drawing characters render correctly in default cmd.exe.

Changes

  • src/main.zig: Added Windows API extern declarations for SetConsoleOutputCP, GetStdHandle, GetConsoleMode, SetConsoleMode
  • src/main.zig: Added setupConsoleOutput() function (compile-time gated on Windows)
  • src/main.zig: Call setupConsoleOutput() at startup in main() before any I/O

Implementation Details

  • Uses extern "kernel32" with callconv(.winapi) — no new dependencies
  • Compile-time conditional via @import("builtin").os.tag == .windows — zero overhead on non-Windows
  • Best-effort: ignores return values per issue scope (no-op on failure)
  • Fixed STD_OUTPUT_HANDLE = -11 bug (u32 can't hold -11) → @bitCast(@as(i32, -11))
  • Fix: Inlined std.os.windows types directly (removed intermediate windows import)
  • Fix: Added comment // 0xFFFFFFF5 for readability
  • Fix: Added INVALID_HANDLE_VALUE check — guards against redirected stdout where GetStdHandle returns invalid handle

Testing

  • zig build (native) succeeds
  • zig build -Dtarget=x86_64-windows-gnu -Dbundle-sqlite=true succeeds
  • zig build -Dtarget=x86-windows-gnu -Dbundle-sqlite=true succeeds
  • zig build -Dtarget=aarch64-windows-gnu -Dbundle-sqlite=true fails — pre-existing carquet/arocc issue unrelated to this change

Oracle Reviews

All 3 phases reviewed and approved:

  1. Phase 1: Extern declarations — fixed STD_OUTPUT_HANDLE bug
  2. Phase 2: setupConsoleOutput() function — correct implementation
  3. Phase 3: Call in main() — correct placement

Closes #201

Add setupConsoleOutput() calling SetConsoleOutputCP(65001) and
SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING on Windows
startup. Compile-time gated via builtin.os.tag. No-op on non-Windows.

Closes #201
@github-actions github-actions Bot added the type:bug Something isn't working label Aug 2, 2026
@vmvarela vmvarela changed the title Fix: UTF-8 console output on Windows (Issue #201) fix: UTF-8 console output on Windows (Issue #201) Aug 2, 2026
@vmvarela
vmvarela merged commit 390bbba into master Aug 2, 2026
6 checks passed
@vmvarela
vmvarela deleted the fix/utf8-console-windows-201 branch August 2, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: UTF-8 console output on Windows (affects --table box-drawing)

1 participant