| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.UI.UITypes
Contents
Description
hledger-ui's UIState holds the currently active screen and any previously visited screens (and their states). The brick App delegates all event-handling and rendering to the UIState's active screen. Screens have their own screen state, render function, event handler, and app state update function, so they have full control.
Brick.defaultMain brickapp st
where
brickapp :: App (UIState) V.Event
brickapp = App {
appLiftVtyEvent = id
, appStartEvent = return
, appAttrMap = const theme
, appChooseCursor = showFirstCursor
, appHandleEvent = st ev -> sHandle (aScreen st) st ev
, appDraw = st -> sDraw (aScreen st) st
}
st :: UIState
st = (sInit s) d
UIState{
aopts=uopts'
,ajournal=j
,aScreen=s
,aPrevScreens=prevscrs
,aMinibuffer=Nothing
}
Synopsis
- data AppEvent
- = FileChange
- | DateChange Day Day
- data UIState = UIState {}
- data Mode
- = Normal
- | Help
- | Minibuffer Text (Editor String Name)
- data Name
- data ScreenName
- data Screen
- data AccountsLikeScreen = ALS (AccountsScreenState -> Screen) AccountsScreenState
- toAccountsLikeScreen :: Screen -> Maybe AccountsLikeScreen
- fromAccountsLikeScreen :: AccountsLikeScreen -> Screen
- data MenuScreenState = MSS {
- _mssList :: List Name MenuScreenItem
- _mssUnused :: ()
- data AccountsScreenState = ASS {
- _assSelectedAccount :: AccountName
- _assList :: List Name AccountsScreenItem
- data RegisterScreenState = RSS {
- _rssAccount :: AccountName
- _rssForceInclusive :: Bool
- _rssList :: List Name RegisterScreenItem
- data TransactionScreenState = TSS {
- _tssAccount :: AccountName
- _tssTransactions :: [NumberedTransaction]
- _tssTransaction :: NumberedTransaction
- data ErrorScreenState = ESS {
- _essError :: String
- _essUnused :: ()
- data MenuScreenItem = MenuScreenItem {
- msItemScreenName :: Text
- msItemScreen :: ScreenName
- data AccountsScreenItem = AccountsScreenItem {
- asItemIndentLevel :: Int
- asItemAccountName :: AccountName
- asItemDisplayAccountName :: AccountName
- asItemMixedAmount :: Maybe MixedAmount
- data RegisterScreenItem = RegisterScreenItem {
- rsItemDate :: Text
- rsItemStatus :: Status
- rsItemDescription :: Text
- rsItemOtherAccounts :: Text
- rsItemChangeAmount :: WideBuilder
- rsItemBalanceAmount :: WideBuilder
- rsItemTransaction :: Transaction
- type NumberedTransaction = (Integer, Transaction)
- mssList :: Lens' MenuScreenState (List Name MenuScreenItem)
- mssUnused :: Lens' MenuScreenState ()
- assList :: Lens' AccountsScreenState (List Name AccountsScreenItem)
- assSelectedAccount :: Lens' AccountsScreenState AccountName
- rssAccount :: Lens' RegisterScreenState AccountName
- rssForceInclusive :: Lens' RegisterScreenState Bool
- rssList :: Lens' RegisterScreenState (List Name RegisterScreenItem)
- tssAccount :: Lens' TransactionScreenState AccountName
- tssTransaction :: Lens' TransactionScreenState NumberedTransaction
- tssTransactions :: Lens' TransactionScreenState [NumberedTransaction]
- essError :: Lens' ErrorScreenState String
- essUnused :: Lens' ErrorScreenState ()
- errorWrongScreenType :: String -> a
- uioptslens :: Functor f => (UIOpts -> f UIOpts) -> UIState -> f UIState
Documentation
Constructors
| FileChange | |
| DateChange Day Day |
hledger-ui's application state. This holds one or more stateful screens. As you navigate through screens, the old ones are saved in a stack. The app can be in one of several modes: normal screen operation, showing a help dialog, entering data in the minibuffer etc.
Constructors
| UIState | |
Fields
| |
Instances
| Show UIState Source # | |
| HasCliOpts UIState Source # | |
Defined in Hledger.UI.UITypes Methods cliOpts :: Lens' UIState CliOpts available_width :: Lens' UIState Int coloropt :: Lens' UIState (Maybe YNA) command :: Lens' UIState String file__ :: Lens' UIState [FilePath] inputopts :: Lens' UIState InputOpts no_new_accounts :: Lens' UIState Bool output_file :: Lens' UIState (Maybe FilePath) output_format :: Lens' UIState (Maybe String) pageropt :: Lens' UIState (Maybe Bool) progstarttime :: Lens' UIState POSIXTime rawopts__ :: Lens' UIState RawOpts reportspec :: Lens' UIState ReportSpec | |
| HasBalancingOpts UIState Source # | |
Defined in Hledger.UI.UITypes Methods balancingOpts :: Lens' UIState BalancingOpts commodity_styles :: Lens' UIState (Maybe (Map CommoditySymbol AmountStyle)) ignore_assertions :: Lens' UIState Bool infer_balancing_costs :: Lens' UIState Bool txn_balancing :: Lens' UIState TransactionBalancingPrecision | |
| HasInputOpts UIState Source # | |
Defined in Hledger.UI.UITypes Methods inputOpts :: Lens' UIState InputOpts aliases :: Lens' UIState [String] balancingopts :: Lens' UIState BalancingOpts forecast :: Lens' UIState (Maybe DateSpan) infer_costs :: Lens' UIState Bool infer_equity :: Lens' UIState Bool mformat :: Lens' UIState (Maybe StorageFormat) mrules_file :: Lens' UIState (Maybe FilePath) new_save :: Lens' UIState Bool oldtimeclock :: Lens' UIState Bool posting_account_tags :: Lens' UIState Bool reportspan :: Lens' UIState DateSpan verbose_tags :: Lens' UIState Bool | |
| HasReportOpts UIState Source # | |
Defined in Hledger.UI.UITypes | |
| HasReportOptsNoUpdate UIState Source # | |
Defined in Hledger.UI.UITypes Methods reportOptsNoUpdate :: Lens' UIState ReportOpts accountlistmode :: Lens' UIState AccountListMode balance_base_url :: Lens' UIState (Maybe Text) balanceaccum :: Lens' UIState BalanceAccumulation balancecalc :: Lens' UIState BalanceCalculation budgetpat :: Lens' UIState (Maybe Text) conversionop :: Lens' UIState (Maybe ConversionOp) date2NoUpdate :: Lens' UIState Bool declared :: Lens' UIState Bool depthNoUpdate :: Lens' UIState DepthSpec format :: Lens' UIState StringFormat infer_prices :: Lens' UIState Bool interval :: Lens' UIState Interval layout :: Lens' UIState Layout no_elide :: Lens' UIState Bool no_total :: Lens' UIState Bool normalbalance :: Lens' UIState (Maybe NormalSign) periodNoUpdate :: Lens' UIState Period querystringNoUpdate :: Lens' UIState [Text] realNoUpdate :: Lens' UIState Bool row_total :: Lens' UIState Bool show_costs :: Lens' UIState Bool sort_amount :: Lens' UIState Bool sortspec :: Lens' UIState SortSpec statusesNoUpdate :: Lens' UIState [Status] summary_only :: Lens' UIState Bool transpose__ :: Lens' UIState Bool | |
| HasReportSpec UIState Source # | |
Defined in Hledger.UI.UITypes Methods reportSpec :: Lens' UIState ReportSpec rsQuery :: Lens' UIState Query rsQueryOpts :: Lens' UIState [QueryOpt] rsReportOpts :: Lens' UIState ReportOpts | |
Any screen can be in one of several modes, which modifies its rendering and event handling. The mode resets to Normal when entering a new screen.
Constructors
| Normal | |
| Help | |
| Minibuffer Text (Editor String Name) |
Constructors
| HelpDialog | |
| MinibufferEditor | |
| MenuList | |
| AccountsViewport | |
| AccountsList | |
| RegisterViewport | |
| RegisterList | |
| TransactionEditor |
data ScreenName Source #
Constructors
| Accounts | |
| CashScreen | |
| Balancesheet | |
| Incomestatement |
Instances
| Show ScreenName Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> ScreenName -> ShowS show :: ScreenName -> String showList :: [ScreenName] -> ShowS | |
| Eq ScreenName Source # | |
Defined in Hledger.UI.UITypes | |
| Ord ScreenName Source # | |
Defined in Hledger.UI.UITypes Methods compare :: ScreenName -> ScreenName -> Ordering (<) :: ScreenName -> ScreenName -> Bool (<=) :: ScreenName -> ScreenName -> Bool (>) :: ScreenName -> ScreenName -> Bool (>=) :: ScreenName -> ScreenName -> Bool max :: ScreenName -> ScreenName -> ScreenName min :: ScreenName -> ScreenName -> ScreenName | |
hledger-ui screen types, v1, "one screen = one module" These types aimed for maximum decoupling of modules and ease of adding more screens. A new screen requires 1. a new constructor in the Screen type, 2. a new module implementing initdrawhandle functions, 3. a call from any other screen which enters it. 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 instance of this screen. Note the latter create partial functions, which means that some invalid cases need to be handled, and also that their lenses are traversals, not single-value getters. 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 :: BrickEvent Name AppEvent -> EventM Name 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 "") } | RegisterScreen { sInit :: Day -> Bool -> UIState -> UIState ,sDraw :: UIState -> [Widget Name] ,sHandle :: BrickEvent Name AppEvent -> EventM Name UIState () -- ,rsList :: List Name RegisterScreenItem -- ^ list widget showing transactions affecting this account ,rsAccount :: AccountName -- ^ the account this register is for ,rsForceInclusive :: Bool -- ^ should this register always include subaccount transactions, -- even when in flat mode ? (ie because entered from a -- depth-clipped accounts screen item) } | TransactionScreen { sInit :: Day -> Bool -> UIState -> UIState ,sDraw :: UIState -> [Widget Name] ,sHandle :: BrickEvent Name AppEvent -> EventM Name UIState () -- ,tsTransaction :: NumberedTransaction -- ^ the transaction we are currently viewing, and its position in the list ,tsTransactions :: [NumberedTransaction] -- ^ list of transactions we can step through ,tsAccount :: AccountName -- ^ the account whose register we entered this screen from } | ErrorScreen { sInit :: Day -> Bool -> UIState -> UIState ,sDraw :: UIState -> [Widget Name] ,sHandle :: BrickEvent Name AppEvent -> EventM Name UIState () -- ,esError :: String -- ^ error message to show } deriving (Show)
hledger-ui screen types, v2, "more parts, but simpler parts" These types aim to be more restrictive, allowing fewer invalid states, and easier to inspect and debug. The screen types store only state, not behaviour (functions), and there is no longer a circular dependency between UIState and Screen. A new screen requires 1. a new constructor in the Screen type 2. a new screen state type if needed 3. a new case in toAccountsLikeScreen if needed 4. new cases in the uiDraw and uiHandle functions 5. new constructor and updater functions in UIScreens, and a new case in screenUpdate 6. a new module implementing draw and event-handling functions 7. a call from any other screen which enters it (eg the menu screen, a new case in msEnterScreen) 8. if it appears on the main menu: a new menu item in msNew
The various screens which a user can navigate to in hledger-ui, along with any screen-specific parameters or data influencing what they display. (The separate state types add code noise but seem to reduce partial code/invalid data a bit.)
data AccountsLikeScreen Source #
A subset of the screens which reuse the account screen's state and logic. Such Screens can be converted to and from this more restrictive type for cleaner code.
Constructors
| ALS (AccountsScreenState -> Screen) AccountsScreenState |
Instances
| Show AccountsLikeScreen Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> AccountsLikeScreen -> ShowS show :: AccountsLikeScreen -> String showList :: [AccountsLikeScreen] -> ShowS | |
toAccountsLikeScreen :: Screen -> Maybe AccountsLikeScreen Source #
data MenuScreenState Source #
Constructors
| MSS | |
Fields
| |
Instances
| Show MenuScreenState Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> MenuScreenState -> ShowS show :: MenuScreenState -> String showList :: [MenuScreenState] -> ShowS | |
data AccountsScreenState Source #
Constructors
| ASS | |
Fields
| |
Instances
| Show AccountsScreenState Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> AccountsScreenState -> ShowS show :: AccountsScreenState -> String showList :: [AccountsScreenState] -> ShowS | |
data RegisterScreenState Source #
Constructors
| RSS | |
Fields
| |
Instances
| Show RegisterScreenState Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> RegisterScreenState -> ShowS show :: RegisterScreenState -> String showList :: [RegisterScreenState] -> ShowS | |
data TransactionScreenState Source #
Constructors
| TSS | |
Fields
| |
Instances
| Show TransactionScreenState Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> TransactionScreenState -> ShowS show :: TransactionScreenState -> String showList :: [TransactionScreenState] -> ShowS | |
data ErrorScreenState Source #
Constructors
| ESS | |
Fields
| |
Instances
| Show ErrorScreenState Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> ErrorScreenState -> ShowS show :: ErrorScreenState -> String showList :: [ErrorScreenState] -> ShowS | |
data MenuScreenItem Source #
An item in the menu screen's list of screens.
Constructors
| MenuScreenItem | |
Fields
| |
Instances
| Show MenuScreenItem Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> MenuScreenItem -> ShowS show :: MenuScreenItem -> String showList :: [MenuScreenItem] -> ShowS | |
data AccountsScreenItem Source #
An item in the accounts screen's list of accounts and balances.
Constructors
| AccountsScreenItem | |
Fields
| |
Instances
| Show AccountsScreenItem Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> AccountsScreenItem -> ShowS show :: AccountsScreenItem -> String showList :: [AccountsScreenItem] -> ShowS | |
data RegisterScreenItem Source #
An item in the register screen's list of transactions in the current account.
Constructors
| RegisterScreenItem | |
Fields
| |
Instances
| Show RegisterScreenItem Source # | |
Defined in Hledger.UI.UITypes Methods showsPrec :: Int -> RegisterScreenItem -> ShowS show :: RegisterScreenItem -> String showList :: [RegisterScreenItem] -> ShowS | |
type NumberedTransaction = (Integer, Transaction) Source #
mssList :: Lens' MenuScreenState (List Name MenuScreenItem) Source #
mssUnused :: Lens' MenuScreenState () Source #
assList :: Lens' AccountsScreenState (List Name AccountsScreenItem) Source #
assSelectedAccount :: Lens' AccountsScreenState AccountName Source #
rssAccount :: Lens' RegisterScreenState AccountName Source #
rssForceInclusive :: Lens' RegisterScreenState Bool Source #
rssList :: Lens' RegisterScreenState (List Name RegisterScreenItem) Source #
tssAccount :: Lens' TransactionScreenState AccountName Source #
essError :: Lens' ErrorScreenState String Source #
essUnused :: Lens' ErrorScreenState () Source #
errorWrongScreenType :: String -> a Source #
Error message to use in case statements adapting to the different Screen shapes.