From 8955a9ca75a2c85d85d39e98ebee0cacd4f673e2 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Tue, 28 Feb 2023 12:04:26 +0100 Subject: [PATCH] hxbrief: Respect lines/columns env var even if ansi fails --- src-hxbrief/Main.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src-hxbrief/Main.hs b/src-hxbrief/Main.hs index 0a8ece4..e690c7d 100644 --- a/src-hxbrief/Main.hs +++ b/src-hxbrief/Main.hs @@ -7,6 +7,7 @@ module Main where +import Control.Applicative ( (<|>) ) import Control.Concurrent ( threadDelay ) import qualified Control.Concurrent.Async as A import Control.Concurrent.MVar @@ -740,12 +741,12 @@ main = B.mainFromCmdParser $ do -- restore $ System.IO.hSetEncoding System.IO.stderr GHC.IO.Encoding.utf8 termSizeMay <- restore $ do support <- Ansi.hSupportsANSI System.IO.stdin - if support - then Ansi.getTerminalSize - else do - envLines <- System.Environment.lookupEnv "LINES" - envCols <- System.Environment.lookupEnv "COLUMNS" - pure $ (,) <$> (envLines >>= readMaybe) <*> (envCols >>= readMaybe) + viaAnsi <- if support then Ansi.getTerminalSize else pure Nothing + viaEnv <- do + envLines <- System.Environment.lookupEnv "LINES" + envCols <- System.Environment.lookupEnv "COLUMNS" + pure $ (,) <$> (envLines >>= readMaybe) <*> (envCols >>= readMaybe) + pure (viaAnsi <|> viaEnv) let stdoutCheckCount = length $ [ () | keepStdout || keepBoth ] ++ [ () | conflateStdout || conflateBoth ] ++ [ () | dropStdout || dropBoth ] let stderrCheckCount = length $ [ () | keepStderr || keepBoth ] ++ [ () | conflateStderr || conflateBoth ] ++ [ () | dropStderr || dropBoth ] adjustedNumLines <- case termSizeMay of