Skip to content
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

UTF-8 paged --help on Windows #5970

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ users)

## Global CLI
* Fix a typo in the variable description returned by "opam var" [#5961 @jmid]
* Out-of-the-box UTF-8 paged --help on Windows [#5970 @kit-ty-kate]

## Plugins

Expand Down Expand Up @@ -88,6 +89,7 @@ users)
## VCS

## Build
* Upgrade vendored cmdliner to 1.3.0 [#5970 @kit-ty-kate]

## Infrastructure
* Ensure GNU coreutils available on the macOS 14 CI runners [#5938 @dra27]
Expand All @@ -114,6 +116,7 @@ users)
## Internal

## Internal: Windows
* Set the console to use UTF-8 on Windows using SetConsoleCP and SetConsoleOutputCP [#5970 @kit-ty-kate]

## Test

Expand Down
4 changes: 3 additions & 1 deletion src/client/opamCliMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,11 @@ let json_out () =
(Printexc.to_string e)

let main () =
if Sys.win32 then
if Sys.win32 then begin
(* Disable the critical error handling dialog *)
ignore (OpamStubs.setErrorMode (1 lor OpamStubs.getErrorMode ()));
OpamStubs.setConsoleToUTF8 ();
end;
OpamStd.Sys.at_exit (fun () ->
flush_all_noerror ();
if OpamClientConfig.(!r.print_stats) then (
Expand Down
1 change: 1 addition & 0 deletions src/core/opamStubs.dummy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ let win_create_process _ _ _ _ _ = that's_a_no_no
let getConsoleWindowClass = that's_a_no_no
let setErrorMode = that's_a_no_no
let getErrorMode = that's_a_no_no
let setConsoleToUTF8 = that's_a_no_no
3 changes: 3 additions & 0 deletions src/core/opamStubs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ val setErrorMode : int -> int

val getErrorMode : unit -> int
(** Windows only. Directly wraps GetErrorMode. *)

val setConsoleToUTF8 : unit -> unit
(** Windows only. Directly wraps SetConsoleOutputCP(CP_UTF8). *)
1 change: 1 addition & 0 deletions src/stubs/win32/opamWin32Stubs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ external getConsoleAlias : string -> string -> string = "OPAMW_GetConsoleAlias"
external getConsoleWindowClass : unit -> string option = "OPAMW_GetConsoleWindowClass"
external setErrorMode : int -> int = "OPAMW_SetErrorMode"
external getErrorMode : unit -> int = "OPAMW_GetErrorMode"
external setConsoleToUTF8 : unit -> unit = "OPAMW_SetConsoleToUTF8"
9 changes: 9 additions & 0 deletions src/stubs/win32/opamWindows.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <TlHelp32.h>
#include <Knownfolders.h>
#include <Objbase.h>
#include <WinCon.h>

#include <stdio.h>

Expand Down Expand Up @@ -795,3 +796,11 @@ CAMLprim value OPAMW_GetErrorMode(value mode)
{
return Val_int(GetErrorMode());
}

CAMLprim value OPAMW_SetConsoleToUTF8(value _unit) {
/* NOTE: Setting Input (SetConsoleCP) is necessary for more.com
* called by cmdliner to correctly output UTF-8 characters */
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
return Val_unit;
}
4 changes: 2 additions & 2 deletions src_ext/Makefile.sources
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ MD5_re = e0199e32947fd33fcc1b8e69de2308a1

$(call PKG_SAME,re)

URL_cmdliner = https://erratique.ch/software/cmdliner/releases/cmdliner-1.2.0.tbz
MD5_cmdliner = b860881cc90c68b703dca0f35bdd4cdb
URL_cmdliner = https://erratique.ch/software/cmdliner/releases/cmdliner-1.3.0.tbz
MD5_cmdliner = 662936095a1613d7254815238e11793f

$(call PKG_SAME,cmdliner)

Expand Down
Loading