1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(************************************************************************)(* * The Rocq Prover / The Rocq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)typecolor=[`ON|`AUTO|`EMACS|`OFF]letinit_coloropts=lethas_color=matchoptswith|`OFF->false|`EMACS->false|`ON->true|`AUTO->Terminal.has_styleUnix.stdout&&Terminal.has_styleUnix.stderr&&(* emacs compilation buffer does not support colors by default,
its TERM variable is set to "dumb". *)trySys.getenv"TERM"<>"dumb"withNot_found->falseinletterm_color=ifhas_colorthenbeginmatchEnvars.getenv_rocq"_COLORS"with|None->Topfmt.default_styles();true(* Default colors *)|Some""->false(* No color output *)|Somes->Topfmt.parse_color_configs;true(* Overwrite all colors *)endelsebeginTopfmt.default_styles();false(* textual markers, no color *)endinifopts=`EMACSthenTopfmt.set_emacs_print_strings()elseifnotterm_colorthenbeginProof_diffs.write_color_enabledterm_color;ifProof_diffs.show_diffs()then(prerr_endline"Error: -diffs requires enabling -color";exit1)end;Topfmt.init_terminal_output~color:term_colorletprint_style_tagsopts=let()=init_coloroptsinlettags=Topfmt.dump_tags()inletiter(t,st)=letopt=Terminal.evalst^t^Terminal.reset^"\n"inprint_stringoptinletmake(t,st)=lettags=List.mapstring_of_int(Terminal.reprst)in(t^"="^String.concat";"tags)inletrepr=List.mapmaketagsinlet()=Printf.printf"ROCQ_COLORS=\"%s\"\n"(String.concat":"repr)inlet()=List.iteritertagsinflush_all()letset_color=function|"yes"|"on"->`ON|"no"|"off"->`OFF|"auto"->`AUTO|_->Coqargs.error_wrong_arg("Error: on/off/auto expected after option color")letparse_extra_colors~emacsextras=letrecparse_extracolor_mode=function|"-color"::next::rest->parse_extra(set_colornext)rest|x::rest->letcolor_mode,rest=parse_extracolor_moderestincolor_mode,x::rest|[]->color_mode,[]inletc,extras=parse_extra`AUTOextrasin(* we parse -color but ignore it when -emacs
maybe should be the other way (ignore -emacs for color printing if -color is given)? *)letc=ifemacsthen`EMACSelsecinc,extras