-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A simple terminal user interface for the hledger accounting system. It
--   can be a more convenient way to browse your accounts than the CLI.
--   
--   hledger is a robust, cross-platform set of tools for tracking money,
--   time, or any other commodity, using double-entry accounting and a
--   simple, editable file format, with command-line, terminal and web
--   interfaces. It is a Haskell rewrite of Ledger, and one of the leading
--   implementations of Plain Text Accounting. Read more at:
--   <a>https://hledger.org</a>
@package hledger-ui
@version 1.51.1


-- | Editor integration.
module Hledger.UI.Editor

-- | The text position meaning "last line, first column".
endPosition :: Maybe TextPosition

-- | Run the user's preferred text editor (or try a default editor), on the
--   given file, blocking until it exits, and return the exit code; or
--   raise an error. If a text position is provided, the editor will be
--   focussed at that position in the file, if we know how.
runEditor :: Maybe TextPosition -> FilePath -> IO ExitCode

-- | Run the hledger-iadd executable on the given file, blocking until it
--   exits, and return the exit code; or raise an error. hledger-iadd is an
--   alternative to the built-in add command.
runIadd :: FilePath -> IO ExitCode


-- | The all-important theming engine!
--   
--   Cf
--   <a>https://hackage.haskell.org/package/vty/docs/Graphics-Vty-Attributes.html</a>
--   <a>http://hackage.haskell.org/package/brick/docs/Brick-AttrMap.html</a>
--   <a>http://hackage.haskell.org/package/brick-0.1/docs/Brick-Util.html</a>
--   <a>http://hackage.haskell.org/package/brick-0.1/docs/Brick-Widgets-Core.html#g:5</a>
--   <a>http://hackage.haskell.org/package/brick-0.1/docs/Brick-Widgets-Border.html</a>
module Hledger.UI.Theme
defaultTheme :: AttrMap

-- | Look up the named theme, if it exists.
getTheme :: String -> Maybe AttrMap

-- | A selection of named themes specifying terminal colours and styles.
--   One of these is active at a time.
--   
--   A hledger-ui theme is a vty/brick AttrMap. Each theme specifies a
--   default style (Attr), plus extra styles which are applied when their
--   (hierarchical) name matches the widget rendering context. "More
--   specific styles, if present, are used and only fall back to more
--   general ones when the more specific ones are absent, but also these
--   styles get merged, so that if a more specific style only provides the
--   foreground color, its more general parent style can set the background
--   color, too." For example: rendering a widget named "b" inside a widget
--   named "a", - if a style named "a" &lt;&gt; "b" exists, it will be
--   used. Anything it does not specify will be taken from a style named
--   "a" if that exists, otherwise from the default style. - otherwise if a
--   style named "a" exists, it will be used, and anything it does not
--   specify will be taken from the default style. - otherwise (you guessed
--   it) the default style is used.
themes :: Map String AttrMap
themeNames :: [String]

module Hledger.UI.UIOptions
packageversion :: PackageVersionString
progname :: ProgramName

-- | Generate the version string for this program. The template haskell
--   call is here rather than in Hledger.Cli.Version to avoid wasteful
--   recompilation.
prognameandversion :: String
binaryinfo :: HledgerBinaryInfo
uiflags :: [Flag RawOpts]
uimode :: Mode RawOpts
data UIOpts
UIOpts :: Bool -> Maybe String -> Maybe String -> CliOpts -> UIOpts
[uoWatch] :: UIOpts -> Bool
[uoTheme] :: UIOpts -> Maybe String
[uoRegister] :: UIOpts -> Maybe String
[uoCliOpts] :: UIOpts -> CliOpts
defuiopts :: UIOpts

-- | Process a RawOpts into a UIOpts. An invalid --theme name will raise an
--   error.
rawOptsToUIOpts :: RawOpts -> IO UIOpts
getHledgerUIOpts :: IO UIOpts
instance Hledger.Data.Balancing.HasBalancingOpts Hledger.UI.UIOptions.UIOpts
instance Hledger.Cli.CliOptions.HasCliOpts Hledger.UI.UIOptions.UIOpts
instance Hledger.Read.InputOptions.HasInputOpts Hledger.UI.UIOptions.UIOpts
instance Hledger.Reports.ReportOptions.HasReportOptsNoUpdate Hledger.UI.UIOptions.UIOpts
instance Hledger.Reports.ReportOptions.HasReportOpts Hledger.UI.UIOptions.UIOpts
instance Hledger.Reports.ReportOptions.HasReportSpec Hledger.UI.UIOptions.UIOpts
instance GHC.Internal.Show.Show Hledger.UI.UIOptions.UIOpts


-- | 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.
--   
--   <pre>
--   Brick.defaultMain brickapp st
--     where
--       brickapp :: App (UIState) V.Event
--       brickapp = App {
--           appLiftVtyEvent = id
--         , appStartEvent   = return
--         , appAttrMap      = const theme
--         , appChooseCursor = showFirstCursor
--         , appHandleEvent  = st ev -&gt; sHandle (aScreen st) st ev
--         , appDraw         = st    -&gt; sDraw   (aScreen st) st
--         }
--       st :: UIState
--       st = (sInit s) d
--            UIState{
--               aopts=uopts'
--              ,ajournal=j
--              ,aScreen=s
--              ,aPrevScreens=prevscrs
--              ,aMinibuffer=Nothing
--              }
--   </pre>
module Hledger.UI.UITypes
data AppEvent
FileChange :: AppEvent
DateChange :: Day -> Day -> AppEvent

-- | 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.
data UIState
UIState :: UIOpts -> UIOpts -> Journal -> [Screen] -> Screen -> Mode -> UIState

-- | the command-line options and query arguments specified at program
--   start can change while program runs:
[astartupopts] :: UIState -> UIOpts

-- | the command-line options and query arguments currently in effect
[aopts] :: UIState -> UIOpts

-- | the journal being viewed (can change with --watch)
[ajournal] :: UIState -> Journal

-- | previously visited screens, most recent first (XXX silly, reverse
--   these)
[aPrevScreens] :: UIState -> [Screen]

-- | the currently active screen
[aScreen] :: UIState -> Screen

-- | the currently active mode on the current screen
[aMode] :: UIState -> Mode

