Add command guides to screens

This commit is contained in:
Rene Vergara 2024-03-17 14:38:26 -05:00
parent bd32eb4f38
commit 466491a7d0
Signed by: pitmutt
GPG Key ID: 65122AD495A7F5B2
1 changed files with 54 additions and 9 deletions

View File

@ -28,6 +28,7 @@ import Brick.Widgets.Core
, (<=>) , (<=>)
, emptyWidget , emptyWidget
, fill , fill
, hBox
, hLimit , hLimit
, joinBorders , joinBorders
, padAll , padAll
@ -35,6 +36,7 @@ import Brick.Widgets.Core
, str , str
, strWrap , strWrap
, txt , txt
, txtWrap
, txtWrapWith , txtWrapWith
, vBox , vBox
, vLimit , vLimit
@ -48,6 +50,7 @@ import Control.Monad (void)
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import Data.Maybe import Data.Maybe
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import qualified Data.Vector as Vec import qualified Data.Vector as Vec
import Database.Persist import Database.Persist
import qualified Graphics.Vty as V import qualified Graphics.Vty as V
@ -88,6 +91,7 @@ data DialogType
data DisplayType data DisplayType
= AddrDisplay = AddrDisplay
| MsgDisplay | MsgDisplay
| PhraseDisplay
| BlankDisplay | BlankDisplay
data State = State data State = State
@ -135,7 +139,14 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
(\(_, a) -> zcashAccountName $ entityVal a) (\(_, a) -> zcashAccountName $ entityVal a)
(L.listSelectedElement (st ^. accounts))))) <=> (L.listSelectedElement (st ^. accounts))))) <=>
listAddressBox "Addresses" (st ^. addresses) <+> listAddressBox "Addresses" (st ^. addresses) <+>
B.vBorder <+> C.center (listBox "Transactions" (st ^. transactions))) B.vBorder <+> C.center (listBox "Transactions" (st ^. transactions))) <=>
C.hCenter
(hBox
[ capCommand "W" "allets"
, capCommand "A" "ccounts"
, capCommand "V" "iew address"
, capCommand "Q" "uit"
])
listBox :: Show e => String -> L.List Name e -> Widget Name listBox :: Show e => String -> L.List Name e -> Widget Name
listBox titleLabel l = listBox titleLabel l =
C.vCenter $ C.vCenter $
@ -158,7 +169,6 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
(B.borderWithLabel (str titleLabel) $ (B.borderWithLabel (str titleLabel) $
hLimit 25 $ vLimit 15 $ L.renderList drawF True l) hLimit 25 $ vLimit 15 $ L.renderList drawF True l)
, str " " , str " "
, C.hCenter $ str "Select "
] ]
listAddressBox :: listAddressBox ::
String -> L.List Name (Entity WalletAddress) -> Widget Name String -> L.List Name (Entity WalletAddress) -> Widget Name
@ -209,11 +219,26 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
WSelect -> WSelect ->
D.renderDialog D.renderDialog
(D.dialog (Just (str "Select Wallet")) Nothing 50) (D.dialog (Just (str "Select Wallet")) Nothing 50)
(selectListBox "Wallets" (st ^. wallets) listDrawWallet) (selectListBox "Wallets" (st ^. wallets) listDrawWallet <=>
C.hCenter
(hBox
[ capCommand "↑↓ " "move"
, capCommand "" "select"
, capCommand "N" "ew"
, capCommand "S" "how phrase"
, xCommand
]))
ASelect -> ASelect ->
D.renderDialog D.renderDialog
(D.dialog (Just (str "Select Account")) Nothing 50) (D.dialog (Just (str "Select Account")) Nothing 50)
(selectListBox "Accounts" (st ^. accounts) listDrawAccount) (selectListBox "Accounts" (st ^. accounts) listDrawAccount <=>
C.hCenter
(hBox
[ capCommand "↑↓ " "move"
, capCommand "" "select"
, capCommand "N" "ew"
, xCommand
]))
Blank -> emptyWidget Blank -> emptyWidget
splashDialog :: State -> Widget Name splashDialog :: State -> Widget Name
splashDialog st = splashDialog st =
@ -225,9 +250,13 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
titleAttr titleAttr
(str (str
" _____ _ _ _ \n|__ /___ _ __ (_) |_| |__\n / // _ \\ '_ \\| | __| '_ \\\n / /| __/ | | | | |_| | | |\n/____\\___|_| |_|_|\\__|_| |_|") <=> " _____ _ _ _ \n|__ /___ _ __ (_) |_| |__\n / // _ \\ '_ \\| | __| '_ \\\n / /| __/ | | | | |_| | | |\n/____\\___|_| |_|_|\\__|_| |_|") <=>
C.hCenter (withAttr titleAttr (str "Zcash Wallet v0.4.3.0")) <=> C.hCenter (withAttr titleAttr (str "Zcash Wallet v0.4.4.0")) <=>
C.hCenter (withAttr blinkAttr $ str "Press any key...")) C.hCenter (withAttr blinkAttr $ str "Press any key..."))
else emptyWidget else emptyWidget
capCommand :: String -> String -> Widget Name
capCommand k comm = hBox [withAttr titleAttr (str k), str comm, str " | "]
xCommand :: Widget Name
xCommand = hBox [str "E", withAttr titleAttr (str "x"), str "it"]
displayDialog :: State -> Widget Name displayDialog :: State -> Widget Name
displayDialog st = displayDialog st =
case st ^. displayBox of case st ^. displayBox of
@ -244,6 +273,17 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
txtWrapWith (WrapSettings False True NoFill FillAfterFirst) $ txtWrapWith (WrapSettings False True NoFill FillAfterFirst) $
getUA $ walletAddressUAddress $ entityVal a) getUA $ walletAddressUAddress $ entityVal a)
Nothing -> emptyWidget Nothing -> emptyWidget
PhraseDisplay ->
case L.listSelectedElement $ st ^. wallets of
Just (_, w) ->
withBorderStyle unicodeBold $
D.renderDialog
(D.dialog (Just $ txt "Seed Phrase") Nothing 50)
(padAll 1 $
txtWrap $
E.decodeUtf8Lenient $
getBytes $ getPhrase $ zcashWalletSeedPhrase $ entityVal w)
Nothing -> emptyWidget
MsgDisplay -> MsgDisplay ->
withBorderStyle unicodeBold $ withBorderStyle unicodeBold $
D.renderDialog D.renderDialog
@ -319,6 +359,7 @@ appEvent (BT.VtyEvent e) = do
case s ^. displayBox of case s ^. displayBox of
AddrDisplay -> BT.modify $ set displayBox BlankDisplay AddrDisplay -> BT.modify $ set displayBox BlankDisplay
MsgDisplay -> BT.modify $ set displayBox BlankDisplay MsgDisplay -> BT.modify $ set displayBox BlankDisplay
PhraseDisplay -> BT.modify $ set displayBox BlankDisplay
BlankDisplay -> do BlankDisplay -> do
case s ^. dialogBox of case s ^. dialogBox of
WName -> do WName -> do
@ -372,26 +413,30 @@ appEvent (BT.VtyEvent e) = do
BT.zoom inputForm $ handleFormEvent (BT.VtyEvent ev) BT.zoom inputForm $ handleFormEvent (BT.VtyEvent ev)
WSelect -> do WSelect -> do
case e of case e of
V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank V.EvKey (V.KChar 'x') [] ->
BT.modify $ set dialogBox Blank
V.EvKey V.KEnter [] -> do V.EvKey V.KEnter [] -> do
ns <- liftIO $ refreshWallet s ns <- liftIO $ refreshWallet s
BT.put ns BT.put ns
BT.modify $ set dialogBox Blank BT.modify $ set dialogBox Blank
V.EvKey (V.KChar 'c') [] -> do V.EvKey (V.KChar 'n') [] -> do
BT.modify $ BT.modify $
set inputForm $ set inputForm $
updateFormState (DialogInput "New Wallet") $ updateFormState (DialogInput "New Wallet") $
s ^. inputForm s ^. inputForm
BT.modify $ set dialogBox WName BT.modify $ set dialogBox WName
V.EvKey (V.KChar 's') [] ->
BT.modify $ set displayBox PhraseDisplay
ev -> BT.zoom wallets $ L.handleListEvent ev ev -> BT.zoom wallets $ L.handleListEvent ev
ASelect -> do ASelect -> do
case e of case e of
V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank V.EvKey (V.KChar 'x') [] ->
BT.modify $ set dialogBox Blank
V.EvKey V.KEnter [] -> do V.EvKey V.KEnter [] -> do
ns <- liftIO $ refreshAccount s ns <- liftIO $ refreshAccount s
BT.put ns BT.put ns
BT.modify $ set dialogBox Blank BT.modify $ set dialogBox Blank
V.EvKey (V.KChar 'c') [] -> do V.EvKey (V.KChar 'n') [] -> do
BT.modify $ BT.modify $
set inputForm $ set inputForm $
updateFormState (DialogInput "New Account") $ updateFormState (DialogInput "New Account") $