diff --git a/otherlibs/stdune-unstable/ansi_color.ml b/otherlibs/stdune-unstable/ansi_color.ml index 6d4515532317..8bbcddbbef03 100644 --- a/otherlibs/stdune-unstable/ansi_color.ml +++ b/otherlibs/stdune-unstable/ansi_color.ml @@ -37,6 +37,24 @@ module Style = struct let fg_bright_white = "97" + let fg_all = + [ fg_black + ; fg_green + ; fg_yellow + ; fg_blue + ; fg_magenta + ; fg_cyan + ; fg_white + ; fg_bright_black + ; fg_bright_red + ; fg_bright_green + ; fg_bright_yellow + ; fg_bright_blue + ; fg_bright_magenta + ; fg_bright_cyan + ; fg_bright_white + ] + let bg_black = "40" let bg_red = "41" @@ -181,6 +199,9 @@ let parse_line str styles = |> String.split ~on:';' |> List.fold_left ~init:(List.rev styles) ~f:(fun styles s -> match s with + | "39" -> + List.filter styles ~f:(fun s -> + not (List.mem Style.fg_all s ~equal:String.equal)) | "0" -> [] | _ -> s :: styles) |> List.rev diff --git a/test/expect-tests/stdune/ansi_color_tests.ml b/test/expect-tests/stdune/ansi_color_tests.ml index 62dd06a97dd0..031b8c655d6b 100644 --- a/test/expect-tests/stdune/ansi_color_tests.ml +++ b/test/expect-tests/stdune/ansi_color_tests.ml @@ -62,425 +62,37 @@ let%expect_test "reproduce #2664" = Seq Seq Nop,Tag [ "34" ],Verbatim "1", Tag - [ "34"; "39"; "34" ],Verbatim "2", - Tag - [ "34"; "39"; "34"; "39"; "34" ], - Verbatim - "3",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "4",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ], - Verbatim - "5", + [ "34" ],Verbatim "2",Tag + [ "34" ], + Verbatim + "3", + Tag + [ "34" ],Verbatim "4",Tag + [ "34" ], + Verbatim + "5", Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "6",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "7",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim + [ "34" ],Verbatim "6",Tag + [ "34" ], + Verbatim + "7",Tag + [ "34" ], + Verbatim "8", Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "9",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "10",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim - "11", - Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "12",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "13",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "14", + [ "34" ],Verbatim "9",Tag + [ "34" ],Verbatim "10", + Tag + [ "34" ],Verbatim "11",Tag [ "34" ],Verbatim "12", + Tag + [ "34" ],Verbatim "13",Tag [ "34" ],Verbatim "14", Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "15",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "16",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "17", + [ "34" ],Verbatim "15",Tag [ "34" ],Verbatim "16",Tag + [ "34" ], + Verbatim + "17", Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "18",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "19",Tag - [ "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ; "39" - ; "34" - ],Verbatim "20" |}] + [ "34" ],Verbatim "18",Tag [ "34" ],Verbatim "19",Tag + [ "34" ], + Verbatim + "20" |}]