-- | 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.
data Mode
Normal :: Mode
Help :: Mode
Minibuffer :: Text -> Editor String Name -> Mode
data Name
HelpDialog :: Name
MinibufferEditor :: Name
MenuList :: Name
AccountsViewport :: Name
AccountsList :: Name
RegisterViewport :: Name
RegisterList :: Name
TransactionEditor :: Name
data ScreenName
Accounts :: ScreenName
CashScreen :: ScreenName
Balancesheet :: ScreenName
Incomestatement :: 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 init<i>draw</i>handle 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 -&gt; Bool -&gt;
--   UIState -&gt; UIState -- ^ function to initialise or update this
--   screen's state ,sDraw :: UIState -&gt; [Widget Name] -- ^ brick
--   renderer for this screen ,sHandle :: BrickEvent Name AppEvent -&gt;
--   EventM Name UIState () -- ^ brick event handler for this screen --
--   state fields.These ones have lenses: ,_asList :: List Name
--   AccountsScreenItem -- ^ list widget showing account names &amp;
--   balances ,_asSelectedAccount :: AccountName -- ^ a backup of the
--   account name from the list widget's selected item (or "") } |
--   RegisterScreen { sInit :: Day -&gt; Bool -&gt; UIState -&gt; UIState
--   ,sDraw :: UIState -&gt; [Widget Name] ,sHandle :: BrickEvent Name
--   AppEvent -&gt; 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 -&gt; Bool -&gt; UIState -&gt;
--   UIState ,sDraw :: UIState -&gt; [Widget Name] ,sHandle :: BrickEvent
--   Name AppEvent -&gt; 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 -&gt; Bool -&gt; UIState -&gt; UIState
--   ,sDraw :: UIState -&gt; [Widget Name] ,sHandle :: BrickEvent Name
--   AppEvent -&gt; 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 Screen
MS :: MenuScreenState -> Screen
AS :: AccountsScreenState -> Screen
CS :: AccountsScreenState -> Screen
BS :: AccountsScreenState -> Screen
IS :: AccountsScreenState -> Screen
RS :: RegisterScreenState -> Screen
TS :: TransactionScreenState -> Screen
ES :: ErrorScreenState -> Screen

-- | 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.
data AccountsLikeScreen
ALS :: (AccountsScreenState -> Screen) -> AccountsScreenState -> AccountsLikeScreen
toAccountsLikeScreen :: Screen -> Maybe AccountsLikeScreen
fromAccountsLikeScreen :: AccountsLikeScreen -> Screen
data MenuScreenState
MSS :: List Name MenuScreenItem -> () -> MenuScreenState

-- | list widget showing screen names
[_mssList] :: MenuScreenState -> List Name MenuScreenItem

-- | dummy field to silence warning
[_mssUnused] :: MenuScreenState -> ()
data AccountsScreenState
ASS :: AccountName -> List Name AccountsScreenItem -> AccountsScreenState

-- | a copy of the account name from the list's selected item (or "") view
--   data derived from options, reporting date, journal, and screen
--   parameters:
[_assSelectedAccount] :: AccountsScreenState -> AccountName

-- | list widget showing account names &amp; balances
[_assList] :: AccountsScreenState -> List Name AccountsScreenItem
data RegisterScreenState
RSS :: AccountName -> Bool -> List Name RegisterScreenItem -> RegisterScreenState

-- | the account this register is for
[_rssAccount] :: RegisterScreenState -> AccountName

-- | 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:
[_rssForceInclusive] :: RegisterScreenState -> Bool

-- | list widget showing transactions affecting this account
[_rssList] :: RegisterScreenState -> List Name RegisterScreenItem
data TransactionScreenState
TSS :: AccountName -> [NumberedTransaction] -> NumberedTransaction -> TransactionScreenState

-- | the account whose register we entered this screen from
[_tssAccount] :: TransactionScreenState -> AccountName

-- | the transactions in that register, which we can step through
[_tssTransactions] :: TransactionScreenState -> [NumberedTransaction]

-- | the currently displayed transaction, and its position in the list
[_tssTransaction] :: TransactionScreenState -> NumberedTransaction
data ErrorScreenState
ESS :: String -> () -> ErrorScreenState

-- | error message to show
[_essError] :: ErrorScreenState -> String

-- | dummy field to silence warning
[_essUnused] :: ErrorScreenState -> ()

-- | An item in the menu screen's list of screens.
data MenuScreenItem
MenuScreenItem :: Text -> ScreenName -> MenuScreenItem

-- | screen display name
[msItemScreenName] :: MenuScreenItem -> Text

-- | an internal name we can use to find the corresponding screen
[msItemScreen] :: MenuScreenItem -> ScreenName

-- | An item in the accounts screen's list of accounts and balances.
data AccountsScreenItem
AccountsScreenItem :: Int -> AccountName -> AccountName -> Maybe MixedAmount -> AccountsScreenItem

-- | indent level
[asItemIndentLevel] :: AccountsScreenItem -> Int

-- | full account name
[asItemAccountName] :: AccountsScreenItem -> AccountName

-- | full or short account name to display
[asItemDisplayAccountName] :: AccountsScreenItem -> AccountName

-- | mixed amount to display
[asItemMixedAmount] :: AccountsScreenItem -> Maybe MixedAmount

-- | An item in the register screen's list of transactions in the current
--   account.
data RegisterScreenItem
RegisterScreenItem :: Text -> Status -> Text -> Text -> WideBuilder -> WideBuilder -> Transaction -> RegisterScreenItem

-- | date
[rsItemDate] :: RegisterScreenItem -> Text

-- | transaction status
[rsItemStatus] :: RegisterScreenItem -> Status

-- | description
[rsItemDescription] :: RegisterScreenItem -> Text

-- | other accounts
[rsItemOtherAccounts] :: RegisterScreenItem -> Text

-- | the change to the current account from this transaction
[rsItemChangeAmount] :: RegisterScreenItem -> WideBuilder

-- | the balance or running total after this transaction
[rsItemBalanceAmount] :: RegisterScreenItem -> WideBuilder

-- | the full transaction
[rsItemTransaction] :: RegisterScreenItem -> 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 ()

-- | Error message to use in case statements adapting to the different
--   Screen shapes.
errorWrongScreenType :: String -> a
uioptslens :: Functor f => (UIOpts -> f UIOpts) -> UIState -> f UIState
instance GHC.Classes.Eq Hledger.UI.UITypes.AppEvent
instance GHC.Classes.Eq (Brick.Widgets.Edit.Editor l n)
instance GHC.Classes.Eq Hledger.UI.UITypes.Mode
instance GHC.Classes.Eq Hledger.UI.UITypes.Name
instance GHC.Classes.Eq Hledger.UI.UITypes.ScreenName
instance Hledger.Data.Balancing.HasBalancingOpts Hledger.UI.UITypes.UIState
instance Hledger.Cli.CliOptions.HasCliOpts Hledger.UI.UITypes.UIState
instance Hledger.Read.InputOptions.HasInputOpts Hledger.UI.UITypes.UIState
instance Hledger.Reports.ReportOptions.HasReportOptsNoUpdate Hledger.UI.UITypes.UIState
instance Hledger.Reports.ReportOptions.HasReportOpts Hledger.UI.UITypes.UIState
instance Hledger.Reports.ReportOptions.HasReportSpec Hledger.UI.UITypes.UIState
instance GHC.Classes.Ord Hledger.UI.UITypes.Name
instance GHC.Classes.Ord Hledger.UI.UITypes.ScreenName
instance GHC.Internal.Show.Show Hledger.UI.UITypes.AccountsLikeScreen
instance GHC.Internal.Show.Show Hledger.UI.UITypes.AccountsScreenItem
instance GHC.Internal.Show.Show Hledger.UI.UITypes.AccountsScreenState
instance GHC.Internal.Show.Show Hledger.UI.UITypes.AppEvent
instance GHC.Internal.Show.Show Hledger.UI.UITypes.ErrorScreenState
instance GHC.Internal.Show.Show Hledger.UI.UITypes.MenuScreenItem
instance GHC.Internal.Show.Show Hledger.UI.UITypes.MenuScreenState
instance GHC.Internal.Show.Show Hledger.UI.UITypes.Mode
instance GHC.Internal.Show.Show Hledger.UI.UITypes.Name
instance GHC.Internal.Show.Show Hledger.UI.UITypes.RegisterScreenItem
instance GHC.Internal.Show.Show Hledger.UI.UITypes.RegisterScreenState
instance GHC.Internal.Show.Show Hledger.UI.UITypes.Screen
instance GHC.Internal.Show.Show Hledger.UI.UITypes.ScreenName
instance GHC.Internal.Show.Show Hledger.UI.UITypes.TransactionScreenState
instance GHC.Internal.Show.Show Hledger.UI.UITypes.UIState


-- | Rendering &amp; misc. helpers.
module Hledger.UI.UIUtils
borderDepthStr :: Maybe Int -> Widget Name
borderKeysStr :: [(String, String)] -> Widget Name
borderKeysStr' :: [(String, Widget Name)] -> Widget Name
borderPeriodStr :: String -> Period -> Widget Name
borderQueryStr :: String -> Widget Name

-- | Wrap a widget in the default hledger-ui screen layout.
defaultLayout :: Widget Name -> Widget Name -> Widget Name -> Widget Name

-- | Draw the help dialog, called when help mode is active.
helpDialog :: Widget Name

-- | Event handler used when help mode is active. May invoke $PAGER, less,
--   man or info, which is likely to fail on MS Windows, TODO.
helpHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()

-- | Draw the minibuffer with the given label.
minibuffer :: Text -> Editor String Name -> Widget Name
moveDownEvents :: [Event]
moveLeftEvents :: [Event]
moveRightEvents :: [Event]
moveUpEvents :: [Event]
normaliseMovementKeys :: Event -> Event

-- | Show both states of a toggle ("aaa/bbb"), highlighting the active one.
renderToggle :: Bool -> String -> String -> Widget Name

-- | Show a toggle's label, highlighted (bold) when the toggle is active.
renderToggle1 :: Bool -> String -> Widget Name

-- | Replace the special account names "*" and "..." (from balance reports
--   with depth limit 0) to something clearer.
replaceHiddenAccountsNameWith :: AccountName -> AccountName -> AccountName

-- | Scroll a list's viewport so that the selected item is centered in the
--   middle of the display area.
scrollSelectionToMiddle :: List Name item -> EventM Name UIState ()
get' :: EventM Name UIState UIState
put' :: UIState -> EventM Name UIState ()
modify' :: (UIState -> UIState) -> EventM Name UIState ()

-- | On posix platforms, suspend the program using the STOP signal, like
--   control-z in bash, returning to the original shell prompt, and when
--   resumed, continue where we left off. On windows, does nothing.
suspend :: Ord a => s -> EventM a s ()

-- | Tell vty to redraw the whole screen.
redraw :: EventM a s ()

-- | Restrict the ReportSpec's query by adding the given additional query.
reportSpecAddQuery :: Query -> ReportSpec -> ReportSpec

-- | Update the ReportSpec's query to exclude future transactions (later
--   than its "today" date) and forecast transactions (generated by
--   --forecast), if the given forecast DateSpan is Nothing, and include
--   them otherwise.
reportSpecSetFutureAndForecast :: Maybe DateSpan -> ReportSpec -> ReportSpec
listScrollPushingSelection :: Name -> Int -> Int -> EventM Name (List Name item) (GenericList Name Vector item)

