Skip to content

Commit

Permalink
use spectrum for color output
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrKovalenko committed Aug 24, 2024
1 parent c27ea05 commit 1a8ca30
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 53 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ jobs:
matrix:
include:
- os: ubuntu-latest
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
triplet: "x64-linux"
- os: windows-latest
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
triplet: "x64-mingw-static"
- os: macos-latest
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
triplet: "arm64-osx"
- os: macos-13
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
triplet: "x64-osx"
defaults:
run:
Expand Down Expand Up @@ -63,11 +67,11 @@ jobs:
- uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
ocaml-compiler: ${{ matrix.ocaml-compiler }}
opam-disable-sandboxing: true
dune-cache: false

- run: opam exec -- opam install . --deps-only
- run: opam exec -- opam install . --deps-only --update-invariant
- run: opam exec -- dune build --verbose
- run: opam exec -- dune exec ODiffBin -- --version

79 changes: 29 additions & 50 deletions bin/Print.ml
Original file line number Diff line number Diff line change
@@ -1,53 +1,32 @@
(* open Odiff.Diff *)
open Odiff.Diff

let printDiffResult makeParsableOutput result =
(* (match (result, makeParsableOutput) with *)
(* | Layout, true -> "" *)
(* | Layout, false -> *)
(* Pastel.createElement *)
(* ~children: *)
(* [ *)
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *)
(* () [@JSX]); *)
(* " Images have different layout.\n"; *)
(* ] *)
(* () [@JSX] *)
(* | Pixel (_output, diffCount, _percentage, _lines), true when diffCount == 0 -> *)
(* "" *)
(* | Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0 *)
(* -> *)
(* Pastel.createElement *)
(* ~children: *)
(* [ *)
(* (Pastel.createElement ~color:Green ~bold:true *)
(* ~children:[ "Success!" ] () [@JSX]); *)
(* " Images are equal.\n"; *)
(* (Pastel.createElement ~dim:true *)
(* ~children:[ "No diff output created." ] *)
(* () [@JSX]); *)
(* ] *)
(* () [@JSX] *)
(* | Pixel (_output, diffCount, diffPercentage, stack), true *)
(* when not (Stack.is_empty stack) -> *)
(* Int.to_string diffCount ^ ";" *)
(* ^ Float.to_string diffPercentage *)
(* ^ ";" *)
(* ^ (stack *)
(* |> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "") *)
(* | Pixel (_output, diffCount, diffPercentage, _), true -> *)
(* Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage *)
(* | Pixel (_output, diffCount, diffPercentage, _lines), false -> *)
(* Pastel.createElement *)
(* ~children: *)
(* [ *)
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *)
(* () [@JSX]); *)
(* " Images are different.\n"; *)
(* "Different pixels: "; *)
(* (Pastel.createElement ~color:Red ~bold:true *)
(* ~children:[ Printf.sprintf "%i (%f%%)" diffCount diffPercentage ] *)
(* () [@JSX]); *)
(* ] *)
(* () [@JSX]) *)
(* |> Console.log; *)
let reset_ppf = Spectrum.prepare_ppf Format.str_formatter in
(match (result, makeParsableOutput) with
| Layout, true -> ()
| Layout, false ->
Spectrum.Simple.printf "@{<red>%s!@} Images have different layout.\n"
"Failure!"
| Pixel (_output, diffCount, diffPercentage, stack), true
when not (Stack.is_empty stack) ->
Int.to_string diffCount ^ ";"
^ Float.to_string diffPercentage
^ ";"
^ (stack
|> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "")
|> print_endline
| Pixel (_output, diffCount, diffPercentage, _), true ->
Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage
|> print_endline
| Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0
->
Spectrum.Simple.printf
"@{<green><bold>Success!@} Images are equal.\n\
@{<dim>No diff output created.@}"
| Pixel (_output, diffCount, diffPercentage, _lines), false ->
Spectrum.Simple.printf
"@{<red,bold>Failure!@} Images are different.\n\
Different pixels: @{<red,bold>%i (%f%%)@}" diffCount diffPercentage);

reset_ppf ();
result
2 changes: 1 addition & 1 deletion bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(package odiff)
(flags
(:standard -w -27))
(libraries odiff-core odiff-io cmdliner))
(libraries odiff-core odiff-io cmdliner spectrum))

(env
(dev
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
odiff-core
odiff-io
(cmdliner (= 1.3.0))
(spectrum (= 0.6.0))
)
)

Expand Down
1 change: 1 addition & 0 deletions odiff.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ depends: [
"odiff-core"
"odiff-io"
"cmdliner" {= "1.3.0"}
"spectrum" {= "0.6.0"}
"odoc" {with-doc}
]
build: [
Expand Down

0 comments on commit 1a8ca30

Please sign in to comment.