Skip to content

Commit

Permalink
Merge pull request #113 from GaloisInc/no-color
Browse files Browse the repository at this point in the history
Avoid outputting any ANSI codes when color option is disabled.
  • Loading branch information
brianhuffman authored Dec 8, 2020
2 parents 8eefd67 + 9b93014 commit 6a70bf3
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 6a70bf3

Please sign in to comment.