diff --git a/app/Main.hs b/app/Main.hs index 906d1af..764bcd9 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,6 +2,7 @@ module Main where +import Brick (simpleMain) import Control.Monad (void) import Control.Monad.IO.Class (liftIO) import qualified Data.ByteString as B @@ -12,9 +13,11 @@ import qualified Data.Text as T import qualified Data.Text.IO as TIO import Data.Time.Clock.POSIX import System.Console.StructuredCLI +import System.Environment (getArgs) import System.Exit import System.IO import Text.Read (readMaybe) +import Zenith.CLI import Zenith.Types (ZcashAddress(..), ZcashPool(..), ZcashTx(..)) import Zenith.Utils import Zenith.Zcashd @@ -196,14 +199,29 @@ processUri user pwd = main :: IO () main = do config <- load ["zenith.cfg"] + args <- getArgs nodeUser <- require config "nodeUser" nodePwd <- require config "nodePwd" - checkServer nodeUser nodePwd - void $ - runCLI - "Zenith" - def - { getBanner = - " ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0" - } - (root nodeUser nodePwd) + if not (null args) + then do + case head args of + "legacy" -> do + checkServer nodeUser nodePwd + void $ + runCLI + "Zenith" + def + { getBanner = + " ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0" + } + (root nodeUser nodePwd) + "cli" -> simpleMain ui + _ -> printUsage + else printUsage + +printUsage :: IO () +printUsage = do + putStrLn "zenith [command] [parameters]\n" + putStrLn "Available commands:" + putStrLn "legacy\tLegacy CLI for zcashd" + putStrLn "cli\tCLI for zebrad" diff --git a/package.yaml b/package.yaml index 476ba1b..9e0bca8 100644 --- a/package.yaml +++ b/package.yaml @@ -43,6 +43,7 @@ library: - persistent - persistent-sqlite - persistent-template + - brick - zcash-haskell executables: @@ -64,6 +65,7 @@ executables: - text - time - sort + - brick tests: zenith-test: diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs new file mode 100644 index 0000000..59df1a8 --- /dev/null +++ b/src/Zenith/CLI.hs @@ -0,0 +1,13 @@ +module Zenith.CLI where + +import Brick (Widget, (<+>), joinBorders, simpleMain, str, withBorderStyle) +import Brick.Widgets.Border (borderWithLabel, vBorder) +import Brick.Widgets.Border.Style (unicode) +import Brick.Widgets.Center (center) + +ui :: Widget () +ui = + joinBorders $ + withBorderStyle unicode $ + borderWithLabel (str "Zenith") $ + (center (str "Addresses") <+> vBorder <+> center (str "Transactions")) diff --git a/zenith.cabal b/zenith.cabal index 18eb1a0..e8a98e3 100644 --- a/zenith.cabal +++ b/zenith.cabal @@ -25,6 +25,7 @@ source-repository head library exposed-modules: + Zenith.CLI Zenith.DB Zenith.Types Zenith.Utils @@ -39,6 +40,7 @@ library , array , base >=4.7 && <5 , base64-bytestring + , brick , bytestring , http-conduit , http-types @@ -64,6 +66,7 @@ executable zenith ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wunused-imports build-depends: base >=4.7 && <5 + , brick , bytestring , configurator , data-default