Skip to content

Commit

Permalink
fix: status line enabled when ANSI colors are forced (#6503) (#6556)
Browse files Browse the repository at this point in the history
We want to enable the status line if and only if stderr is a tty. ANSI
color usage was tweaked in 3.6.0 with #6340 to allow users to force
colors. As status line activation actually depended on whether ANSI
colors were enabled or not, this change had the side effect to always
enable the status line even when ANSI colors were requested for
something that's not a tty.

Fix this by exposing a simple lazy wrapper of Unix.isatty to use
instead of Ansi_color.stderr_supports_color.

Signed-off-by: Antonin Décimo <antonin@tarides.com>

Signed-off-by: Antonin Décimo <antonin@tarides.com>
Co-authored-by: Antonin Décimo <antonin@tarides.com>
  • Loading branch information
emillon and MisterDA authored Nov 24, 2022
1 parent c3b75bd commit a133f52
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
3.6.1 (unreleased)
------------------

- Fix status line enabled when ANSI colors are forced. (#6503, @MisterDA)

3.6.0 (2022-11-14)
------------------

Expand Down
2 changes: 1 addition & 1 deletion bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let init ?log_file c =
in
let config =
Dune_config.adapt_display config
~output_is_a_tty:(Lazy.force Ansi_color.stderr_supports_color)
~output_is_a_tty:(Lazy.force Ansi_color.output_is_a_tty)
in
Dune_config.init config;
Dune_util.Log.init () ?file:log_file;
Expand Down
2 changes: 2 additions & 0 deletions otherlibs/stdune/ansi_color.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ let stdout_supports_color = lazy (supports_color Unix.stdout)

let stderr_supports_color = lazy (supports_color Unix.stderr)

let output_is_a_tty = lazy (Unix.isatty Unix.stderr)

let rec tag_handler current_styles ppf styles pp =
Format.pp_print_as ppf 0 (Style.escape_sequence_no_reset styles);
Pp.to_fmt_with_tags ppf pp
Expand Down
2 changes: 2 additions & 0 deletions otherlibs/stdune/ansi_color.mli
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ val stdout_supports_color : bool Lazy.t

val stderr_supports_color : bool Lazy.t

val output_is_a_tty : bool Lazy.t

(** Filter out escape sequences in a string *)
val strip : string -> string

Expand Down

0 comments on commit a133f52

Please sign in to comment.