Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ocolor_printf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127(** {1 Printf-friendly functions} *)(** These functions are useful when trying to print with styles with Printf.
However, they are a very bad choice. They perform a context-free formatting.
For instance, there is no way to end the current style and restore the
previous, like stack-base functions of {!Ocolor_format} do. They just print
the desired style and keep no track of the current state.
Thus, it's better to use {!Ocolor_format} as much as possible. Moreover,
{!Format} provide a nice way of composing printers with %a and
{!Format.asprintf}. Even if you don't like boxes, {!Format.asprintf} and
semantic tags are cool.
So, here are the Printf-friendly functions. Use with care, and preferably,
not at all.
*)(** {2 fprintf} *)(** {3 %a} *)letapply_style(channel:out_channel)(s:Ocolor_types.style):unit=Printf.fprintfchannel"%s"(Ocolor_sgr.sgr_of_styles)letapply_styles(channel:out_channel)(s:Ocolor_types.stylelist):unit=Printf.fprintfchannel"%s"(Ocolor_sgr.styles_sgrs)letfg_color4(channel:out_channel)(c:Ocolor_types.color4):unit=apply_stylechannelOcolor_types.(Fg(C4c))letfg_color8(channel:out_channel)(c:Ocolor_types.color8):unit=apply_stylechannelOcolor_types.(Fg(C8c))letfg_color24(channel:out_channel)(c:Ocolor_types.color24):unit=apply_stylechannelOcolor_types.(Fg(C24c))letbg_color4(channel:out_channel)(c:Ocolor_types.color4):unit=Printf.fprintfchannel"%s"(Ocolor_sgr.bg_color4_sgrc)letbg_color8(channel:out_channel)(c:Ocolor_types.color8):unit=Printf.fprintfchannel"%s"(Ocolor_sgr.bg_color8_sgrc)letbg_color24(channel:out_channel)(c:Ocolor_types.color24):unit=apply_stylechannelOcolor_types.(Bg(C24c))(** {3 %t} *)letdefault_fg(channel:out_channel):unit=apply_stylechannelOcolor_types.Default_fgletfg_rgb(r:int)(g:int)(b:int)(channel:out_channel):unit=apply_stylechannelOcolor_types.(Fg(C24{r24=r;g24=g;b24=b}))letdefault_bg(channel:out_channel):unit=Printf.fprintfchannel"%s"Ocolor_sgr.default_bg_sgrletbg_rgb(r:int)(g:int)(b:int)(channel:out_channel):unit=apply_stylechannelOcolor_types.(Bg(C24{r24=r;g24=g;b24=b}))letreset(channel:out_channel):unit=apply_stylechannelOcolor_types.Reset(** {2 sprintf} *)(** {3 %a} *)lets_apply_style()(s:Ocolor_types.style):string=Ocolor_sgr.sgr_of_styleslets_apply_styles()(s:Ocolor_types.stylelist):string=Ocolor_sgr.styles_sgrs(** {2 Printf-like} *)(** Just like printf but perform automatic reset after printing if
{!Ocolor_config.auto_reset} is set
*)letfprintf(channel:out_channel)(oc:('a,out_channel,unit)format):'a=letreset(channel:out_channel):unit=ifOcolor_config.get_auto_reset()thenapply_stylechannelOcolor_types.Resetelse()inPrintf.kfprintfresetchannelocletkfprintf(k:out_channel->unit)(channel:out_channel)(oc:('a,out_channel,unit)format):'a=letreset(channel:out_channel):unit=ifOcolor_config.get_auto_reset()thenapply_stylechannelOcolor_types.Reset;kchannelinPrintf.kfprintfresetchannelocletsprintf(oc:('a,unit,string,string)format4):'a=letreset(s:string):string=ifOcolor_config.get_auto_reset()thens^Ocolor_sgr.reset_sgrelsesinPrintf.ksprintfresetocletprintf(oc:('a,out_channel,unit)format):'a=fprintfstdoutocletkprintf(k:out_channel->unit)(oc:('a,out_channel,unit)format):'a=kfprintfkstdoutocmoduleStylingPrettyPrinters=Ocolor_pp.BuildPrettyPrinters(structtypeformatter=out_channelletfprintf=Printf.fprintfletpp_open_styles=apply_stylesletpp_close_styleschannel()=apply_stylechannelOcolor_types.Resetend)includeStylingPrettyPrintersmoduleNonStylingPrettyPrinters=Ocolor_pp.BuildPrettyPrinters(structtypeformatter=out_channelletfprintf=Printf.fprintfletpp_open_styles=fun__->()letpp_close_styles=fun__->()end)