File tree Expand file tree Collapse file tree 5 files changed +26
-2
lines changed Expand file tree Collapse file tree 5 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,8 @@ let terminalStateFunctions () =
118
118
startReading = (fun () -> () );
119
119
stopReading = (fun () -> () ) }
120
120
121
+ let termVtCapable fd = Unix. isatty fd
122
+
121
123
let has_stdout ~info :_ = true
122
124
let has_stderr ~info :_ = true
123
125
Original file line number Diff line number Diff line change @@ -115,6 +115,8 @@ type terminalStateFunctions =
115
115
startReading : unit -> unit ; stopReading : unit -> unit }
116
116
val terminalStateFunctions : unit -> terminalStateFunctions
117
117
118
+ val termVtCapable : Unix .file_descr -> bool
119
+
118
120
val has_stdout : info :string -> bool
119
121
val has_stderr : info :string -> bool
120
122
Original file line number Diff line number Diff line change @@ -199,5 +199,7 @@ let terminalStateFunctions () =
199
199
startReading = (fun () -> setConsoleMode 0x18 );
200
200
stopReading = (fun () -> setConsoleMode 0x19 ) }
201
201
202
+ external termVtCapable : Unix .file_descr -> bool = " win_vt_capable"
203
+
202
204
external has_stdout : info :string -> bool = " win_hasconsole_gui_stdout"
203
205
external has_stderr : info :string -> bool = " win_hasconsole_gui_stderr"
Original file line number Diff line number Diff line change @@ -591,3 +591,19 @@ CAMLprim value win_set_console_output_cp (value cp) {
591
591
}
592
592
CAMLreturn (Val_unit );
593
593
}
594
+
595
+ CAMLprim value win_vt_capable (value fd )
596
+ {
597
+ CAMLparam1 (fd );
598
+ DWORD mode ;
599
+
600
+ if (Handle_val (fd ) == INVALID_HANDLE_VALUE ) {
601
+ CAMLreturn (Val_int (0 ));
602
+ }
603
+
604
+ if (!GetConsoleMode (Handle_val (fd ), & mode )) {
605
+ CAMLreturn (Val_int (0 ));
606
+ }
607
+
608
+ CAMLreturn (Val_int (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING ));
609
+ }
Original file line number Diff line number Diff line change @@ -104,13 +104,15 @@ let setColorPreference () =
104
104
let envOk = try let _ = System. getenv " NO_COLOR" in false
105
105
with Not_found -> true
106
106
and termOk = try System. getenv " TERM" <> " dumb" with Not_found -> true
107
- and ttyOk = (Unix. isatty Unix. stdin ) && (Unix. isatty Unix. stderr) in
107
+ and ttyOk = (Unix. isatty Unix. stdout ) && (Unix. isatty Unix. stderr) in
108
108
let colorOk = envOk && termOk && ttyOk && not (Prefs. read dumbtty) in
109
109
colorEnabled :=
110
110
match Prefs. read colorMode with
111
111
| `True -> true
112
112
| `False -> false
113
- | `Default -> colorOk && Sys. os_type <> " Win32"
113
+ | `Default -> colorOk && (not Sys. win32
114
+ || (System. termVtCapable Unix. stdout
115
+ && System. termVtCapable Unix. stderr))
114
116
115
117
let color t =
116
118
if not ! colorEnabled then " " else
You can’t perform that action at this time.
0 commit comments