highlight errors even if real output is to a file

(unless told not to)
This commit is contained in:
rhiannon morris 2023-11-01 14:16:03 +01:00
parent 050346e344
commit 4cc50c6bcd
2 changed files with 10 additions and 8 deletions

View file

@ -30,7 +30,7 @@ die opts err = do
private private
runPretty : Options -> Eff Pretty a -> a runPretty : Options -> Eff Pretty a -> a
runPretty opts act = runPretty opts act =
let doColor = opts.color && opts.outFile == Stdout let doColor = opts.color && opts.outFile == Console
hl = if doColor then highlightSGR else noHighlight hl = if doColor then highlightSGR else noHighlight
in in
runPrettyWith Outer opts.flavor hl 2 act runPrettyWith Outer opts.flavor hl 2 act
@ -134,7 +134,7 @@ outputStr : Lazy String -> Eff Compile ()
outputStr str = outputStr str =
case !(asksAt OPTS outFile) of case !(asksAt OPTS outFile) of
None => pure () None => pure ()
Stdout => putStr str Console => putStr str
File f => do File f => do
res <- withFile f WriteTruncate pure $ \h => fPutStr h str res <- withFile f WriteTruncate pure $ \h => fPutStr h str
rethrow $ mapFst (WriteError f) res rethrow $ mapFst (WriteError f) res
@ -221,7 +221,9 @@ main = do
(_, opts, files) <- options (_, opts, files) <- options
case !(runCompile opts !newState $ traverse_ processFile files) of case !(runCompile opts !newState $ traverse_ processFile files) of
Right () => pure () Right () => pure ()
Left e => die (Opts opts.width) $ runPretty opts $ prettyError e Left e => die (Opts opts.width) $
runPretty ({outFile := Console} opts) $
prettyError e
----------------------------------- -----------------------------------

View file

@ -11,7 +11,7 @@ import Derive.Prelude
%language ElabReflection %language ElabReflection
public export public export
data OutFile = File String | Stdout | None data OutFile = File String | Console | None
%name OutFile f %name OutFile f
%runElab derive "OutFile" [Eq, Ord, Show] %runElab derive "OutFile" [Eq, Ord, Show]
@ -44,7 +44,7 @@ export
defaultOpts : IO Options defaultOpts : IO Options
defaultOpts = pure $ MkOpts { defaultOpts = pure $ MkOpts {
color = True, color = True,
outFile = Stdout, outFile = Console,
until = Nothing, until = Nothing,
flavor = Unicode, flavor = Unicode,
width = cast !getTermCols, width = cast !getTermCols,
@ -61,7 +61,7 @@ data OptAction = ShowHelp HelpType | Err String | Ok (Options -> Options)
private private
toOutFile : String -> OptAction toOutFile : String -> OptAction
toOutFile "" = Ok {outFile := None} toOutFile "" = Ok {outFile := None}
toOutFile "-" = Ok {outFile := Stdout} toOutFile "-" = Ok {outFile := Console}
toOutFile f = Ok {outFile := File f} toOutFile f = Ok {outFile := File f}
private private