Implement help dialog

This commit is contained in:
Rene Vergara 2024-02-13 14:19:05 -06:00
parent f55a724f99
commit 1022944e67
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
2 changed files with 24 additions and 4 deletions

View file

@ -23,8 +23,10 @@ import Brick.Widgets.Core
( Padding(..) ( Padding(..)
, (<+>) , (<+>)
, (<=>) , (<=>)
, emptyWidget
, hLimit , hLimit
, joinBorders , joinBorders
, padAll
, padRight , padRight
, str , str
, vBox , vBox
@ -32,6 +34,7 @@ import Brick.Widgets.Core
, withAttr , withAttr
, withBorderStyle , withBorderStyle
) )
import qualified Brick.Widgets.Dialog as D
import qualified Brick.Widgets.List as L import qualified Brick.Widgets.List as L
import qualified Data.Vector as Vec import qualified Data.Vector as Vec
import Network.HTTP.Simple import Network.HTTP.Simple
@ -42,6 +45,7 @@ data Name
= WList = WList
| AList | AList
| TList | TList
| HelpDialog
deriving (Eq, Show, Ord) deriving (Eq, Show, Ord)
data State = State data State = State
@ -50,12 +54,13 @@ data State = State
, _addresses :: !(L.List Name String) , _addresses :: !(L.List Name String)
, _transactions :: !(L.List Name String) , _transactions :: !(L.List Name String)
, _msg :: !String , _msg :: !String
, _helpBox :: !Bool
} deriving (Show) } deriving (Show)
makeLenses ''State makeLenses ''State
drawUI :: State -> [Widget Name] drawUI :: State -> [Widget Name]
drawUI s = [ui s] drawUI s = [helpDialog s, ui s]
where where
ui :: State -> Widget Name ui :: State -> Widget Name
ui s = ui s =
@ -79,6 +84,17 @@ drawUI s = [ui s]
msgBox m = msgBox m =
vBox vBox
[B.hBorderWithLabel (str "Messages"), hLimit 70 $ padRight Max $ str m] [B.hBorderWithLabel (str "Messages"), hLimit 70 $ padRight Max $ str m]
helpDialog :: State -> Widget Name
helpDialog s =
if s ^. helpBox
then D.renderDialog
(D.dialog (Just (str "Commands")) Nothing 50)
(vBox ([C.hCenter $ str "Key", B.hBorder] <> keyList) <+>
vBox ([str "Actions", B.hBorder] <> actionList))
else emptyWidget
where
keyList = map (C.hCenter . str) ["?", "Esc", "q"]
actionList = map (hLimit 40 . str) ["Open help", "Close dialog", "Quit"]
listDrawElement :: (Show a) => Bool -> a -> Widget Name listDrawElement :: (Show a) => Bool -> a -> Widget Name
listDrawElement sel a = listDrawElement sel a =
@ -94,7 +110,9 @@ customAttr = L.listSelectedAttr <> A.attrName "custom"
appEvent :: BT.BrickEvent Name e -> BT.EventM Name State () appEvent :: BT.BrickEvent Name e -> BT.EventM Name State ()
appEvent (BT.VtyEvent e) = appEvent (BT.VtyEvent e) =
case e of case e of
V.EvKey V.KEsc [] -> M.halt V.EvKey V.KEsc [] -> BT.modify $ set helpBox False
V.EvKey (V.KChar 'q') [] -> M.halt
V.EvKey (V.KChar '?') [] -> BT.modify $ set helpBox True
V.EvKey (V.KChar 'c') [] -> printMsg "You pressed C!" V.EvKey (V.KChar 'c') [] -> printMsg "You pressed C!"
V.EvKey (V.KChar 's') [] -> printMsg "You pressed S!" V.EvKey (V.KChar 's') [] -> printMsg "You pressed S!"
ev -> BT.zoom addresses $ L.handleListEvent ev ev -> BT.zoom addresses $ L.handleListEvent ev
@ -141,6 +159,7 @@ runZenithCLI port dbName = do
(L.list TList (Vec.fromList ["tx1", "tx2", "tx3"]) 1) (L.list TList (Vec.fromList ["tx1", "tx2", "tx3"]) 1)
("Start up Ok! Connected to Zebra " ++ ("Start up Ok! Connected to Zebra " ++
(T.unpack . zgi_build) zebra ++ " on port " ++ show port ++ ".") (T.unpack . zgi_build) zebra ++ " on port " ++ show port ++ ".")
False
Nothing -> do Nothing -> do
print $ print $
"No Zebra node available on port " <> "No Zebra node available on port " <>

View file

@ -16,10 +16,11 @@ import Zenith.DB
-- | Returns the list of wallets available in the given database -- | Returns the list of wallets available in the given database
checkWallets :: checkWallets ::
T.Text -- ^ The database name to check T.Text -- ^ The database name to check
-> ZcashNet -- ^ The network the wallet is running
-> IO [Entity ZcashWallet] -> IO [Entity ZcashWallet]
checkWallets dbName = do checkWallets dbName znet = do
runSqlite dbName $ do runMigration migrateAll runSqlite dbName $ do runMigration migrateAll
runSqlite dbName $ selectList [ZcashWalletBirthdayHeight >. 0] [] runSqlite dbName $ selectList [ZcashWalletNetwork ==. znet] []
-- * Zebra Node interaction -- * Zebra Node interaction
-- | Checks the status of the `zebrad` node -- | Checks the status of the `zebrad` node