From f8c8d3d606d60c69f90d858c00d2c9d352b8c5de Mon Sep 17 00:00:00 2001 From: Kate Date: Thu, 23 May 2024 17:51:22 +0100 Subject: [PATCH 1/2] Upgrade vendored cmdliner to 1.3.0 (fix support of paging on Windows) --- master_changes.md | 1 + src_ext/Makefile.sources | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/master_changes.md b/master_changes.md index 661c27174d5..ffb8a05036e 100644 --- a/master_changes.md +++ b/master_changes.md @@ -88,6 +88,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] diff --git a/src_ext/Makefile.sources b/src_ext/Makefile.sources index 7c343e325ef..62857412561 100644 --- a/src_ext/Makefile.sources +++ b/src_ext/Makefile.sources @@ -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) From e490a0e01699a0d7d6a1a27dbeecdc77a5642fe6 Mon Sep 17 00:00:00 2001 From: Kate Date: Thu, 23 May 2024 17:15:05 +0100 Subject: [PATCH 2/2] Set the console to use UTF-8 on Windows --- master_changes.md | 2 ++ src/client/opamCliMain.ml | 4 +++- src/core/opamStubs.dummy.ml | 1 + src/core/opamStubs.mli | 3 +++ src/stubs/win32/opamWin32Stubs.ml | 1 + src/stubs/win32/opamWindows.c | 9 +++++++++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/master_changes.md b/master_changes.md index ffb8a05036e..ac8c96377af 100644 --- a/master_changes.md +++ b/master_changes.md @@ -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 @@ -115,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 diff --git a/src/client/opamCliMain.ml b/src/client/opamCliMain.ml index 642cc0fbf30..2ddf5ff7b3e 100644 --- a/src/client/opamCliMain.ml +++ b/src/client/opamCliMain.ml @@ -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 ( diff --git a/src/core/opamStubs.dummy.ml b/src/core/opamStubs.dummy.ml index ccc044ef301..34d3924a49c 100644 --- a/src/core/opamStubs.dummy.ml +++ b/src/core/opamStubs.dummy.ml @@ -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 diff --git a/src/core/opamStubs.mli b/src/core/opamStubs.mli index e9075fc98cf..41303e4f949 100644 --- a/src/core/opamStubs.mli +++ b/src/core/opamStubs.mli @@ -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). *) diff --git a/src/stubs/win32/opamWin32Stubs.ml b/src/stubs/win32/opamWin32Stubs.ml index b5911f9dbd7..d1d06d7ff18 100644 --- a/src/stubs/win32/opamWin32Stubs.ml +++ b/src/stubs/win32/opamWin32Stubs.ml @@ -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" diff --git a/src/stubs/win32/opamWindows.c b/src/stubs/win32/opamWindows.c index 5d6e6c46d15..1487bcdcde3 100644 --- a/src/stubs/win32/opamWindows.c +++ b/src/stubs/win32/opamWindows.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -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; +}