diff options
Diffstat (limited to 'Omni/Log/Terminal.hs')
| -rw-r--r-- | Omni/Log/Terminal.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Omni/Log/Terminal.hs b/Omni/Log/Terminal.hs index a78e544..0d2ca7a 100644 --- a/Omni/Log/Terminal.hs +++ b/Omni/Log/Terminal.hs @@ -33,16 +33,22 @@ detectTerminal :: IO TerminalInfo detectTerminal = do term <- Env.lookupEnv "TERM" area <- Env.lookupEnv "AREA" + noColor <- Env.lookupEnv "NO_COLOR" -- Check if we support ANSI - let supportsANSI = case (term, area) of - (Just "dumb", _) -> False - (_, Just "Live") -> False -- production logs - (Nothing, _) -> False + let supportsANSI = case (term, area, noColor) of + (_, _, Just _) -> False -- NO_COLOR set + (Just "dumb", _, _) -> False + (_, Just "Live", _) -> False -- production logs + (Nothing, _, _) -> False _ -> True -- Get terminal size, catching exceptions from stdin issues - mSize <- Exception.catch ANSI.getTerminalSize <| \(_ :: Exception.IOException) -> pure Nothing + -- When NO_COLOR is set or ANSI is not supported, skip terminal size detection + -- to avoid outputting escape codes + mSize <- case supportsANSI of + False -> pure Nothing -- Skip if no ANSI support + True -> Exception.catch ANSI.getTerminalSize <| \(_ :: Exception.IOException) -> pure Nothing let (width, height) = case mSize of Just (h, w) -> (w, h) Nothing -> (80, 24) -- sensible default |
