ui: cleanup, haddocks

This commit is contained in:
Simon Michael 2016-06-07 07:04:32 -07:00
parent a216c7216a
commit 7a951a8dd7
2 changed files with 85 additions and 44 deletions

View File

@ -126,15 +126,15 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do
,aPrevScreens=prevscrs ,aPrevScreens=prevscrs
,aMinibuffer=Nothing ,aMinibuffer=Nothing
} }
app :: App (AppState) V.Event brickapp :: App (AppState) V.Event
app = App { brickapp = App {
appLiftVtyEvent = id appLiftVtyEvent = id
, appStartEvent = return , appStartEvent = return
, appAttrMap = const theme , appAttrMap = const theme
, appChooseCursor = showFirstCursor , appChooseCursor = showFirstCursor
, appHandleEvent = \st ev -> sHandleFn (aScreen st) st ev , appHandleEvent = \st ev -> sHandleFn (aScreen st) st ev
, appDraw = \st -> sDrawFn (aScreen st) st , appDraw = \st -> sDrawFn (aScreen st) st
-- XXX bizarro. removing the st arg and parameter above, -- XXX bizarro. removing the st arg and parameter above,
-- which according to GHCI does not change the type, -- which according to GHCI does not change the type,
-- causes "Exception: draw function called with wrong screen type" -- causes "Exception: draw function called with wrong screen type"
@ -142,5 +142,5 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do
-- causes an exception on exiting a register. -- causes an exception on exiting a register.
} }
void $ defaultMain app st void $ defaultMain brickapp st

View File

@ -1,3 +1,34 @@
{- |
Overview:
hledger-ui's AppState holds the active screen and any previously visited screens.
Screens have their own render state, render function, event handler,
and app state update function (which can update the whole AppState).
A brick App delegates event-handling and rendering to our AppState's active screen.
@
Brick.defaultMain brickapp st
where
brickapp :: App (AppState) V.Event
brickapp = App {
appLiftVtyEvent = id
, appStartEvent = return
, appAttrMap = const theme
, appChooseCursor = showFirstCursor
, appHandleEvent = \st ev -> sHandleFn (aScreen st) st ev
, appDraw = \st -> sDrawFn (aScreen st) st
}
st :: AppState
st = (sInitFn scr) d
AppState{
aopts=uopts'
,ajournal=j
,aScreen=scr
,aPrevScreens=prevscrs
,aMinibuffer=Nothing
}
@
-}
{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE StandaloneDeriving #-}
module Hledger.UI.UITypes where module Hledger.UI.UITypes where
@ -13,58 +44,68 @@ import Text.Show.Functions ()
import Hledger import Hledger
import Hledger.UI.UIOptions import Hledger.UI.UIOptions
---------------------------------------------------------------------- -- | hledger-ui's application state. This holds one or more stateful screens.
instance Show Editor
where
show = const "<Editor>"
-- | hledger-ui's application state. This is part of, but distinct
-- from, brick's App.
data AppState = AppState { data AppState = AppState {
aopts :: UIOpts -- ^ the command-line options and query currently in effect aopts :: UIOpts -- ^ the command-line options and query arguments currently in effect
,ajournal :: Journal -- ^ the journal being viewed ,ajournal :: Journal -- ^ the journal being viewed
,aScreen :: Screen -- ^ the currently active screen ,aScreen :: Screen -- ^ the currently active screen
,aPrevScreens :: [Screen] -- ^ previously visited screens, most recent first ,aPrevScreens :: [Screen] -- ^ previously visited screens, most recent first
,aMinibuffer :: Maybe Editor -- ^ a compact editor used for data entry, when active ,aMinibuffer :: Maybe Editor -- ^ a compact editor used for data entry, when active
} deriving (Show) } deriving (Show)
-- | Types of screen available within the app, along with their state. -- | Types of screen available within hledger-ui. Each has its own
-- Screen types are distinguished by their constructor and their state -- specific state type, and generic initialisation, event handling
-- field, which must have unique names. -- and rendering functions.
-- --
-- This type causes partial functions, so take care. -- Screen types are pattern-matched by their constructor and their
-- state field, which must have a unique name. This type causes
-- partial functions, so take care.
data Screen = data Screen =
AccountsScreen { AccountsScreen {
asState :: (List (Int,AccountName,AccountName,[String]), AccountName) -- ^ list widget holding (indent level, full account name, full or short account name to display, rendered amounts); asState :: (List -- list widget holding:
-- the full name of the currently selected account (or "") (Int -- indent level
,sInitFn :: Day -> AppState -> AppState -- ^ function to initialise the screen's state on entry ,AccountName -- full account name
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState) -- ^ brick event handler to use for this screen ,AccountName -- full or short account name to display
,sDrawFn :: AppState -> [Widget] -- ^ brick renderer to use for this screen ,[String] -- rendered amounts
)
,AccountName -- full name of the currently selected account (or "")
)
,sInitFn :: Day -> AppState -> AppState -- ^ function to generate the screen's state on entry or change
,sDrawFn :: AppState -> [Widget] -- ^ brick renderer to use for this screen
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState) -- ^ brick event handler to use for this screen
} }
| RegisterScreen { | RegisterScreen {
rsState :: (List (String,String,String,String,String,Transaction), AccountName) rsState :: (List -- list widget holding:
-- ^ list widget holding (date, description, other accts, change amt, balance amt, and the full transaction); (String -- date
-- the full name of the account we are showing a register for ,String -- description
,sInitFn :: Day -> AppState -> AppState ,String -- other accts
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState) ,String -- change amt
,sDrawFn :: AppState -> [Widget] ,String -- balance amt
,Transaction -- the full transaction
)
,AccountName -- full name of the acct we are showing a register for
)
,sInitFn :: Day -> AppState -> AppState -- ^ function to generate the screen's state on entry or change
,sDrawFn :: AppState -> [Widget] -- ^ brick renderer to use for this screen
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState) -- ^ brick event handler to use for this screen
} }
| TransactionScreen { | TransactionScreen {
tsState :: ((Integer,Transaction), [(Integer,Transaction)], AccountName) tsState :: ((Integer, Transaction) -- the (numbered) transaction we are currently viewing
-- ^ the (numbered) transaction we are currently viewing, ,[(Integer, Transaction)] -- the list of numbered transactions we can step through
-- the list of numbered transactions we can step through, ,AccountName -- the account whose register we entered this screen from
-- and the account whose register we entered this screen from )
,sInitFn :: Day -> AppState -> AppState ,sInitFn :: Day -> AppState -> AppState
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState) ,sDrawFn :: AppState -> [Widget]
,sDrawFn :: AppState -> [Widget] ,sHandleFn :: AppState -> V.Event -> EventM (Next AppState)
} }
| ErrorScreen { | ErrorScreen {
esState :: String -- ^ error message to display esState :: String -- error message to display
,sInitFn :: Day -> AppState -> AppState ,sInitFn :: Day -> AppState -> AppState
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState) ,sDrawFn :: AppState -> [Widget]
,sDrawFn :: AppState -> [Widget] ,sHandleFn :: AppState -> V.Event -> EventM (Next AppState)
} }
deriving (Show) deriving (Show)
instance Show (List a) where show _ = "<List>" instance Show (List a) where show _ = "<List>"
instance Show Editor where show _ = "<Editor>"