-- | A debug logging helper for hledger-ui code: at any debug level &gt;=
--   1, logs the string to hledger-ui.log before returning the second
--   argument. Uses unsafePerformIO.
dbgui :: String -> a -> a

-- | Like dbgui, but convenient to use in IO.
dbguiIO :: String -> IO ()

-- | Like dbgui, but convenient to use in EventM handlers.
dbguiEv :: String -> EventM Name s ()

-- | Like dbguiEv, but log a compact view of the current screen stack. See
--   showScreenStack. To just log the stack: <tt>dbguiScreensEv ""
--   showScreenId ui</tt>
dbguiScreensEv :: String -> (Screen -> String) -> UIState -> EventM Name UIState ()
showScreenId :: Screen -> String
showScreenRegisterDescriptions :: Screen -> String
showScreenSelection :: Screen -> String

-- | Run a function on each screen in a UIState's screen "stack", from
--   topmost screen down to currently-viewed screen.
mapScreens :: (Screen -> a) -> UIState -> [a]

-- | How many blank items to add to lists to fill the full window height.
uiNumBlankItems :: Int
showScreenStack :: String -> (Screen -> String) -> UIState -> String
sendVtyEvents :: [Event] -> EventM n s ()


-- | Constructors and updaters for all hledger-ui screens.
--   
--   Constructors (*New) create and initialise a new screen with valid
--   state, based on the provided options, reporting date, journal, and
--   screen-specific parameters.
--   
--   Updaters (*Update) recalculate an existing screen's state, based on
--   new options, reporting date, journal, and the old screen state.
--   
--   These are gathered in this low-level module so that any screen's
--   handler can create or regenerate all other screens. Drawing and
--   event-handling code is elsewhere, in per-screen modules.
module Hledger.UI.UIScreens

