1:- module(text_style,
    2	 [reset_text_style/0,
    3    foreground_color/1,
    4    background_color/1,
    5    text_property/2
    6    ]).    7
    8:- use_module(prolog_version).    9:- (is_dialect(swi) -> use_module(swi_specific) ; use_module(sicstus_specific)).   10:- use_module(sciff_options).   11
   12
   13
   14% In Linux, coloring works both in SWI and in SICStus.
   15% To use coloring, I use the ANSI codes.
   16% In Windows the console does not support coloring by default
   17% The following page on Wikipedia
   18%   http://en.wikipedia.org/wiki/ANSI_escape_code
   19% says that by loading ANSI.SYS one should be able to make the command.com (not the cmd.exe!)
   20% able to show colors. I tried and it did not work.
   21% So, I set coloring on by default on Unix, and off otherwise
   22
   23set_default_coloring:-
   24    (is_unix(true)
   25        ->  set_option(coloring,on)
   26        ;   set_option(coloring,off)
   27    ).
   28
   29:- (get_option(coloring,_) -> true ; set_default_coloring).   30
   31
   32reset_text_style:- text_style_if_enabled(0).
   33
   34foreground_color(Col):-
   35    color_num(Col,Num),
   36    Num1 is Num+30,
   37    text_style_if_enabled(Num1).
   38background_color(Col):-
   39    color_num(Col,Num),
   40    Num1 is Num+40,
   41    text_style_if_enabled(Num1).
   42
   43color_num(black,0).
   44color_num(red,1).
   45color_num(green,2).
   46color_num(yellow,3).
   47color_num(blue,4).
   48color_num(magenta,5).
   49color_num(cyan,6).
   50color_num(white,7).
   51
   52% On=1 -> activated, On=0 -> deactivated
   53text_property(Prop,On):-
   54    text_property_num(Prop,Num),
   55    N is Num+20*(1-On),
   56    text_style_if_enabled(N).
   57
   58text_property_num(bold,1).
   59text_property_num(light,2).
   60text_property_num(underlined,4).
   61text_property_num(reversed,7).
   62text_property_num(invisible,8).
   63text_property_num(strikeout,9).
   64
   65text_style_if_enabled(_):-
   66    get_option(coloring,off),!.
   67text_style_if_enabled(N):-
   68    text_style(N)