Skip to content

Commit

Permalink
Colors in CLI output
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Aug 5, 2021
1 parent 193eb2c commit fbc576b
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bench/cardano-topology/cardano-topology.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ executable cardano-topology
, bytestring
, containers
, graphviz
, optparse-applicative-fork
, optparse-applicative
, split
, text
4 changes: 2 additions & 2 deletions bench/locli/locli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ library
, gnuplot
, Histogram
, iohk-monitoring
, optparse-applicative-fork
, optparse-applicative
, optparse-generic
, ouroboros-network
, process
Expand Down Expand Up @@ -94,7 +94,7 @@ executable locli
build-depends: base
, cardano-prelude
, locli
, optparse-applicative-fork
, optparse-applicative
, text
, text-short
, transformers
Expand Down
4 changes: 2 additions & 2 deletions bench/tx-generator/tx-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ library
, ixset-typed
, network
, network-mux
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-byron
, ouroboros-consensus-cardano
Expand Down Expand Up @@ -139,7 +139,7 @@ test-suite tx-generator-test
build-depends: base >=4.12 && <5
, hedgehog
, heredoc
, optparse-applicative-fork
, optparse-applicative
, tasty
, tasty-hedgehog
, tasty-hunit
Expand Down
11 changes: 9 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,19 @@ package cardano-ledger-alonzo-test
-- --------------------------- 8< --------------------------
-- Please do not put any `source-repository-package` clause above this line.

-- Using a fork until our patches can be merged upstream
source-repository-package
type: git
location: https://github.com/input-output-hk/criterion
tag: fb2e7be532db96255d203f86360230cae37130f3
--sha256: 14r9zkfa8zslky3969gaq27gi7yi9rlqv0h1iq7zam9l15z53vhr

-- Using a fork until our patches can be merged upstream
source-repository-package
type: git
location: https://github.com/input-output-hk/optparse-applicative
tag: 3b259646f60325a0759fdf10b129ddc23518d11a
--sha256: 110sis5l8xff9sgxvk49sad2j1i3nikfycf8ff0yfxmbj0vx3b3k
tag: 27b99b346d58db877a61224a745de872601ba3e6
--sha256: 0y6imnwsd6h2myhaf6m1b8vyrnx44qz2s9x8760ii66jz15xih6r

source-repository-package
type: git
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ library
, formatting
, iproute
, network
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-byron
, ouroboros-consensus-cardano
Expand Down Expand Up @@ -158,7 +158,7 @@ executable cardano-cli
build-depends: cardano-cli
, cardano-crypto-class
, cardano-prelude
, optparse-applicative-fork
, optparse-applicative
, transformers-except

test-suite cardano-cli-test
Expand Down
18 changes: 14 additions & 4 deletions cardano-cli/src/Cardano/CLI/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Options.Applicative.Help.Types (helpText)
import Prelude (String)
import Prettyprinter
import Prettyprinter.Render.Util.SimpleDocTree
import Options.Applicative.Help.Types (renderHelp)

import qualified Data.Text as T
import qualified System.Environment as IO
Expand All @@ -26,17 +27,23 @@ cliHelpTraceEnabled = IO.unsafePerformIO $ do
-- tools can be used to inspect tracing that aids in describing the structure of the output
-- document.
customRenderHelp :: Int -> ParserHelp -> String
customRenderHelp cols
customRenderHelp = if cliHelpTraceEnabled
then customRenderHelpAsHtml
else customRenderHelpAsAnsi

customRenderHelpAsHtml :: Int -> ParserHelp -> String
customRenderHelpAsHtml cols
= T.unpack
. wrapper
. renderSimplyDecorated id renderElement
. treeForm
. layoutSmart (LayoutOptions (AvailablePerLine cols 1.0))
. helpText
where
renderElement = if cliHelpTraceEnabled
then \(AnnTrace _ name) x -> "<span name=" <> show name <> ">" <> x <> "</span>"
else flip const
renderElement :: Ann -> Text -> Text
renderElement ann x = case ann of
AnnTrace _ name -> "<span name=" <> show name <> ">" <> x <> "</span>"
AnnStyle _ -> x
wrapper = if cliHelpTraceEnabled
then id
. ("<html>\n" <>)
Expand All @@ -46,3 +53,6 @@ customRenderHelp cols
. (<> "\n</body>")
. (<> "\n</pre>")
else id