-- | Regenerate the content of any screen from new options, reporting date
--   and journal.
screenUpdate :: UIOpts -> Day -> Journal -> Screen -> Screen

-- | Construct an error screen. Screen-specific arguments: the error
--   message to show.
esNew :: String -> Screen

-- | Update an error screen. Currently a no-op since error screen depends
--   only on its screen-specific state.
esUpdate :: ErrorScreenState -> ErrorScreenState

-- | Construct a menu screen, with the first item selected. Screen-specific
--   arguments: none.
msNew :: Screen

-- | Update a menu screen. Currently a no-op since menu screen has
--   unchanging content.
msUpdate :: MenuScreenState -> MenuScreenState

-- | Construct an accounts screen listing the appropriate set of accounts,
--   with the appropriate one selected. Screen-specific arguments: the
--   account to select if any.
asNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update an accounts screen's state from these options, reporting date,
--   and journal.
asUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asItemIndex :: Int

-- | Construct a cash accounts screen listing the appropriate set of
--   accounts, with the appropriate one selected. Screen-specific
--   arguments: the account to select if any.
csNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update a balance sheet screen's state from these options, reporting
--   date, and journal.
csUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState

-- | Positions of menu screen items, so we can move selection to them.
csItemIndex :: Int

-- | Construct a balance sheet screen listing the appropriate set of
--   accounts, with the appropriate one selected. Screen-specific
--   arguments: the account to select if any.
bsNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update a balance sheet screen's state from these options, reporting
--   date, and journal.
bsUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
bsItemIndex :: Int

-- | Construct an income statement screen listing the appropriate set of
--   accounts, with the appropriate one selected. Screen-specific
--   arguments: the account to select if any.
isNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update an income statement screen's state from these options,
--   reporting date, and journal.
isUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
isItemIndex :: Int

-- | Construct a register screen listing the appropriate set of
--   transactions, with the appropriate one selected. Screen-specific
--   arguments: the account whose register this is, whether to force
--   inclusive balances.
rsNew :: UIOpts -> Day -> Journal -> AccountName -> Bool -> Screen

-- | Update a register screen from these options, reporting date, and
--   journal.
rsUpdate :: UIOpts -> Day -> Journal -> RegisterScreenState -> RegisterScreenState

-- | Construct a transaction screen showing one of a given list of
--   transactions, with the ability to step back and forth through the
--   list. Screen-specific arguments: the account whose transactions are
--   being shown, the list of showable transactions, the currently shown
--   transaction.
tsNew :: AccountName -> [NumberedTransaction] -> NumberedTransaction -> Screen

