Skip to content

Commit 33081e5

Browse files
authored
Merge pull request #5970 from kit-ty-kate/windows-utf8
UTF-8 paged --help on Windows
2 parents ff1c97b + e490a0e commit 33081e5

File tree

7 files changed

+22
-3
lines changed

7 files changed

+22
-3
lines changed

master_changes.md

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ users)
1717

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

2122
## Plugins
2223

@@ -89,6 +90,7 @@ users)
8990
## VCS
9091

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

9395
## Infrastructure
9496
* Ensure GNU coreutils available on the macOS 14 CI runners [#5938 @dra27]
@@ -115,6 +117,7 @@ users)
115117
## Internal
116118

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

119122
## Test
120123

src/client/opamCliMain.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,11 @@ let json_out () =
483483
(Printexc.to_string e)
484484

485485
let main () =
486-
if Sys.win32 then
486+
if Sys.win32 then begin
487487
(* Disable the critical error handling dialog *)
488488
ignore (OpamStubs.setErrorMode (1 lor OpamStubs.getErrorMode ()));
489+
OpamStubs.setConsoleToUTF8 ();
490+
end;
489491
OpamStd.Sys.at_exit (fun () ->
490492
flush_all_noerror ();
491493
if OpamClientConfig.(!r.print_stats) then (

src/core/opamStubs.dummy.ml

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ let win_create_process _ _ _ _ _ = that's_a_no_no
4141
let getConsoleWindowClass = that's_a_no_no
4242
let setErrorMode = that's_a_no_no
4343
let getErrorMode = that's_a_no_no
44+
let setConsoleToUTF8 = that's_a_no_no

src/core/opamStubs.mli

+3
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,6 @@ val setErrorMode : int -> int
142142

143143
val getErrorMode : unit -> int
144144
(** Windows only. Directly wraps GetErrorMode. *)
145+
146+
val setConsoleToUTF8 : unit -> unit
147+
(** Windows only. Directly wraps SetConsoleOutputCP(CP_UTF8). *)

src/stubs/win32/opamWin32Stubs.ml

+1
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ external getConsoleAlias : string -> string -> string = "OPAMW_GetConsoleAlias"
3939
external getConsoleWindowClass : unit -> string option = "OPAMW_GetConsoleWindowClass"
4040
external setErrorMode : int -> int = "OPAMW_SetErrorMode"
4141
external getErrorMode : unit -> int = "OPAMW_GetErrorMode"
42+
external setConsoleToUTF8 : unit -> unit = "OPAMW_SetConsoleToUTF8"

src/stubs/win32/opamWindows.c

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <TlHelp32.h>
2929
#include <Knownfolders.h>
3030
#include <Objbase.h>
31+
#include <WinCon.h>
3132

3233
#include <stdio.h>
3334

@@ -795,3 +796,11 @@ CAMLprim value OPAMW_GetErrorMode(value mode)
795796
{
796797
return Val_int(GetErrorMode());
797798
}
799+
800+
CAMLprim value OPAMW_SetConsoleToUTF8(value _unit) {
801+
/* NOTE: Setting Input (SetConsoleCP) is necessary for more.com
802+
* called by cmdliner to correctly output UTF-8 characters */
803+
SetConsoleCP(CP_UTF8);
804+
SetConsoleOutputCP(CP_UTF8);
805+
return Val_unit;
806+
}

src_ext/Makefile.sources

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ MD5_re = e0199e32947fd33fcc1b8e69de2308a1
1818

1919
$(call PKG_SAME,re)
2020

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

2424
$(call PKG_SAME,cmdliner)
2525

0 commit comments

Comments
 (0)