Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file patdiff_format.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255open!Coreopen!ImportmoduleColor=structmoduleRGB6:sigtypet=private{r:int;g:int;b:int}[@@derivingcompare,sexp]valcreate_exn:r:int->g:int->b:int->tend=structtypet={r:int;g:int;b:int}[@@derivingcompare,sexp]letcreate_exn~r~g~b=letcheckx=0<=x&&x<6inifnot(checkr&&checkg&&checkb)theninvalid_arg"RGB6 (r, g, b) -- expected (0 <= r, g, b < 6)";{r;g;b};;endmoduleGray24:sigtypet=private{level:int}[@@derivingcompare,sexp]valcreate_exn:level:int->tend=structtypet={level:int}[@@derivingcompare,sexp]letcreate_exn~level=ifnot(0<=level&&level<24)theninvalid_arg"Gray24 level -- expected (0 <= level < 24)";{level};;endmoduleT=structtypet=|Black|Red|Green|Yellow|Blue|Magenta|Cyan|White|Default|Gray|Bright_black|Bright_red|Bright_green|Bright_yellow|Bright_blue|Bright_magenta|Bright_cyan|Bright_white|RGB6ofRGB6.t|Gray24ofGray24.t[@@derivingcompare,sexp]endincludeTincludeComparable.Make(T)letrgb6_exn(r,g,b)=RGB6(RGB6.create_exn~r~g~b)letgray24_exnlevel=Gray24(Gray24.create_exn~level)endmoduleStyle=structmoduleT=structtypet=|Bold|Underline|Emph|Blink|Dim|Inverse|Hide|Reset|ForegroundofColor.t|FgofColor.t|BackgroundofColor.t|BgofColor.t[@@derivingcompare,sexp]endincludeTincludeComparable.Make(T)end(* A rule consists of a styled prefix, a styled suffix, and a style. Rules
are applied to strings using functions defined in Output_ops.
*)moduleRule=struct(* An annex is either a prefix or a suffix. *)moduleAnnex=structtypet={text:string;styles:Style.tlist}[@@derivingfields,sexp_of]letcreate?(styles=[])text={text;styles}letblank=create""letstrip_stylest={twithstyles=[]}endtypet={pre:Annex.t;suf:Annex.t;styles:Style.tlist;name:string}[@@derivingfields,sexp_of](* Rule creation: Most rules have a style, and maybe a prefix. For
instance, a line_new rule might have a bold "+" prefix and a green
style.
*)letcreate?(pre=Annex.blank)?(suf=Annex.blank)styles~name={pre;suf;styles;name};;letblank=create[]letunstyled_prefixtext~name=letrule=blank~namein{rulewithpre=Annex.createtext};;letstrip_stylest=letfffield=f(Field.getfieldt)inFields.map~pre:(fAnnex.strip_styles)~suf:(fAnnex.strip_styles)~styles:(f(const[]))~name:(fFn.id);;end(* Rules are configured in the configuration file.
Default values are provided in Configuration.
*)moduleRules=structtypet={line_same:Rule.t;line_old:Rule.t;line_new:Rule.t;line_unified:Rule.t;word_same_old:Rule.t;word_same_new:Rule.t;word_same_unified:Rule.t;word_old:Rule.t;word_new:Rule.t;hunk:Rule.t;header_old:Rule.t;header_new:Rule.t}[@@derivingfields,sexp_of]letinner_line_change~nametextcolor=letstyle=Style.[Fgcolor]inletpre=Rule.Annex.create~styles:Style.[Bold;Fgcolor]textinRule.create~prestyle~name;;letline_unified=letpre=Rule.Annex.create~styles:Style.[Bold;FgColor.Yellow]"!|"inRule.create~pre[]~name:"line_unified";;letword_change~namecolor=Rule.createStyle.[Fgcolor]~nameletdefault=letopenRulein{line_same=unstyled_prefix~name:"line_same"" ";line_old=inner_line_change~name:"line_old""-|"Color.Red;line_new=inner_line_change~name:"line_new""+|"Color.Green;line_unified;word_same_old=blank~name:"word_same_old";word_same_new=blank~name:"word_same_new";word_same_unified=blank~name:"word_same_unified";word_old=word_change~name:"word_old"Color.Red;word_new=word_change~name:"word_new"Color.Green;hunk=blank~name:"hunk";header_old=blank~name:"hunk";header_new=blank~name:"hunk"};;letstrip_stylest=letffield=Rule.strip_styles(Field.getfieldt)inFields.map~line_same:f~line_old:f~line_new:f~line_unified:f~word_same_old:f~word_same_new:f~word_same_unified:f~word_old:f~word_new:f~hunk:f~header_old:f~header_new:f;;endmoduleLocation_style=structtypet=|Diff|Omake[@@derivingbin_io,compare,enumerate,sexp]letto_string=function|Diff->"diff"|Omake->"omake";;letof_string=function|"diff"->Diff|"omake"->Omake|other->failwiths"invalid location style"other[%sexp_of:string];;letsprintt(hunk:stringPatience_diff.Hunk.t)~prev_filename~rule=matchtwith|Diff->rule(sprintf"-%i,%i +%i,%i"hunk.prev_starthunk.prev_sizehunk.next_starthunk.next_size)(* omake locations must be parseable, so we can't let the user config insert
arbitrary prefixes and suffixes and ANSI color rubbish. *)|Omake->(* Print line number of first difference, skipping past context lines. *)letprev_start=with_return(funr->List.foldhunk.ranges~init:hunk.prev_start~f:(funinit->function|Sames->init+Array.lengths|Prev_|Next_|Replace_|Unified_->r.returninit))inerror_message_start~file:prev_filename~line:prev_start;;end