Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Avoid outputting any ANSI codes when color option is disabled.
Browse files Browse the repository at this point in the history
Previously, even with color output disabled, the pretty printer
for terms was putting ANSI codes like `^[[0m` around all identifiers.
(See GaloisInc/saw-script#957.)
  • Loading branch information
Brian Huffman committed Dec 7, 2020
1 parent 8eefd67 commit 9b93014
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions saw-core/src/Verifier/SAW/Term/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -611,20 +611,23 @@ ppTerm opts trm = runPPM opts $ ppTermWithMemoTable PrecNone True trm
ppTermDepth :: Int -> Term -> SawDoc
ppTermDepth depth t = ppTerm (depthPPOpts depth) t

renderSawDoc :: (SawStyle -> AnsiStyle) -> SawDoc -> String
renderSawDoc style doc = Text.Lazy.unpack (renderLazy (reAnnotateS style (layoutPretty opts doc)))
where opts = LayoutOptions (AvailablePerLine 80 0.8)
renderSawDoc :: PPOpts -> SawDoc -> String
renderSawDoc ppOpts doc =
Text.Lazy.unpack (renderLazy (style (layoutPretty layoutOpts doc)))
where
layoutOpts = LayoutOptions (AvailablePerLine 80 0.8)
style = if ppColor ppOpts then reAnnotateS colorStyle else unAnnotateS

-- | Pretty-print a term and render it to a string, using the given options
scPrettyTerm :: PPOpts -> Term -> String
scPrettyTerm opts t =
renderSawDoc (if ppColor opts then colorStyle else const mempty) $ ppTerm opts t
renderSawDoc opts $ ppTerm opts t

-- | Like 'scPrettyTerm', but also supply a context of bound names, where the
-- most recently-bound variable is listed first in the context
scPrettyTermInCtx :: PPOpts -> [String] -> Term -> String
scPrettyTermInCtx opts ctx trm =
renderSawDoc (if ppColor opts then colorStyle else const mempty) $
renderSawDoc opts $
runPPM opts $
flip (Fold.foldl' (\m x -> snd <$> withBoundVarM x m)) ctx $
ppTermWithMemoTable PrecNone False trm
Expand Down

0 comments on commit 9b93014

Please sign in to comment.