-- | Update a transaction screen. This currently does nothing because the
--   initialisation in rsHandle is not so easy to extract. To see the
--   updated transaction, one must exit and re-enter the transaction
--   screen. See also tsHandle.
tsUpdate :: TransactionScreenState -> TransactionScreenState


-- | UIState operations.
module Hledger.UI.UIState

-- | Make an initial UI state with the given options, journal, parent
--   screen stack if any, and starting screen.
uiState :: UIOpts -> Journal -> [Screen] -> Screen -> UIState

-- | Generate zero or more indicators of the status filters currently
--   active, which will be shown comma-separated as part of the indicators
--   list.
uiShowStatus :: CliOpts -> [Status] -> [String]

-- | Apply a new filter query, or return the failing query.
setFilter :: String -> UIState -> Either String UIState
setMode :: Mode -> UIState -> UIState

-- | Set the report period.
setReportPeriod :: Period -> UIState -> UIState

-- | Open the minibuffer, setting its content to the current query with the
--   cursor at the end.
showMinibuffer :: Text -> Maybe String -> UIState -> UIState

-- | Close the minibuffer, discarding any edit in progress.
closeMinibuffer :: UIState -> UIState

-- | Toggle between showing only cleared items or all items.
toggleCleared :: UIState -> UIState

-- | Toggle between showing the primary amounts or costs.
toggleConversionOp :: UIState -> UIState

-- | Toggle the ignoring of balance assertions.
toggleIgnoreBalanceAssertions :: UIState -> UIState

-- | Toggle between showing all and showing only nonempty (more precisely,
--   nonzero) items.
toggleEmpty :: UIState -> UIState

-- | Toggle hledger-ui's "forecast/future mode". When this mode is enabled,
--   hledger-shows regular transactions which have future dates, and
--   "forecast" transactions generated by periodic transaction rules (which
--   are usually but not necessarily future-dated). In normal mode, both of
--   these are hidden.
toggleForecast :: Day -> UIState -> UIState

-- | Toggle between historical balances and period balances.
toggleHistorical :: UIState -> UIState

-- | Toggle between showing only pending items or all items.
togglePending :: UIState -> UIState

-- | Toggle between showing only unmarked items or all items.
toggleUnmarked :: UIState -> UIState

-- | Toggle between showing all and showing only real (non-virtual) items.
toggleReal :: UIState -> UIState

-- | Toggle between flat and tree mode. If current mode is
--   unspecified/default, assume it's flat.
toggleTree :: UIState -> UIState

-- | Set hierarchic account tree mode.
setTree :: UIState -> UIState

-- | Set flat account list mode.
setList :: UIState -> UIState

-- | Toggle between showing primary amounts or values (using valuation
--   specified at startup, or a default).
toggleValue :: UIState -> UIState

-- | Get the report period.
reportPeriod :: UIState -> Period

-- | Step through smaller report periods, down to a day.
shrinkReportPeriod :: Day -> UIState -> UIState

-- | Step through larger report periods, up to all.
growReportPeriod :: Day -> UIState -> UIState

-- | Step the report start/end dates to the next period of same duration,
--   remaining inside the given enclosing span.
nextReportPeriod :: DateSpan -> UIState -> UIState

-- | Step the report start/end dates to the next period of same duration,
--   remaining inside the given enclosing span.
previousReportPeriod :: DateSpan -> UIState -> UIState

-- | Clear any report period limits.
resetReportPeriod :: UIState -> UIState

-- | If a standard report period is set, step it forward/backward if needed
--   so that it encloses the given date.
moveReportPeriodToDate :: Day -> UIState -> UIState
getDepth :: UIState -> Maybe Int

-- | Set the current depth limit to the specified depth, or remove the
--   depth limit. Also remove the depth limit if the specified depth is
--   greater than the current maximum account depth. If the specified depth
--   is negative, reset the depth limit to whatever was specified at
--   uiartup.
setDepth :: Maybe Int -> UIState -> UIState

-- | Decrement the current depth limit towards 0. If there was no depth
--   limit, set it to one less than the maximum account depth.
decDepth :: UIState -> UIState

-- | Increment the current depth limit. If this makes it equal to the the
--   maximum account depth, remove the depth limit.
incDepth :: UIState -> UIState
resetDepth :: UIState -> UIState
popScreen :: UIState -> UIState
pushScreen :: Screen -> UIState -> UIState

