Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ocolor_types.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185(** {1 Basic types and values} *)(** {2 Types} *)(** {3 Color types} *)(** The type of 4-bits colors. They are informally rgb colors where each
component is in a scale from 0 to 1, with an additionnal intensity bit. *)typecolor4={r4:bool;g4:bool;b4:bool;intensity4 :bool;}(** The type of rgb colors with each component in \[0; 5\]. This is used to encode
the 6*6*6 color cube of 8-bits colors? *)typecube6={r6:int;g6:int;b6:int;}(** The type of a 8-bits color. Such a color is either a standard color, a 6*6*6
rgb color or some kind of grey on a 24-steps grayscale. Thus, the paramter of
{!Grayscale} should be in \[0; 23\] *)typecolor8=|Standardofcolor4|Cube6ofcube6|Grayscale ofint(* [0; 23] *)(** The type of 24-bits colors. Each component belongs to \[0; 255\]. *)typecolor24={r24:int;g24:int;b24:int;}(** The type of a color that can be a 4-, 8- or 24-bits color. *)typecolor=|C4ofcolor4|C8ofcolor8|C24ofcolor24(** {3 Style types} *)(** All style sequences that are implemented.
- {!Reset} disables everything (returns to default)
- {!Bold} enables bold font
- {!Faint} decreases intensity
- {!Faint_bold_off} revert the effect of {!Bold} and {!Faint}
- {!Italic}: italic font (likely to not work)
- {!Fraktur}: fraktur font (likely to not work)
- {!Italic_fraktur_off}: disables italic and fraktur (likely to not work)
- {!Underlined}: underlines text
- {!Underlined_off}: disable underline
- {!Blink} and {!Blink_off} enables and disables flow blink (fast blink is
rarely supported)
- {!Reverse_video} and {!Reverse_video_off} as expected
- {!Conceal} and {!Conceal_off} as excpected (rarely supported)
- {!Crossed_out} and {!Crossed_out_off} as excpected
- {!Framed}, {!Encircled} and {!Framed_encircled_off} as excpected (rarely
supported)
- {!Overlined} and {!Overlined_off} as excpected
- {!Default_font} set font to default (rarely supported)
- {!Font} set font to specified number (in \[1;9\]) (rarely supported)
- {!Fg} set foreground color to specified color
- {!Default_fg} set foreground color to default color
- {!Bg} set background color to specified color
- {!Default_bg} set background color to default color
*)typestyle=(* Comments for sequences that probably won't work *)|Reset|Bold|Faint|Faint_bold_off|Italic|Italic_fraktur_off(* Maybe this *)|Fraktur(* This *)|DoubleUnderlined (* Maybe this *)|Underlined|Underlined_off|Blink|Blink_off|Reverse_video |Reverse_video_off|Conceal |Conceal_off|Crossed_out |Crossed_out_off|Framed |Framed_encircled_off (* This *)|Encircled(* This *)|Overlined |Overlined_off|Default_font|Fontofint(* [1-9] *) (* This *)|Fgofcolor|Default_fg|Bgofcolor|Default_bg(** {2 Helpers and values} *)(** {3 Iterators on finite (small) color space} *)letfold_color4(typeacc)(f:color4->acc->acc)(acc:acc):acc=letrecaux(r4:bool)(g4:bool)(b4:bool)(intensity4:bool)(acc:acc):acc=let acc=f{r4;g4;b4;intensity4}accinmatch r4,g4,b4,intensity4with|true,true,true,true->acc|false,true,true,true->auxtruefalsefalsefalseacc|_,false,true,true->auxr4truefalsefalseacc|_,_,false,true->auxr4g4truefalseacc|_,_,_,false->auxr4g4b4trueaccinauxfalse falsefalse falseaccletfold_cube6(typeacc)(f:cube6->acc ->acc)(acc:acc):acc=letrecaux(r6:int)(g6:int)(b6:int)(acc:acc):acc =let acc=f{r6;g6;b6}accinmatchr6,g6,b6with|5,5,5->acc|_,5,5->aux(r6+1)00acc|_,_,5->auxr6(g6+1)0acc|_,_,_->auxr6g6(b6+1)accinaux000accletfold_greyscale(typeacc)(f:int->acc->acc)(acc:acc):acc=letrecaux(g:int)(acc:acc)=letacc=fgaccinmatchgwith|23->acc|_->aux(g+1)accinaux0accletfold_color8 (typeacc)(f:color8->acc->acc)(acc:acc):acc=acc|>fold_color4(func4acc->f(Standardc4)acc)|>fold_cube6(func6acc->f(Cube6c6)acc)|>fold_greyscale(fungacc->f(Grayscaleg)acc)(** {3 Useful names for 4-bits colors} *)(** {4 Standard 3-bits colors} *)letblack:color4={r4=false;g4=false;b4=false;intensity4=false;}letred:color4={blackwith r4=true;}letgreen:color4={blackwithg4=true;}letblue:color4={blackwith b4=true;}letyellow:color4={redwithg4=true;}letmagenta:color4={bluewithr4 =true;}letcyan:color4={greenwith b4=true;}letwhite:color4={yellowwithb4=true;}(** {4 High intensity 4-bits colors} *)lethi_black:color4={blackwithintensity4=true;}lethi_red:color4={redwith intensity4=true;}lethi_green:color4={greenwithintensity4=true;}lethi_blue:color4={bluewithintensity4=true;}lethi_yellow:color4={yellowwithintensity4=true;}lethi_magenta:color4={magentawithintensity4=true;}lethi_cyan:color4={cyanwithintensity4=true;}lethi_white:color4={whitewithintensity4=true;}(** {2 Standard palettes types} *)typergb=int*int*intmoduleColor4Map=Map.Make(structtypet=color4letcompare=compareend)moduleColor8Map=Map.Make(structtypet=color8letcompare=compareend)(** The kind of palette the terminal uses. It is used to match a 4-bits color to
a rgb color. This is useful to find the clostest 4-bits color to a rgb
color, according to the actual colors. *)typecolor_palette=|VGA|CMD|Terminal_app|PuTTY|MIRC|Xterm|X|Ubuntu|Custom_palette ofrgbColor4Map.tmoduleColorPaletteMap=Map.Make(structtypet=color_paletteletcompare=compareend)