summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.depend14
-rw-r--r--Makefile5
-rw-r--r--driver/compenv.ml11
-rw-r--r--driver/main.ml5
-rw-r--r--driver/main_args.ml17
-rw-r--r--driver/main_args.mli1
-rw-r--r--driver/optmain.ml5
-rw-r--r--ocamlbuild/ocaml_specific.ml1
-rw-r--r--tools/ocamlcp.ml1
-rw-r--r--tools/ocamloptp.ml1
-rw-r--r--utils/clflags.ml8
-rw-r--r--utils/clflags.mli4
-rw-r--r--utils/misc.ml8
-rw-r--r--utils/misc.mli13
14 files changed, 70 insertions, 24 deletions
diff --git a/.depend b/.depend
index 782c2d10fd..c782b44fa0 100644
--- a/.depend
+++ b/.depend
@@ -2,7 +2,7 @@ utils/ccomp.cmi :
utils/clflags.cmi :
utils/config.cmi :
utils/consistbl.cmi :
-utils/misc.cmi :
+utils/misc.cmi : utils/clflags.cmi
utils/tbl.cmi :
utils/terminfo.cmi :
utils/warnings.cmi :
@@ -16,8 +16,8 @@ utils/config.cmo : utils/config.cmi
utils/config.cmx : utils/config.cmi
utils/consistbl.cmo : utils/consistbl.cmi
utils/consistbl.cmx : utils/consistbl.cmi
-utils/misc.cmo : utils/misc.cmi
-utils/misc.cmx : utils/misc.cmi
+utils/misc.cmo : utils/clflags.cmi utils/misc.cmi
+utils/misc.cmx : utils/clflags.cmx utils/misc.cmi
utils/tbl.cmo : utils/tbl.cmi
utils/tbl.cmx : utils/tbl.cmi
utils/terminfo.cmo : utils/terminfo.cmi
@@ -63,10 +63,10 @@ parsing/lexer.cmo : utils/warnings.cmi parsing/parser.cmi utils/misc.cmi \
parsing/location.cmi parsing/docstrings.cmi parsing/lexer.cmi
parsing/lexer.cmx : utils/warnings.cmx parsing/parser.cmx utils/misc.cmx \
parsing/location.cmx parsing/docstrings.cmx parsing/lexer.cmi
-parsing/location.cmo : utils/warnings.cmi utils/terminfo.cmi \
- parsing/location.cmi
-parsing/location.cmx : utils/warnings.cmx utils/terminfo.cmx \
- parsing/location.cmi
+parsing/location.cmo : utils/warnings.cmi utils/terminfo.cmi utils/misc.cmi \
+ utils/clflags.cmi parsing/location.cmi
+parsing/location.cmx : utils/warnings.cmx utils/terminfo.cmx utils/misc.cmx \
+ utils/clflags.cmx parsing/location.cmi
parsing/longident.cmo : utils/misc.cmi parsing/longident.cmi
parsing/longident.cmx : utils/misc.cmx parsing/longident.cmi
parsing/parse.cmo : parsing/syntaxerr.cmi parsing/parser.cmi \
diff --git a/Makefile b/Makefile
index b87b2aab08..19b4a2accc 100644
--- a/Makefile
+++ b/Makefile
@@ -38,8 +38,9 @@ OCAMLDOC_OPT=$(WITH_OCAMLDOC:=.opt)
INCLUDES=-I utils -I parsing -I typing -I bytecomp -I asmcomp -I driver \
-I toplevel
-UTILS=utils/misc.cmo utils/tbl.cmo utils/config.cmo \
- utils/clflags.cmo utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \
+UTILS=utils/config.cmo utils/clflags.cmo \
+ utils/misc.cmo utils/tbl.cmo \
+ utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \
utils/consistbl.cmo
PARSING=parsing/location.cmo parsing/longident.cmo \
diff --git a/driver/compenv.ml b/driver/compenv.ml
index 6f3567e882..32d5f7e91c 100644
--- a/driver/compenv.ml
+++ b/driver/compenv.ml
@@ -212,6 +212,17 @@ let read_OCAMLPARAM ppf position =
"non-integer parameter for \"inline\""))
end
+ (* color output *)
+ | "color" ->
+ begin match parse_color_setting v with
+ | None ->
+ Location.print_warning Location.none ppf
+ (Warnings.Bad_env_variable ("OCAMLPARAM",
+ "bad value for \"color\", \
+ (expected \"auto\", \"always\" or \"never\")"))
+ | Some setting -> color := setting
+ end
+
| "intf-suffix" -> Config.interface_suffix := v
| "I" -> begin
diff --git a/driver/main.ml b/driver/main.ml
index 9835284989..e765d2eedd 100644
--- a/driver/main.ml
+++ b/driver/main.ml
@@ -128,6 +128,11 @@ module Options = Main_args.Make_bytecomp_options (struct
let _w = (Warnings.parse_options false)
let _warn_error = (Warnings.parse_options true)
let _warn_help = Warnings.help_warnings
+ let _color option =
+ begin match Clflags.parse_color_setting option with
+ | None -> ()
+ | Some setting -> Clflags.color := setting
+ end
let _where = print_standard_library
let _verbose = set verbose
let _nopervasives = set nopervasives
diff --git a/driver/main_args.ml b/driver/main_args.ml
index 7bf4c4945b..b44941f9f7 100644
--- a/driver/main_args.ml
+++ b/driver/main_args.ml
@@ -368,6 +368,19 @@ let mk_warn_help f =
"-warn-help", Arg.Unit f, " Show description of warning numbers"
;;
+let mk_color f =
+ "-color", Arg.Symbol (["auto"; "always"; "never"], f),
+ Printf.sprintf
+ " Enable or disable colors in compiler messages\n\
+ \ The following settings are supported:\n\
+ \ auto use heuristics to enable colors only if supported\n\
+ \ always enable colors\n\
+ \ never disable colors\n\
+ \ The default setting is 'auto', and the current heuristic\n\
+ \ checks that the TERM environment variable exists and is\n\
+ \ not empty or \"dumb\", and that isatty(stderr) holds."
+;;
+
let mk_where f =
"-where", Arg.Unit f, " Print location of standard library and exit"
;;
@@ -551,6 +564,8 @@ module type Compiler_options = sig
val _v : unit -> unit
val _verbose : unit -> unit
val _where : unit -> unit
+ val _color : string -> unit
+
val _nopervasives : unit -> unit
end
;;
@@ -659,6 +674,7 @@ struct
mk_cc F._cc;
mk_cclib F._cclib;
mk_ccopt F._ccopt;
+ mk_color F._color;
mk_compat_32 F._compat_32;
mk_config F._config;
mk_custom F._custom;
@@ -783,6 +799,7 @@ struct
mk_cc F._cc;
mk_cclib F._cclib;
mk_ccopt F._ccopt;
+ mk_color F._color;
mk_compact F._compact;
mk_config F._config;
mk_dtypes F._annot;
diff --git a/driver/main_args.mli b/driver/main_args.mli
index ddee921d4b..04f0c6d713 100644
--- a/driver/main_args.mli
+++ b/driver/main_args.mli
@@ -80,6 +80,7 @@ module type Compiler_options = sig
val _v : unit -> unit
val _verbose : unit -> unit
val _where : unit -> unit
+ val _color : string -> unit
val _nopervasives : unit -> unit
end
diff --git a/driver/optmain.ml b/driver/optmain.ml
index 84c27b7866..bef8d86b4f 100644
--- a/driver/optmain.ml
+++ b/driver/optmain.ml
@@ -129,6 +129,11 @@ module Options = Main_args.Make_optcomp_options (struct
let _w s = Warnings.parse_options false s
let _warn_error s = Warnings.parse_options true s
let _warn_help = Warnings.help_warnings
+ let _color option =
+ begin match Clflags.parse_color_setting option with
+ | None -> ()
+ | Some setting -> Clflags.color := setting
+ end
let _where () = print_standard_library ()
let _nopervasives = set nopervasives
diff --git a/ocamlbuild/ocaml_specific.ml b/ocamlbuild/ocaml_specific.ml
index e6f0ec52a6..b902810ad7 100644
--- a/ocamlbuild/ocaml_specific.ml
+++ b/ocamlbuild/ocaml_specific.ml
@@ -643,6 +643,7 @@ let () =
(fun param -> S [A "-for-pack"; A param]);
pflag ["ocaml"; "native"; "compile"] "inline"
(fun param -> S [A "-inline"; A param]);
+ pflag ["ocaml"; "compile"] "color" (fun setting -> S[A "-color"; A setting]);
List.iter (fun pp ->
pflag ["ocaml"; "compile"] pp
(fun param -> S [A ("-" ^ pp); A param]);
diff --git a/tools/ocamlcp.ml b/tools/ocamlcp.ml
index 26ced6c567..74724576db 100644
--- a/tools/ocamlcp.ml
+++ b/tools/ocamlcp.ml
@@ -100,6 +100,7 @@ module Options = Main_args.Make_bytecomp_options (struct
let _w = option_with_arg "-w"
let _warn_error = option_with_arg "-warn-error"
let _warn_help = option "-warn-help"
+ let _color s = option_with_arg "-color" s
let _where = option "-where"
let _nopervasives = option "-nopervasives"
let _dsource = option "-dsource"
diff --git a/tools/ocamloptp.ml b/tools/ocamloptp.ml
index fd15fe5968..6daaa252ab 100644
--- a/tools/ocamloptp.ml
+++ b/tools/ocamloptp.ml
@@ -100,6 +100,7 @@ module Options = Main_args.Make_optcomp_options (struct
let _w = option_with_arg "-w"
let _warn_error = option_with_arg "-warn-error"
let _warn_help = option "-warn-help"
+ let _color s = option_with_arg "-color" s
let _where = option "-where"
let _nopervasives = option "-nopervasives"
diff --git a/utils/clflags.ml b/utils/clflags.ml
index 4d2010af77..0e6dc345ad 100644
--- a/utils/clflags.ml
+++ b/utils/clflags.ml
@@ -117,3 +117,11 @@ let runtime_variant = ref "";; (* -runtime-variant *)
let keep_docs = ref false (* -keep-docs *)
let keep_locs = ref false (* -keep-locs *)
let unsafe_string = ref true;; (* -safe-string / -unsafe-string *)
+
+type color_setting = Auto | Always | Never
+let parse_color_setting = function
+ | "auto" -> Some Auto
+ | "always" -> Some Always
+ | "never" -> Some Never
+ | _ -> None
+let color = ref Auto ;; (* -color *)
diff --git a/utils/clflags.mli b/utils/clflags.mli
index e62dc8b848..4b6d4786ba 100644
--- a/utils/clflags.mli
+++ b/utils/clflags.mli
@@ -98,3 +98,7 @@ val keep_docs : bool ref
val keep_locs : bool ref
val unsafe_string : bool ref
val opaque : bool ref
+
+type color_setting = Auto | Always | Never
+val parse_color_setting : string -> color_setting option
+val color : color_setting ref
diff --git a/utils/misc.ml b/utils/misc.ml
index 676e2dd735..cbbd472fa4 100644
--- a/utils/misc.ml
+++ b/utils/misc.ml
@@ -475,8 +475,6 @@ module Color = struct
if !color_enabled then ansi_of_style_l [Reset] else ""
with Not_found -> or_else s
- type options = On | Off | Auto
-
(* add color handling to formatter [ppf] *)
let set_color_tag_handling ppf =
let open Format in
@@ -506,9 +504,9 @@ module Color = struct
Format.set_mark_tags true;
List.iter set_color_tag_handling formatter_l;
color_enabled := (match o with
- | On -> true
- | Auto -> should_enable_color ()
- | Off -> false
+ | Clflags.Always -> true
+ | Clflags.Auto -> should_enable_color ()
+ | Clflags.Never -> false
)
);
()
diff --git a/utils/misc.mli b/utils/misc.mli
index db320306dd..75fc500147 100644
--- a/utils/misc.mli
+++ b/utils/misc.mli
@@ -226,16 +226,9 @@ module Color : sig
val get_styles: unit -> styles
val set_styles: styles -> unit
- type options = On | Off | Auto
- (* setup for colors:
- - on means colors are printed unconditionally
- - off means colors are not printed
- - auto means colors are printed on channels that "look like" they support colors
- *)
-
- val setup : options -> unit
- (* [setup o] will enable or disable color handling on standard formatters
- according to the value of [o].
+ val setup : Clflags.color_setting -> unit
+ (* [setup opt] will enable or disable color handling on standard formatters
+ according to the value of color setting [opt].
Only the first call to this function has an effect. *)
val set_color_tag_handling : Format.formatter -> unit