package windtrap

  1. Overview
  2. Docs

Source file diff_display.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(*---------------------------------------------------------------------------
   Copyright (c) 2026 Invariant Systems. All rights reserved.
   SPDX-License-Identifier: ISC
  ---------------------------------------------------------------------------*)

(* Colorize unified diff lines while keeping the underlying text unchanged. *)
let colorize_unified_diff diff_text =
  let style_line line =
    if String.starts_with ~prefix:"@@ " line then Pp.styled_string `Cyan line
    else if String.starts_with ~prefix:"--- " line then
      Pp.styled_string `Bold line
    else if String.starts_with ~prefix:"+++ " line then
      Pp.styled_string `Bold line
    else if String.starts_with ~prefix:"- " line then Pp.styled_string `Red line
    else if String.starts_with ~prefix:"+ " line then
      Pp.styled_string `Green line
    else line
  in
  String.split_on_char '\n' diff_text
  |> List.map style_line |> String.concat "\n"