Hack to force OCaml to use colors when possible
This commit is contained in:
parent
aa5c4078f7
commit
d696bd113b
|
@ -107,3 +107,27 @@ let strip str =
|
||||||
| _ -> skip (i + 1)
|
| _ -> skip (i + 1)
|
||||||
in
|
in
|
||||||
loop 0
|
loop 0
|
||||||
|
|
||||||
|
let stderr_supports_colors = lazy(
|
||||||
|
not Sys.win32 &&
|
||||||
|
Unix.(isatty stderr) &&
|
||||||
|
match Sys.getenv "TERM" with
|
||||||
|
| exception Not_found -> false
|
||||||
|
| "dumb" -> false
|
||||||
|
| _ -> true
|
||||||
|
)
|
||||||
|
|
||||||
|
(* We redirect the output of all commands, so by default the compiler will disable
|
||||||
|
colors. Since we support colors in the output of commands, we force it via OCAMLPARAM
|
||||||
|
if stderr supports colors. *)
|
||||||
|
let setup_env_for_ocaml_colors = lazy(
|
||||||
|
if Lazy.force stderr_supports_colors then begin
|
||||||
|
let value =
|
||||||
|
match Sys.getenv "OCAMLPARAM" with
|
||||||
|
| exception Not_found -> "color=always,_"
|
||||||
|
| s -> "color=always," ^ s
|
||||||
|
in
|
||||||
|
Unix.putenv "OCAMLPARAM" value
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
val colorize : key:string -> string -> string
|
val colorize : key:string -> string -> string
|
||||||
val strip : string -> string
|
val strip : string -> string
|
||||||
|
val stderr_supports_colors : bool Lazy.t
|
||||||
|
val setup_env_for_ocaml_colors : unit Lazy.t
|
||||||
|
|
|
@ -210,7 +210,9 @@ let create ~(kind : Kind.t) ~path ~env =
|
||||||
all_known := String_map.add !all_known ~key:name ~data:t;
|
all_known := String_map.add !all_known ~key:name ~data:t;
|
||||||
return t
|
return t
|
||||||
|
|
||||||
let initial_env = lazy (Unix.environment ())
|
let initial_env = lazy (
|
||||||
|
Lazy.force Ansi_color.setup_env_for_ocaml_colors;
|
||||||
|
Unix.environment ())
|
||||||
|
|
||||||
let default = lazy (
|
let default = lazy (
|
||||||
let env = Lazy.force initial_env in
|
let env = Lazy.force initial_env in
|
||||||
|
|
|
@ -214,17 +214,20 @@ module Scheduler = struct
|
||||||
| None -> s
|
| None -> s
|
||||||
| Some dir -> sprintf "(cd %s && %s)" dir s
|
| Some dir -> sprintf "(cd %s && %s)" dir s
|
||||||
|
|
||||||
let strip_colors_for_stderr =
|
let stderr_supports_colors = lazy(
|
||||||
let strip = lazy (
|
not Sys.win32 &&
|
||||||
Sys.win32 ||
|
Unix.(isatty stderr) &&
|
||||||
not (Unix.(isatty stderr)) ||
|
match Sys.getenv "TERM" with
|
||||||
match Sys.getenv "TERM" with
|
| exception Not_found -> false
|
||||||
| exception Not_found -> true
|
| "dumb" -> false
|
||||||
| "dumb" -> true
|
| _ -> true
|
||||||
| _ -> false
|
)
|
||||||
) in
|
|
||||||
fun s ->
|
let strip_colors_for_stderr s =
|
||||||
if Lazy.force strip then Ansi_color.strip s else s
|
if Lazy.force Ansi_color.stderr_supports_colors then
|
||||||
|
s
|
||||||
|
else
|
||||||
|
Ansi_color.strip s
|
||||||
|
|
||||||
type running_job =
|
type running_job =
|
||||||
{ id : int
|
{ id : int
|
||||||
|
@ -375,6 +378,7 @@ module Scheduler = struct
|
||||||
go_rec cwd log t
|
go_rec cwd log t
|
||||||
|
|
||||||
let go ?log t =
|
let go ?log t =
|
||||||
|
Lazy.force Ansi_color.setup_env_for_ocaml_colors;
|
||||||
let cwd = Sys.getcwd () in
|
let cwd = Sys.getcwd () in
|
||||||
go_rec cwd log t
|
go_rec cwd log t
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue