-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved formatting. Switch to prettyprinter library. Tracing.
- Loading branch information
Showing
9 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "optparse-applicative"] | ||
path = optparse-applicative | ||
url = git@github.com:input-output-hk/optparse-applicative.git | ||
[submodule "criterion"] | ||
path = criterion | ||
url = git@github.com:input-output-hk/criterion.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Cardano.CLI.Render | ||
( renderHtmlShowS | ||
) where | ||
|
||
import Data.Function | ||
import Data.Ord | ||
import Options.Applicative.Help.Ann | ||
import Prettyprinter | ||
import Prettyprinter.Render.Util.Panic | ||
import Text.Show | ||
|
||
import qualified Data.List as L | ||
import qualified Data.Text as T | ||
|
||
renderOpenAnn :: Ann -> ShowS | ||
renderOpenAnn ann = case ann of | ||
AnnTrace _ s -> id | ||
. ("<span trace=" <>) | ||
. (show s <>) | ||
. (">" <>) | ||
|
||
renderCloseAnn :: Ann -> ShowS | ||
renderCloseAnn ann = case ann of | ||
AnnTrace _ _ -> id | ||
. (<> "</span>") | ||
|
||
-- | Render a 'SimpleDocStream' to a 'ShowS', useful to write 'Show' instances | ||
-- based on the prettyprinter. | ||
-- | ||
-- @ | ||
-- instance 'Show' MyType where | ||
-- 'showsPrec' _ = 'renderHtmlShowS' . 'layoutPretty' 'defaultLayoutOptions' . 'pretty' | ||
-- @ | ||
renderHtmlShowS :: SimpleDocStream Ann -> ShowS | ||
renderHtmlShowS ds = id | ||
. ("<html>\n" <>) | ||
. ("<body>\n" <>) | ||
. ("<pre>\n" <>) | ||
. (<> "\n</pre>") | ||
. (<> "\n</body>") | ||
. (<> "\n</html>") | ||
. go [] ds | ||
where | ||
go :: [Ann] -> SimpleDocStream Ann -> ShowS | ||
go anns sds = case sds of | ||
SFail -> panicUncaughtFail | ||
SEmpty -> id | ||
SChar c x -> showChar c . go anns x | ||
SText _l t x -> showString (T.unpack t) . go anns x | ||
SLine i x -> showString ('\n' : L.replicate i ' ') . go anns x | ||
SAnnPush ann x -> onLevel ann (renderOpenAnn ann) . go (ann:anns) x | ||
SAnnPop x -> case anns of | ||
(a:as) -> go as x . onLevel a (renderCloseAnn a) | ||
[] -> go [] x | ||
onLevel :: Ann -> ShowS -> ShowS | ||
onLevel (AnnTrace n _) f = if n >= 2 then f else id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
zsh: command not found: transaction |
Submodule optparse-applicative
added at
ca02c8