Skip to content

Commit 5814096

Browse files
committed
use spectrum for color output
1 parent c27ea05 commit 5814096

File tree

4 files changed

+32
-51
lines changed

4 files changed

+32
-51
lines changed

bin/Print.ml

+29-50
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,32 @@
1-
(* open Odiff.Diff *)
1+
open Odiff.Diff
22

33
let printDiffResult makeParsableOutput result =
4-
(* (match (result, makeParsableOutput) with *)
5-
(* | Layout, true -> "" *)
6-
(* | Layout, false -> *)
7-
(* Pastel.createElement *)
8-
(* ~children: *)
9-
(* [ *)
10-
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *)
11-
(* () [@JSX]); *)
12-
(* " Images have different layout.\n"; *)
13-
(* ] *)
14-
(* () [@JSX] *)
15-
(* | Pixel (_output, diffCount, _percentage, _lines), true when diffCount == 0 -> *)
16-
(* "" *)
17-
(* | Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0 *)
18-
(* -> *)
19-
(* Pastel.createElement *)
20-
(* ~children: *)
21-
(* [ *)
22-
(* (Pastel.createElement ~color:Green ~bold:true *)
23-
(* ~children:[ "Success!" ] () [@JSX]); *)
24-
(* " Images are equal.\n"; *)
25-
(* (Pastel.createElement ~dim:true *)
26-
(* ~children:[ "No diff output created." ] *)
27-
(* () [@JSX]); *)
28-
(* ] *)
29-
(* () [@JSX] *)
30-
(* | Pixel (_output, diffCount, diffPercentage, stack), true *)
31-
(* when not (Stack.is_empty stack) -> *)
32-
(* Int.to_string diffCount ^ ";" *)
33-
(* ^ Float.to_string diffPercentage *)
34-
(* ^ ";" *)
35-
(* ^ (stack *)
36-
(* |> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "") *)
37-
(* | Pixel (_output, diffCount, diffPercentage, _), true -> *)
38-
(* Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage *)
39-
(* | Pixel (_output, diffCount, diffPercentage, _lines), false -> *)
40-
(* Pastel.createElement *)
41-
(* ~children: *)
42-
(* [ *)
43-
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *)
44-
(* () [@JSX]); *)
45-
(* " Images are different.\n"; *)
46-
(* "Different pixels: "; *)
47-
(* (Pastel.createElement ~color:Red ~bold:true *)
48-
(* ~children:[ Printf.sprintf "%i (%f%%)" diffCount diffPercentage ] *)
49-
(* () [@JSX]); *)
50-
(* ] *)
51-
(* () [@JSX]) *)
52-
(* |> Console.log; *)
4+
let reset_ppf = Spectrum.prepare_ppf Format.str_formatter in
5+
(match (result, makeParsableOutput) with
6+
| Layout, true -> ()
7+
| Layout, false ->
8+
Spectrum.Simple.printf "@{<red>%s!@} Images have different layout.\n"
9+
"Failure!"
10+
| Pixel (_output, diffCount, diffPercentage, stack), true
11+
when not (Stack.is_empty stack) ->
12+
Int.to_string diffCount ^ ";"
13+
^ Float.to_string diffPercentage
14+
^ ";"
15+
^ (stack
16+
|> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "")
17+
|> print_endline
18+
| Pixel (_output, diffCount, diffPercentage, _), true ->
19+
Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage
20+
|> print_endline
21+
| Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0
22+
->
23+
Spectrum.Simple.printf
24+
"@{<green><bold>Success!@} Images are equal.\n\
25+
@{<dim>No diff output created.@}"
26+
| Pixel (_output, diffCount, diffPercentage, _lines), false ->
27+
Spectrum.Simple.printf
28+
"@{<red,bold>Failure!@} Images are different.\n\
29+
Different pixels: @{<red,bold>%i (%f%%)@}" diffCount diffPercentage);
30+
31+
reset_ppf ();
5332
result

bin/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(package odiff)
55
(flags
66
(:standard -w -27))
7-
(libraries odiff-core odiff-io cmdliner))
7+
(libraries odiff-core odiff-io cmdliner spectrum))
88

99
(env
1010
(dev

dune-project

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
odiff-core
2525
odiff-io
2626
(cmdliner (= 1.3.0))
27+
(spectrum (= 0.6.0))
2728
)
2829
)
2930

odiff.opam

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ depends: [
1111
"odiff-core"
1212
"odiff-io"
1313
"cmdliner" {= "1.3.0"}
14+
"spectrum" {= "0.6.0"}
1415
"odoc" {with-doc}
1516
]
1617
build: [

0 commit comments

Comments
 (0)