ui: use a custom application event type

This commit is contained in:
Simon Michael 2016-11-24 09:10:50 -08:00
parent 015b9570d4
commit 0f1108db07
7 changed files with 12 additions and 12 deletions

View File

@ -247,7 +247,7 @@ asDrawItem (acctwidth, balwidth) selected AccountsScreenItem{..} =
sel | selected = (<> "selected")
| otherwise = id
asHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
asHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
asHandle ui0@UIState{
aScreen=scr@AccountsScreen{..}
,aopts=UIOpts{cliopts_=copts}

View File

@ -68,7 +68,7 @@ esDraw UIState{ --aopts=UIOpts{cliopts_=copts@CliOpts{}}
esDraw _ = error "draw function called with wrong screen type, should not happen"
esHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
esHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
esHandle ui@UIState{
aScreen=ErrorScreen{..}
,aopts=UIOpts{cliopts_=copts}

View File

@ -23,7 +23,6 @@ import qualified Data.Text as T
import Safe
import System.Exit
import qualified Graphics.Vty as V
import Brick
import Hledger
@ -135,7 +134,7 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do
,aMode=Normal
}
brickapp :: App (UIState) V.Event Name
brickapp :: App (UIState) AppEvent Name
brickapp = App {
appStartEvent = return
, appAttrMap = const theme

View File

@ -236,7 +236,7 @@ rsDrawItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected Regist
sel | selected = (<> "selected")
| otherwise = id
rsHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
rsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
rsHandle ui@UIState{
aScreen=s@RegisterScreen{..}
,aopts=UIOpts{cliopts_=copts}

View File

@ -102,7 +102,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
tsDraw _ = error "draw function called with wrong screen type, should not happen"
tsHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
tsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
tsHandle ui@UIState{aScreen=s@TransactionScreen{tsTransaction=(i,t)
,tsTransactions=nts
,tsAccount=acct}

View File

@ -39,7 +39,6 @@ Brick.defaultMain brickapp st
module Hledger.UI.UITypes where
import Data.Time.Calendar (Day)
import Graphics.Vty (Event)
import Brick
import Brick.Widgets.List
import Brick.Widgets.Edit (Editor)
@ -83,6 +82,8 @@ data Name =
| RegisterList
deriving (Ord, Show, Eq)
data AppEvent = DummyEvent
-- | hledger-ui screen types & instances.
-- Each screen type has generically named initialisation, draw, and event handling functions,
-- and zero or more uniquely named screen state fields, which hold the data for a particular
@ -92,7 +93,7 @@ data Screen =
AccountsScreen {
sInit :: Day -> Bool -> UIState -> UIState -- ^ function to initialise or update this screen's state
,sDraw :: UIState -> [Widget Name] -- ^ brick renderer for this screen
,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) -- ^ brick event handler for this screen
,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) -- ^ brick event handler for this screen
-- state fields.These ones have lenses:
,_asList :: List Name AccountsScreenItem -- ^ list widget showing account names & balances
,_asSelectedAccount :: AccountName -- ^ a backup of the account name from the list widget's selected item (or "")
@ -100,7 +101,7 @@ data Screen =
| RegisterScreen {
sInit :: Day -> Bool -> UIState -> UIState
,sDraw :: UIState -> [Widget Name]
,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
--
,rsList :: List Name RegisterScreenItem -- ^ list widget showing transactions affecting this account
,rsAccount :: AccountName -- ^ the account this register is for
@ -111,7 +112,7 @@ data Screen =
| TransactionScreen {
sInit :: Day -> Bool -> UIState -> UIState
,sDraw :: UIState -> [Widget Name]
,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
--
,tsTransaction :: NumberedTransaction -- ^ the transaction we are currently viewing, and its position in the list
,tsTransactions :: [NumberedTransaction] -- ^ list of transactions we can step through
@ -120,7 +121,7 @@ data Screen =
| ErrorScreen {
sInit :: Day -> Bool -> UIState -> UIState
,sDraw :: UIState -> [Widget Name]
,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
--
,esError :: String -- ^ error message to show
}

View File

@ -110,7 +110,7 @@ helpDialog =
renderKey (key,desc) = withAttr (borderAttr <> "keys") (str key) <+> str " " <+> str desc
-- | Event handler used when help mode is active.
helpHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)
helpHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
helpHandle ui ev =
case ev of
VtyEvent (EvKey k []) | k `elem` [KEsc, KLeft, KChar 'h', KChar '?'] -> continue $ setMode Normal ui