Proof-of-concept of brick TUI #59

Merged
pitmutt merged 2 commits from rav001 into dev041 2024-02-08 19:30:07 +00:00
4 changed files with 45 additions and 9 deletions
Showing only changes of commit e82a5e17ae - Show all commits

View file

@ -2,6 +2,7 @@
module Main where module Main where
import Brick (simpleMain)
import Control.Monad (void) import Control.Monad (void)
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString as B import qualified Data.ByteString as B
@ -12,9 +13,11 @@ import qualified Data.Text as T
import qualified Data.Text.IO as TIO import qualified Data.Text.IO as TIO
import Data.Time.Clock.POSIX import Data.Time.Clock.POSIX
import System.Console.StructuredCLI import System.Console.StructuredCLI
import System.Environment (getArgs)
import System.Exit import System.Exit
import System.IO import System.IO
import Text.Read (readMaybe) import Text.Read (readMaybe)
import Zenith.CLI
import Zenith.Types (ZcashAddress(..), ZcashPool(..), ZcashTx(..)) import Zenith.Types (ZcashAddress(..), ZcashPool(..), ZcashTx(..))
import Zenith.Utils import Zenith.Utils
import Zenith.Zcashd import Zenith.Zcashd
@ -196,8 +199,13 @@ processUri user pwd =
main :: IO () main :: IO ()
main = do main = do
config <- load ["zenith.cfg"] config <- load ["zenith.cfg"]
args <- getArgs
nodeUser <- require config "nodeUser" nodeUser <- require config "nodeUser"
nodePwd <- require config "nodePwd" nodePwd <- require config "nodePwd"
if not (null args)
then do
case head args of
"legacy" -> do
checkServer nodeUser nodePwd checkServer nodeUser nodePwd
void $ void $
runCLI runCLI
@ -207,3 +215,13 @@ main = do
" ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0" " ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0"
} }
(root nodeUser nodePwd) (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
- persistent-sqlite - persistent-sqlite
- persistent-template - persistent-template
- brick
- zcash-haskell - zcash-haskell
executables: executables:
@ -64,6 +65,7 @@ executables:
- text - text
- time - time
- sort - sort
- brick
tests: tests:
zenith-test: 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 library
exposed-modules: exposed-modules:
Zenith.CLI
Zenith.DB Zenith.DB
Zenith.Types Zenith.Types
Zenith.Utils Zenith.Utils
@ -39,6 +40,7 @@ library
, array , array
, base >=4.7 && <5 , base >=4.7 && <5
, base64-bytestring , base64-bytestring
, brick
, bytestring , bytestring
, http-conduit , http-conduit
, http-types , http-types
@ -64,6 +66,7 @@ executable zenith
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wunused-imports ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wunused-imports
build-depends: build-depends:
base >=4.7 && <5 base >=4.7 && <5
, brick
, bytestring , bytestring
, configurator , configurator
, data-default , data-default