hledger-ui-1.52.1: Terminal interface for the hledger accounting system
Safe HaskellNone
LanguageGHC2021

Hledger.UI.UITypes

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

Documentation

data AppEvent Source #

Constructors

FileChange 
DateChange Day Day 

Instances

Instances details
Show AppEvent Source # 
Instance details

Defined in Hledger.UI.UITypes

Eq AppEvent Source # 
Instance details

Defined in Hledger.UI.UITypes

data UIState Source #

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

  • astartupopts :: UIOpts

    the command-line options and query arguments specified at program start can change while program runs:

  • aopts :: UIOpts

    the command-line options and query arguments currently in effect

  • ajournal :: Journal

    the journal being viewed (can change with --watch)

  • aPrevScreens :: [Screen]

    previously visited screens, most recent first (XXX silly, reverse these)

  • aScreen :: Screen

    the currently active screen

  • aMode :: Mode

    the currently active mode on the current screen

Instances

Instances details
Show UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

HasCliOpts UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

HasBalancingOpts UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

HasInputOpts UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

HasReportOpts UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

reportOpts :: ReportableLens' UIState ReportOpts #

period :: ReportableLens' UIState Period #

statuses :: ReportableLens' UIState [Status] #

depth :: ReportableLens' UIState DepthSpec #

date2 :: ReportableLens' UIState Bool #

real :: ReportableLens' UIState Bool #

querystring :: ReportableLens' UIState [Text] #

HasReportOptsNoUpdate UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

HasReportSpec UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

data Mode Source #

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.

Instances

Instances details
Show Mode Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

showsPrec :: Int -> Mode -> ShowS #

show :: Mode -> String #

showList :: [Mode] -> ShowS #

Eq Mode Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

(==) :: Mode -> Mode -> Bool #

(/=) :: Mode -> Mode -> Bool #

data Name Source #

Instances

Instances details
Show Name Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

showsPrec :: Int -> Name -> ShowS #

show :: Name -> String #

showList :: [Name] -> ShowS #

Eq Name Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

(==) :: Name -> Name -> Bool #

(/=) :: Name -> Name -> Bool #

Ord Name Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

compare :: Name -> Name -> Ordering #

(<) :: Name -> Name -> Bool #

(<=) :: Name -> Name -> Bool #

(>) :: Name -> Name -> Bool #

(>=) :: Name -> Name -> Bool #

max :: Name -> Name -> Name #

min :: Name -> Name -> Name #

data Screen Source #

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.)

Instances

Instances details
Show Screen Source # 
Instance details

Defined in Hledger.UI.UITypes

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.

Instances

Instances details
Show AccountsLikeScreen Source # 
Instance details

Defined in Hledger.UI.UITypes

data MenuScreenState Source #

Constructors

MSS 

Fields

Instances

Instances details
Show MenuScreenState Source # 
Instance details

Defined in Hledger.UI.UITypes

data AccountsScreenState Source #

Constructors

ASS 

Fields

Instances

Instances details
Show AccountsScreenState Source # 
Instance details

Defined in Hledger.UI.UITypes

data RegisterScreenState Source #

Constructors

RSS 

Fields

  • _rssAccount :: AccountName

    the account this register is for

  • _rssForceInclusive :: Bool

    should this register always include subaccount transactions, even when in flat mode ? (ie because entered from a depth-clipped accounts screen item) view data derived from options, reporting date, journal, and screen parameters:

  • _rssList :: List Name RegisterScreenItem

    list widget showing transactions affecting this account

Instances

Instances details
Show RegisterScreenState Source # 
Instance details

Defined in Hledger.UI.UITypes

data TransactionScreenState Source #

Constructors

TSS 

Fields

data ErrorScreenState Source #

Constructors

ESS 

Fields

Instances

Instances details
Show ErrorScreenState Source # 
Instance details

Defined in Hledger.UI.UITypes

data MenuScreenItem Source #

An item in the menu screen's list of screens.

Constructors

MenuScreenItem 

Fields

Instances

Instances details
Show MenuScreenItem Source # 
Instance details

Defined in Hledger.UI.UITypes

data AccountsScreenItem Source #

An item in the accounts screen's list of accounts and balances.

Constructors

AccountsScreenItem 

Fields

Instances

Instances details
Show AccountsScreenItem Source # 
Instance details

Defined in Hledger.UI.UITypes

data RegisterScreenItem Source #

An item in the register screen's list of transactions in the current account.

Constructors

RegisterScreenItem 

Fields

Instances

Instances details
Show RegisterScreenItem Source # 
Instance details

Defined in Hledger.UI.UITypes

errorWrongScreenType :: String -> a Source #

Error message to use in case statements adapting to the different Screen shapes.

Orphan instances

Eq (Editor l n) Source # 
Instance details

Methods

(==) :: Editor l n -> Editor l n -> Bool #

(/=) :: Editor l n -> Editor l n -> Bool #