Implement POC of `brick`

This commit is contained in:
Rene Vergara 2024-02-08 13:26:54 -06:00
parent a9a9e824cd
commit e82a5e17ae
Signed by: pitmutt
GPG Key ID: 65122AD495A7F5B2
4 changed files with 45 additions and 9 deletions

View File

@ -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"

View File

@ -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:

13
src/Zenith/CLI.hs Normal file
View File

@ -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"))

View File

@ -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