hxbrief: Respect lines/columns env var even if ansi fails

master
Lennart Spitzner 2023-02-28 12:04:26 +01:00
parent ad1e8a0b12
commit 8955a9ca75
1 changed files with 7 additions and 6 deletions

View File

@ -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