mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Don't try to read screen columns without a tty
This commit is contained in:
parent
2d756698fb
commit
81e2d18100
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user