customRenderHelpAsAnsi :: Int -> ParserHelp -> String
customRenderHelpAsAnsi = renderHelp
29 changes: 19 additions & 10 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Parser as Aeson.Parser
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import qualified Options.Applicative as Opt
import qualified Options.Applicative.Help as H
import qualified Text.Parsec as Parsec
import qualified Text.Parsec.Error as Parsec
import qualified Text.Parsec.Language as Parsec
Expand Down Expand Up @@ -558,17 +559,25 @@ pTransaction :: Parser TransactionCmd
pTransaction =
asum
[ subParser "build-raw"
$ Opt.info pTransactionBuildRaw $ Opt.progDescDoc $ Just $
pretty @String "Build a transaction (low-level, inconvenient)"
<> line <> line
<> "Please note the order of some cmd options is crucial. If used incorrectly may produce "
<> "undesired tx body. See nested [] notation above for details."
$ Opt.info pTransactionBuildRaw $ Opt.progDescDoc $ Just $ mconcat
[ pretty @String "Build a transaction (low-level, inconvenient)"
, line
, line
, H.yellow $ mconcat
[ "Please note the order of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
]
, subParser "build"
$ Opt.info pTransactionBuild $ Opt.progDescDoc $ Just $
pretty @String "Build a balanced transaction (automatically calculates fees)"
<> line <> line
<> "Please note the order of some cmd options is crucial. If used incorrectly may produce "
<> "undesired tx body. See nested [] notation above for details."
$ Opt.info pTransactionBuild $ Opt.progDescDoc $ Just $ mconcat
[ pretty @String "Build a balanced transaction (automatically calculates fees)"
, line
, line
, H.yellow $ mconcat
[ "Please note the order of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
]
, subParser "sign"
(Opt.info pTransactionSign $ Opt.progDesc "Sign a transaction")
, subParser "witness"
Expand Down
2 changes: 1 addition & 1 deletion cardano-node-chairman/cardano-node-chairman.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ executable cardano-node-chairman
, contra-tracer
, io-classes
, network-mux
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-network
, ouroboros-network-framework
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ library
, network
, network-mux
, nothunks
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-byron
, ouroboros-consensus-cardano
Expand Down Expand Up @@ -167,7 +167,7 @@ executable cardano-node
build-depends: cardano-config
, cardano-node
, cardano-prelude
, optparse-applicative-fork
, optparse-applicative
, text

test-suite cardano-node-test
Expand Down
6 changes: 3 additions & 3 deletions cardano-submit-api/cardano-submit-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ common http-media { build-depends: http-media
common iohk-monitoring { build-depends: iohk-monitoring >= 0.1.10.1 }
common mtl { build-depends: mtl >= 2.2.2 }
common network { build-depends: network >= 3.1.2.1 }
common optparse-applicative-fork { build-depends: optparse-applicative-fork >= 0.16.1.0 }
common optparse-applicative { build-depends: optparse-applicative >= 0.16.1.0 }
common ouroboros-consensus-cardano { build-depends: ouroboros-consensus-cardano >= 0.1.0.0 }
common ouroboros-network { build-depends: ouroboros-network >= 0.1.0.0 }
common prometheus { build-depends: prometheus >= 2.2.2 }
Expand Down Expand Up @@ -78,7 +78,7 @@ library
, iohk-monitoring
, mtl
, network
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus-cardano
, ouroboros-network
, prometheus
Expand Down Expand Up @@ -111,7 +111,7 @@ library
executable cardano-submit-api
import: base, project-config
, cardano-submit-api
, optparse-applicative-fork
, optparse-applicative
main-is: Main.hs
hs-source-dirs: app
ghc-options: -threaded -rtsopts "-with-rtsopts=-T -I0"
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ executable cardano-testnet
, cardano-testnet
, hedgehog
, hedgehog-extras
, optparse-applicative-fork
, optparse-applicative
, resourcet
, stm
, text
Expand Down

0 comments on commit fbc576b

Please sign in to comment.