Implements a help dialog in the TUI #63

Merged
pitmutt merged 3 commits from rav001 into dev041 2024-02-13 22:12:37 +00:00
2 changed files with 24 additions and 4 deletions
Showing only changes of commit 1022944e67 - Show all commits

View file

@ -23,8 +23,10 @@ import Brick.Widgets.Core
( Padding(..)
, (<+>)
, (<=>)
, emptyWidget
, hLimit
, joinBorders
, padAll
, padRight
, str
, vBox
@ -32,6 +34,7 @@ import Brick.Widgets.Core
, withAttr
, withBorderStyle
)
import qualified Brick.Widgets.Dialog as D
import qualified Brick.Widgets.List as L
import qualified Data.Vector as Vec
import Network.HTTP.Simple
@ -42,6 +45,7 @@ data Name
= WList
| AList
| TList
| HelpDialog
deriving (Eq, Show, Ord)
data State = State
@ -50,12 +54,13 @@ data State = State
, _addresses :: !(L.List Name String)
, _transactions :: !(L.List Name String)
, _msg :: !String
, _helpBox :: !Bool
} deriving (Show)
makeLenses ''State
drawUI :: State -> [Widget Name]
drawUI s = [ui s]
drawUI s = [helpDialog s, ui s]
where
ui :: State -> Widget Name
ui s =
@ -79,6 +84,17 @@ drawUI s = [ui s]
msgBox m =
vBox
[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 sel a =
@ -94,7 +110,9 @@ customAttr = L.listSelectedAttr <> A.attrName "custom"
appEvent :: BT.BrickEvent Name e -> BT.EventM Name State ()
appEvent (BT.VtyEvent e) =
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 's') [] -> printMsg "You pressed S!"
ev -> BT.zoom addresses $ L.handleListEvent ev
@ -141,6 +159,7 @@ runZenithCLI port dbName = do
(L.list TList (Vec.fromList ["tx1", "tx2", "tx3"]) 1)
("Start up Ok! Connected to Zebra " ++
(T.unpack . zgi_build) zebra ++ " on port " ++ show port ++ ".")
False
Nothing -> do
print $
"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
checkWallets ::
T.Text -- ^ The database name to check
-> ZcashNet -- ^ The network the wallet is running
-> IO [Entity ZcashWallet]
checkWallets dbName = do
checkWallets dbName znet = do
runSqlite dbName $ do runMigration migrateAll
runSqlite dbName $ selectList [ZcashWalletBirthdayHeight >. 0] []
runSqlite dbName $ selectList [ZcashWalletNetwork ==. znet] []
-- * Zebra Node interaction
-- | Checks the status of the `zebrad` node