diff --git a/compiler/catala_utils/file.ml b/compiler/catala_utils/file.ml index 02fbe6f1..f043b3df 100644 --- a/compiler/catala_utils/file.ml +++ b/compiler/catala_utils/file.ml @@ -185,21 +185,24 @@ let process_out ?check_exit cmd args = let () = let default = 80 in let get_terminal_cols () = + let from_env () = + try int_of_string (Sys.getenv "COLUMNS") with Not_found | Failure _ -> 0 + in let count = - try - (* terminfo *) - process_out "tput" ["cols"] |> String.trim |> int_of_string - with Failure _ -> ( + if not Unix.(isatty stdin) then from_env () + else try - (* stty *) - process_out "stty" ["size"] - |> String.trim - |> fun s -> - let i = String.rindex s ' ' + 1 in - String.sub s i (String.length s - i) |> int_of_string - with Failure _ | Not_found | Invalid_argument _ -> ( - try int_of_string (Sys.getenv "COLUMNS") - with Not_found | Failure _ -> 0)) + (* terminfo *) + process_out "tput" ["cols"] |> String.trim |> int_of_string + with Failure _ -> ( + try + (* stty *) + process_out "stty" ["size"] + |> String.trim + |> fun s -> + let i = String.rindex s ' ' + 1 in + String.sub s i (String.length s - i) |> int_of_string + with Failure _ | Not_found | Invalid_argument _ -> from_env ()) in if count > 0 then count else default in