aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-04 15:44:37 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-04 15:44:37 +0200
commit80c35ec3ba6abcbb39aa140eebff5fe9468d37e4 (patch)
tree59aa654bf65d238b0998ab5bb3475380d417f394 /app
parent3056117ee6a84ec0110f9ee6e1f9ef0f4d150183 (diff)
output ansi styles only to tty, fixes tests
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 60c81e4..151115e 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DuplicateRecordFields #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
@@ -58,7 +59,7 @@ import Issue.Tag qualified as I
import Options.Applicative ((<**>))
import Options.Applicative qualified as O
import Prettyprinter qualified as P
-import Prettyprinter.Render.Terminal as P
+import Prettyprinter.Render.Terminal qualified as P
import System.Exit (ExitCode (ExitFailure), exitWith)
import System.FilePath qualified as F
import System.IO (hPutStrLn, stderr)
@@ -125,7 +126,7 @@ main = do
showMatches :: [Issue] -> IO ()
showMatches issues = do
- P.putDoc . P.vsep $
+ putDoc . P.vsep $
map
( \issue ->
P.vsep
@@ -141,7 +142,7 @@ showMatches issues = do
listMatches :: [Issue] -> IO ()
listMatches issues =
- P.putDoc . P.vsep $
+ putDoc . P.vsep $
map
( \issue ->
P.hsep
@@ -158,6 +159,13 @@ listMatches issues =
)
issues
+putDoc :: P.Doc P.AnsiStyle -> IO ()
+putDoc doc = do
+ isTty <- (== 1) <$> c_isatty 1
+ P.putDoc . (if isTty then id else P.unAnnotate) $ doc
+
+foreign import ccall "unistd.h isatty" c_isatty :: Int -> IO Int
+
data UnknownFileExtension = UnknownFileExtension
{ extension :: String
}