Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file patdiff_format.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236open!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)endmoduleRule=structmoduleAffix=structtypet={text:string;styles:Style.tlist}[@@derivingfields,sexp_of]letcreate?(styles=[])text={text;styles}letblank=create""letstrip_stylest={twithstyles=[]}endtypet={pre:Affix.t;suf:Affix.t;styles:Style.tlist}[@@derivingfields,sexp_of]letcreate?(pre=Affix.blank)?(suf=Affix.blank)styles={pre;suf;styles}letblank=create[]letunstyled_prefixtext={blankwithpre=Affix.createtext}letstrip_stylest=letfffield=f(Field.getfieldt)inFields.map~pre:(fAffix.strip_styles)~suf:(fAffix.strip_styles)~styles:(f(const[]));;endmoduleRules=structtypet={line_same:Rule.t;line_prev:Rule.t;line_next:Rule.t;line_unified:Rule.t;word_same_prev:Rule.t;word_same_next:Rule.t;word_same_unified:Rule.t;word_prev:Rule.t;word_next:Rule.t;hunk:Rule.t;header_prev:Rule.t;header_next:Rule.t}[@@derivingfields,sexp_of]letinner_line_changetextcolor=letstyle=Style.[Fgcolor]inletpre=Rule.Affix.create~styles:Style.[Bold;Fgcolor]textinRule.create~prestyle;;letline_unified=letpre=Rule.Affix.create~styles:Style.[Bold;FgColor.Yellow]"!|"inRule.create~pre[];;letword_changecolor=Rule.createStyle.[Fgcolor]letdefault=letopenRulein{line_same=unstyled_prefix" ";line_prev=inner_line_change"-|"Color.Red;line_next=inner_line_change"+|"Color.Green;line_unified;word_same_prev=blank;word_same_next=blank;word_same_unified=blank;word_prev=word_changeColor.Red;word_next=word_changeColor.Green;hunk=blank;header_prev=blank;header_next=blank};;letstrip_stylest=letffield=Rule.strip_styles(Field.getfieldt)inFields.map~line_same:f~line_prev:f~line_next:f~line_unified:f~word_same_prev:f~word_same_next:f~word_same_unified:f~word_prev:f~word_next:f~hunk:f~header_prev:f~header_next:f;;endmoduleLocation_style=structtypet=|Diff|Omake[@@derivingbin_io,compare,enumerate,equal,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