hledger-ui
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

Methods

showsPrec :: Int -> AppEvent -> ShowS

show :: AppEvent -> String

showList :: [AppEvent] -> ShowS

Eq AppEvent Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

(==) :: AppEvent -> AppEvent -> Bool

(/=) :: AppEvent -> AppEvent -> Bool

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

Methods

showsPrec :: Int -> UIState -> ShowS

show :: UIState -> String

showList :: [UIState] -> ShowS

HasCliOpts UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

cliOpts :: Lens' UIState CliOpts

available_width :: Lens' UIState Int

coloropt :: Lens' UIState (Maybe YNA)

command :: Lens' UIState String

debug__ :: Lens' UIState Int

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

width__ :: Lens' UIState (Maybe String)

HasBalancingOpts UIState Source # 
Instance details

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 # 
Instance details

Defined in Hledger.UI.UITypes

Methods

inputOpts :: Lens' UIState InputOpts

aliases :: Lens' UIState [String]

anon__ :: Lens' UIState Bool

auto__ :: Lens' UIState Bool

balancingopts :: Lens' UIState BalancingOpts

defer :: Lens' UIState Bool

forecast :: Lens' UIState (Maybe DateSpan)

infer_costs :: Lens' UIState Bool

infer_equity :: Lens' UIState Bool

ioDay :: Lens' UIState Day

mformat :: Lens' UIState (Maybe StorageFormat)

mrules_file :: Lens' UIState (Maybe FilePath)

new__ :: Lens' UIState Bool

new_save :: Lens' UIState Bool

oldtimeclock :: Lens' UIState Bool

pivot :: Lens' UIState String

posting_account_tags :: Lens' UIState Bool

reportspan :: Lens' UIState DateSpan

strict :: Lens' UIState Bool

verbose_tags :: Lens' UIState Bool

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

Methods

reportOptsNoUpdate :: Lens' UIState ReportOpts

accountlistmode :: Lens' UIState AccountListMode

average :: Lens' UIState Bool

balance_base_url :: Lens' UIState (Maybe Text)

balanceaccum :: Lens' UIState BalanceAccumulation

balancecalc :: Lens' UIState BalanceCalculation

budgetpat :: Lens' UIState (Maybe Text)

color__ :: Lens' UIState Bool

conversionop :: Lens' UIState (Maybe ConversionOp)

date2NoUpdate :: Lens' UIState Bool

declared :: Lens' UIState Bool

depthNoUpdate :: Lens' UIState DepthSpec

drop__ :: Lens' UIState Int

empty__ :: Lens' UIState Bool

format :: Lens' UIState StringFormat

infer_prices :: Lens' UIState Bool

interval :: Lens' UIState Interval

invert :: Lens' UIState Bool

layout :: Lens' UIState Layout

no_elide :: Lens' UIState Bool

no_total :: Lens' UIState Bool

normalbalance :: Lens' UIState (Maybe NormalSign)

percent :: Lens' UIState Bool

periodNoUpdate :: Lens' UIState Period

pretty :: Lens' UIState Bool

querystringNoUpdate :: Lens' UIState [Text]

realNoUpdate :: Lens' UIState Bool

related :: 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

txn_dates :: Lens' UIState Bool

value :: Lens' UIState (Maybe ValuationType)

HasReportSpec UIState Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

reportSpec :: Lens' UIState ReportSpec

rsDay :: Lens' UIState Day

rsQuery :: Lens' UIState Query

rsQueryOpts :: Lens' UIState [QueryOpt]

rsReportOpts :: Lens' UIState ReportOpts

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.

Constructors

Normal 
Help 
Minibuffer Text (Editor String Name) 

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 ScreenName Source #

Instances

Instances details
Show ScreenName Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

showsPrec :: Int -> ScreenName -> ShowS

show :: ScreenName -> String

showList :: [ScreenName] -> ShowS

Eq ScreenName Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

(==) :: ScreenName -> ScreenName -> Bool

(/=) :: ScreenName -> ScreenName -> Bool

Ord ScreenName Source # 
Instance details

Defined in Hledger.UI.UITypes

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

Methods

showsPrec :: Int -> Screen -> ShowS

show :: Screen -> String

showList :: [Screen] -> ShowS

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

Methods

showsPrec :: Int -> AccountsLikeScreen -> ShowS

show :: AccountsLikeScreen -> String

showList :: [AccountsLikeScreen] -> ShowS

data MenuScreenState Source #

Constructors

MSS 

Fields

Instances

Instances details
Show MenuScreenState Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

showsPrec :: Int -> MenuScreenState -> ShowS

show :: MenuScreenState -> String

showList :: [MenuScreenState] -> ShowS

data AccountsScreenState Source #

Constructors

ASS 

Fields

  • _assSelectedAccount :: AccountName

    a copy of the account name from the list's selected item (or "") view data derived from options, reporting date, journal, and screen parameters:

  • _assList :: List Name AccountsScreenItem

    list widget showing account names & balances

Instances

Instances details
Show AccountsScreenState Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

showsPrec :: Int -> AccountsScreenState -> ShowS

show :: AccountsScreenState -> String

showList :: [AccountsScreenState] -> ShowS

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

Methods

showsPrec :: Int -> RegisterScreenState -> ShowS

show :: RegisterScreenState -> String

showList :: [RegisterScreenState] -> ShowS

data TransactionScreenState Source #

Constructors

TSS 

Fields

Instances

Instances details
Show TransactionScreenState Source # 
Instance details

Defined in Hledger.UI.UITypes

data ErrorScreenState Source #

Constructors

ESS 

Fields

Instances

Instances details
Show ErrorScreenState Source # 
Instance details

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

Instances details
Show MenuScreenItem Source # 
Instance details

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

Instances details
Show AccountsScreenItem Source # 
Instance details

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

Instances details
Show RegisterScreenItem Source # 
Instance details

Defined in Hledger.UI.UITypes

Methods

showsPrec :: Int -> RegisterScreenItem -> ShowS

show :: RegisterScreenItem -> String

showList :: [RegisterScreenItem] -> ShowS

type NumberedTransaction = (Integer, Transaction) Source #

rssAccount :: Lens' RegisterScreenState AccountName Source #

errorWrongScreenType :: String -> a Source #

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

uioptslens :: Functor f => (UIOpts -> f UIOpts) -> UIState -> f UIState Source #

Orphan instances

Eq (Editor l n) Source # 
Instance details

Methods

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

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