-- | Enable forecasting in this CliOpts. If it previously specified a
--   forecast period, or else if the given ui startup options did, preserve
--   that as the forecast period.
enableForecast :: UIOpts -> CliOpts -> CliOpts

-- | Reset some filters &amp; toggles.
resetFilter :: UIState -> UIState

-- | Reset options to their startup values, discard screen navigation
--   history, and return to the top screen, regenerating it with the
--   startup options and the provided reporting date.
resetScreens :: Day -> UIState -> UIState

-- | Given a new journal and reporting date, save the new journal in the ui
--   state, then regenerate the content of all screens in the stack (using
--   the ui state's current options), preserving the screen navigation
--   history. Note, does not save the reporting date.
--   
--   XXX Currently this does not properly regenerate the transaction screen
--   or error screen, which depend on state from their parent(s); those
--   screens' handlers must do additional work, which is fragile.
regenerateScreens :: Journal -> Day -> UIState -> UIState

module Hledger.UI.ErrorScreen

-- | Construct an error screen. Screen-specific arguments: the error
--   message to show.
esNew :: String -> Screen

-- | Update an error screen. Currently a no-op since error screen depends
--   only on its screen-specific state.
esUpdate :: ErrorScreenState -> ErrorScreenState
esDraw :: UIState -> [Widget Name]
esHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
uiCheckBalanceAssertions :: Day -> UIState -> UIState

-- | Reload the journal from its input files, then update the ui app state
--   accordingly. This means regenerate the entire screen stack from top
--   level down to the current screen, using the provided today-date. As a
--   convenience (usually), if journal reloading fails, this enters the
--   error screen, or if already there, updates its message.
--   
--   The provided cli options can influence reloading; then if reloading
--   succeeds they are saved in the ui state, otherwise the UIState keeps
--   its old options. (XXX needed for.. ?)
--   
--   Like at hledger-ui startup, --forecast is always enabled. A forecast
--   period specified in the provided opts, or at startup, is preserved.
uiReload :: CliOpts -> Day -> UIState -> EventM Name UIState UIState

-- | Like uiReload, except it skips re-reading the journal if its file(s)
--   have not changed since it was last loaded. The up app state is always
--   updated, since the options or today-date may have changed. Also, this
--   one runs in IO, suitable for suspendAndResume.
uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState

-- | Toggle ignoring balance assertions (when user presses I), and if no
--   longer ignoring, recheck them. Normally the recheck is done quickly on
--   the in-memory journal. But if --pivot is active, a full journal reload
--   is done instead (because we can't check balance assertions after
--   pivoting has occurred). In that case, this operation could be slower
--   and could reveal other data changes (not just balance assertion
--   failures).
uiToggleBalanceAssertions :: Day -> UIState -> EventM Name UIState ()

module Hledger.UI.RegisterScreen

-- | Construct a register screen listing the appropriate set of
--   transactions, with the appropriate one selected. Screen-specific
--   arguments: the account whose register this is, whether to force
--   inclusive balances.
rsNew :: UIOpts -> Day -> Journal -> AccountName -> Bool -> Screen

-- | Update a register screen from these options, reporting date, and
--   journal.
rsUpdate :: UIOpts -> Day -> Journal -> RegisterScreenState -> RegisterScreenState
rsDraw :: UIState -> [Widget Name]
rsHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
rsSetAccount :: AccountName -> Bool -> Screen -> Screen

-- | Scroll the selected item to the middle of the screen, when on the
--   register screen. No effect on other screens.
rsCenterSelection :: UIState -> EventM Name UIState UIState

module Hledger.UI.TransactionScreen

-- | Construct a transaction screen showing one of a given list of
--   transactions, with the ability to step back and forth through the
--   list. Screen-specific arguments: the account whose transactions are
--   being shown, the list of showable transactions, the currently shown
--   transaction.
tsNew :: AccountName -> [NumberedTransaction] -> NumberedTransaction -> Screen

-- | Update a transaction screen. This currently does nothing because the
--   initialisation in rsHandle is not so easy to extract. To see the
--   updated transaction, one must exit and re-enter the transaction
--   screen. See also tsHandle.
tsUpdate :: TransactionScreenState -> TransactionScreenState
tsDraw :: UIState -> [Widget Name]
tsHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()

module Hledger.UI.MenuScreen

-- | Construct a menu screen, with the first item selected. Screen-specific
--   arguments: none.
msNew :: Screen

-- | Update a menu screen. Currently a no-op since menu screen has
--   unchanging content.
msUpdate :: MenuScreenState -> MenuScreenState
msDraw :: UIState -> [Widget Name]
msHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()

-- | Set the selected list item on the menu screen. Has no effect on other
--   screens.
msSetSelectedScreen :: Int -> Screen -> Screen

module Hledger.UI.AccountsScreen

-- | Construct an accounts screen listing the appropriate set of accounts,
--   with the appropriate one selected. Screen-specific arguments: the
--   account to select if any.
asNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update an accounts screen's state from these options, reporting date,
--   and journal.
asUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asDraw :: UIState -> [Widget Name]

-- | Help draw any accounts-like screen (all accounts, balance sheet,
--   income statement..). The provided ReportOpts are used instead of the
--   ones in the UIState. The other argument is the screen display name.
asDrawHelper :: UIState -> ReportOpts -> String -> [Widget Name]

-- | Handle events on any accounts-like screen (all accounts, balance
--   sheet, income statement..).
asHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()

-- | Handle events when in help mode on any screen.
handleHelpMode :: BrickEvent Name AppEvent -> EventM Name UIState ()

-- | Handle events when in minibuffer mode on any screen.
handleMinibufferMode :: Editor String Name -> BrickEvent n e -> EventM Name UIState ()

-- | Handle events when in normal mode on any accounts-like screen. The
--   provided AccountsLikeScreen should correspond to the ui state's
--   current screen.
asHandleNormalMode :: AccountsLikeScreen -> BrickEvent Name AppEvent -> EventM Name UIState ()
enterRegisterScreen :: Day -> AccountName -> UIState -> EventM Name UIState ()

-- | Set the selected account on any of the accounts screens. Has no effect
--   on other screens. Sets the high-level property _assSelectedAccount and
--   also selects the corresponding or best alternative item in the list
--   widget (_assList).
asSetSelectedAccount :: AccountName -> Screen -> Screen

module Hledger.UI.IncomestatementScreen

-- | Construct an income statement screen listing the appropriate set of
--   accounts, with the appropriate one selected. Screen-specific
--   arguments: the account to select if any.
isNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update an income statement screen's state from these options,
--   reporting date, and journal.
isUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
isDraw :: UIState -> [Widget Name]
isHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()

module Hledger.UI.CashScreen

-- | Construct a cash accounts screen listing the appropriate set of
--   accounts, with the appropriate one selected. Screen-specific
--   arguments: the account to select if any.
csNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update a balance sheet screen's state from these options, reporting
--   date, and journal.
csUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
csDraw :: UIState -> [Widget Name]
csHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()

module Hledger.UI.BalancesheetScreen

-- | Construct a balance sheet screen listing the appropriate set of
--   accounts, with the appropriate one selected. Screen-specific
--   arguments: the account to select if any.
bsNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update a balance sheet screen's state from these options, reporting
--   date, and journal.
bsUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
bsDraw :: UIState -> [Widget Name]
bsHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()


-- | hledger-ui - a hledger add-on providing an efficient TUI.
--   
--   SPDX-License-Identifier: GPL-3.0-or-later Copyright (c) 2007-2025
--   (each year in this range) Simon Michael <a>simon@joyful.com</a> and
--   contributors.
--   
--   This program is free software: you can redistribute it and/or modify
--   it under the terms of the GNU General Public License as published by
--   the Free Software Foundation, either version 3 of the License, or (at
--   your option) any later version.
--   
--   This program is distributed in the hope that it will be useful, but
--   WITHOUT ANY WARRANTY; without even the implied warranty of
--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--   General Public License for more details. You should have received a
--   copy of the GNU General Public License along with this program. If
--   not, see <a>https://www.gnu.org/licenses/</a>.
module Hledger.UI.Main
newChan :: IO (BChan a)
writeChan :: BChan a -> a -> IO ()
hledgerUiMain :: IO ()
runBrickUi :: UIOpts -> Journal -> IO ()
brickApp :: Maybe String -> App UIState AppEvent Name
uiHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
uiDraw :: UIState -> [Widget Name]


-- | This is the root module of the <tt>hledger-ui</tt> package, providing
--   hledger's terminal user interface. The main function, command-line
--   options, and terminal themes are exported.
--   
--   <h2>See also:</h2>
--   
--   <ul>
--   <li>hledger-lib:Hledger</li>
--   <li>hledger:Hledger.Cli</li>
--   <li><a>The README files</a></li>
--   <li><a>The high-level developer docs</a></li>
--   </ul>
module Hledger.UI
