-- 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 2.0


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

-- | The options to load (or reload) the journal with: lot detail kept, and
--   no conversion to cost basis. The UI collapses lots and converts to
--   cost when it derives the display journal for the current options
--   (uiDisplayJournal), so that the L and B keys can turn either off
--   again.
uiLoadOpts :: CliOpts -> CliOpts
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 -> Journal -> Screen -> [Screen] -> Mode -> [String] -> ClickFocus -> 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). This is
--   auncollapsedjournal collapsed for display, unless the lots toggle
--   (--lots) is on.
[ajournal] :: UIState -> Journal

-- | the journal as loaded, retaining full lot detail (lot subaccounts and
--   synthetic lot postings). Kept so the lots toggle can re-derive
--   ajournal in memory. aScreen together with aPrevScreens forms a
--   non-empty navigation zipper: there is always an active screen, with
--   zero or more suspended ancestor screens behind it. "At least one
--   screen" is thus guaranteed by the types, and popScreen at the root is
--   a no-op. aPrevScreens is kept nearest-first, so pushScreen/popScreen
--   are O(1). Change the stack only through
--   pushScreen<i>popScreen</i>resetScreens, not by editing these fields.
--   
--   Both fields are kept lazy (~) under StrictData: a screen's
--   construction may read back from the UIState that will contain it (eg
--   --register startup derives a screen parameter from the ui's options),
--   and forcing them at construction would turn that benign laziness knot
--   into a (#1825). Reload regeneration forces screens explicitly
--   (regenerateScreens), so this does not weaken the leak fix.
[auncollapsedjournal] :: UIState -> Journal

-- | the currently active screen (the zipper's focus)
[aScreen] :: UIState -> Screen

-- | suspended ancestor screens, nearest first
[aPrevScreens] :: UIState -> [Screen]

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

-- | warnings collected during the last journal (re)load, oldest first;
--   displayed until the next keypress (see warningOverlay)
[aWarnings] :: UIState -> [String]

-- | tracks the click that brings the terminal window forward, so it can be
--   ignored
[aClickFocus] :: UIState -> ClickFocus

-- | Where we are in recognising a window-activating click (see uiHandle in
--   Main). This relies on the terminal's focus reporting; without it, we
--   stay Unfocused.
data ClickFocus

-- | no recent focus gain, clicks are handled normally
Unfocused :: ClickFocus

-- | the terminal window just gained focus, at this time
FocusGainedAt :: UTCTime -> ClickFocus

-- | ignoring the activating click, until its button release
IgnoringClick :: ClickFocus

-- | 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 AccountsScreenKind
AllAccounts :: AccountsScreenKind
CashAccounts :: AccountsScreenKind
BalancesheetAccounts :: AccountsScreenKind
IncomestatementAccounts :: AccountsScreenKind

-- | 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. new cases
--   in the uiDraw and uiHandle functions 4. new constructor and updater
--   functions in UIScreens, and a new case in screenUpdate 5. a new module
--   implementing draw and event-handling functions 6. a call from any
--   other screen which enters it (eg the menu screen, a new case in
--   msEnterScreen) 7. 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

-- | the all-accounts, cash, balance sheet and income statement screens;
--   see _assKind
AS :: AccountsScreenState -> Screen
RS :: RegisterScreenState -> Screen
TS :: TransactionScreenState -> Screen
ES :: ErrorScreenState -> 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 :: AccountsScreenKind -> AccountName -> List Name AccountsScreenItem -> AccountsScreenState

-- | which accounts-like screen this is
[_assKind] :: AccountsScreenState -> AccountsScreenKind

-- | 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 -> Bool -> [NumberedTransaction] -> NumberedTransaction -> TransactionScreenState

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

-- | whether the parent register included subaccounts
[_tssForceInclusive] :: TransactionScreenState -> Bool

-- | 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 -> AccountsScreenKind -> MenuScreenItem

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

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

-- | 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 ()
assKind :: Lens' AccountsScreenState AccountsScreenKind
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
tssForceInclusive :: Lens' TransactionScreenState Bool
tssTransaction :: Lens' TransactionScreenState NumberedTransaction
tssTransactions :: Lens' TransactionScreenState [NumberedTransaction]
essError :: Lens' ErrorScreenState String
essUnused :: Lens' ErrorScreenState ()
uioptslens :: Functor f => (UIOpts -> f UIOpts) -> UIState -> f UIState
instance GHC.Internal.Classes.Eq Hledger.UI.UITypes.AccountsScreenKind
instance GHC.Internal.Classes.Eq Hledger.UI.UITypes.AppEvent
instance GHC.Internal.Classes.Eq Hledger.UI.UITypes.ClickFocus
instance GHC.Internal.Classes.Eq (Brick.Widgets.Edit.Editor l n)
instance GHC.Internal.Classes.Eq Hledger.UI.UITypes.Mode
instance GHC.Internal.Classes.Eq Hledger.UI.UITypes.Name
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.Internal.Classes.Ord Hledger.UI.UITypes.AccountsScreenKind
instance GHC.Internal.Classes.Ord Hledger.UI.UITypes.Name
instance GHC.Internal.Show.Show Hledger.UI.UITypes.AccountsScreenItem
instance GHC.Internal.Show.Show Hledger.UI.UITypes.AccountsScreenKind
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.ClickFocus
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.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

-- | Recognise the click that brings a background terminal window forward,
--   so that it only activates the window, without also selecting or
--   entering something. With focus reporting on, such a click arrives as a
--   focus gain followed, a moment later, by a left button press; we ignore
--   that press, any repeats of it, and its release. A click made more than
--   <a>activatingClickTime</a> after the window gained focus (eg after
--   switching to it with the keyboard) is handled as usual. Focus events
--   themselves are not passed on. Given the current time, an event and the
--   current state, returns the new state and whether to ignore the event.
clickFocusStep :: UTCTime -> BrickEvent n e -> ClickFocus -> (ClickFocus, Bool)

-- | 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. When the selected item is near the end of
--   the list, the viewport is capped so that no blank padding is visible
--   below the last real item, and the last real items stay bottom-aligned
--   (so recentering a near-the-end selection doesn't push those items off
--   screen). numitems is the number of non-blank items in the list.
scrollSelectionToMiddle :: Int -> 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 ()

-- | Make warnIO collect warnings in uiWarningsRef instead of printing them
--   to stderr. Call once, before starting the brick app.
uiInstallWarningCollector :: IO ()

-- | Take any warnings collected since last time, clearing the collection.
uiTakeWarnings :: IO [String]

-- | Was this journal's main file read from standard input ? If so it can't
--   be re-read, edited, or watched for changes.
journalIsFromStdin :: Journal -> Bool

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

-- | 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-like screen (all accounts, cash, balance sheet
--   or income statement, selected by the AccountsScreenKind), listing the
--   appropriate set of accounts, with the appropriate one selected.
--   Screen-specific arguments: the kind of screen, and the account to
--   select if any.
asNew :: AccountsScreenKind -> UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update an accounts-like screen's state from these options, reporting
--   date, and journal. The report is restricted and accumulated according
--   to the screen's kind (_assKind).
asUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asItemIndex :: Int

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

-- | The report-options modifier for an accounts-like screen of the given
--   kind: which balance accumulation it forces, if any.
accountsScreenRoptsMod :: AccountsScreenKind -> ReportOpts -> ReportOpts

-- | The extra query restricting an accounts-like screen of the given kind
--   to its account types.
accountsScreenQuery :: AccountsScreenKind -> Query

-- | 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, whether that register included subaccounts, the list of
--   showable transactions, the currently shown transaction.
tsNew :: AccountName -> Bool -> [NumberedTransaction] -> NumberedTransaction -> Screen

-- | Update a transaction screen: rebuild its transaction list from the
--   (possibly reloaded) journal, and reselect the same transaction by its
--   journal index, so the screen refreshes in place on reload. If that
--   transaction is gone, fall back to the one at the same position, else
--   the last, else a blank.
tsUpdate :: UIOpts -> Day -> Journal -> TransactionScreenState -> TransactionScreenState

-- | Set selected index of a list if there are displayitems. If there are
--   no displayitems, remove the selected index of the list.
listMoveToIfDisplayItems :: Int -> [item] -> GenericList Name Vector item -> GenericList Name Vector item

-- | The account a register-like screen should display: normally the
--   screen's stored account, but when that is a lot subaccount and lot
--   detail is collapsed (so the account doesn't exist in the display
--   journal), its base account, where the collapsed postings now appear.
--   Keep the collapse condition synced with uiDisplayJournal.
uiDisplayAccount :: UIOpts -> AccountName -> AccountName


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

-- | Make an initial UI state with the given options, journal, parent
--   screen stack if any, and starting screen. The provided journal should
--   be the uncollapsed journal (with full lot detail); the display journal
--   (ajournal) is derived from it according to the lots toggle.
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 display of lot detail (lot subaccounts and synthetic lot
--   postings), like the CLI's --lots flag. This only flips the option;
--   <a>regenerateScreens</a> then re-derives the display journal from the
--   stored uncollapsed journal, in memory, without reloading from disk.
toggleLots :: UIState -> UIState

-- | Derive the display journal (what screens show) from the uncollapsed
--   journal: prepare lot detail for the current options (converted to cost
--   basis when B is on), collapsing it unless the lots toggle (--lots) is
--   on. Mirrors the CLI's maybePrepareLotDetail, so UI and CLI agree (and
--   --ignore-lots is honored).
uiDisplayJournal :: UIOpts -> Journal -> Journal

-- | 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. Also sets no_elide, which hledger-ui
--   wants in tree mode only (see uiInitialState).
setTree :: UIState -> UIState

-- | Set flat account list mode. Also unsets no_elide, which hledger-ui
--   wants in tree mode only (see uiInitialState).
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

-- | Return to the parent screen, discarding the active one. At the root
--   screen this is a no-op, since the stack always keeps at least one
--   screen. The canonical way to pop the zipper.
popScreen :: UIState -> UIState

-- | Descend into a new screen, making it active and suspending the current
--   one onto the navigation stack. The canonical way to push the zipper.
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

-- | Regenerate the content of all screens in the stack from the ui state's
--   current options and stored journal, preserving the screen navigation
--   history. Note, does not save the reporting date.
--   
--   This is the single place that establishes the display journal
--   (ajournal) from the stored uncollapsed journal and the current
--   options, so the two journals can never drift out of sync. To change
--   the journal (eg on reload), set auncollapsedjournal and then call
--   this. To change the lots toggle, flip the option (toggleLots) and call
--   this.
--   
--   Every screen regenerates from its own stored parameters (plus the
--   options, date and journal), not from any other screen, so the whole
--   stack refreshes uniformly here.
regenerateScreens :: 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 :: ErrorScreenState -> UIState -> [Widget Name]
esHandle :: ErrorScreenState -> 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 and assert rules (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 or --obfuscate
--   is active, a full journal reload is done instead (because they change
--   account names, so the checks can't be done on the in-memory journal).
--   In that case, this operation could be slower and could reveal other
--   data changes (not just check failures).
uiToggleBalanceAssertions :: Day -> UIState -> EventM Name UIState ()

-- | Modify some input options for loading the journal in hledger-ui, given
--   its startup options: always enable --forecast, so forecast
--   transactions can be shown or hidden without reloading. If --forecast
--   wasn't used at startup, mark the forecast as only for display, so
--   assert rules ignore it.
uiAdjustOpts :: UIOpts -> CliOpts -> CliOpts

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, whether that register included subaccounts, the list of
--   showable transactions, the currently shown transaction.
tsNew :: AccountName -> Bool -> [NumberedTransaction] -> NumberedTransaction -> Screen

-- | Update a transaction screen: rebuild its transaction list from the
--   (possibly reloaded) journal, and reselect the same transaction by its
--   journal index, so the screen refreshes in place on reload. If that
--   transaction is gone, fall back to the one at the same position, else
--   the last, else a blank.
tsUpdate :: UIOpts -> Day -> Journal -> TransactionScreenState -> TransactionScreenState
tsDraw :: TransactionScreenState -> UIState -> [Widget Name]
tsHandle :: TransactionScreenState -> BrickEvent Name AppEvent -> 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 :: RegisterScreenState -> UIState -> [Widget Name]
rsHandle :: RegisterScreenState -> 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.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 :: MenuScreenState -> UIState -> [Widget Name]
msHandle :: MenuScreenState -> 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-like screen (all accounts, cash, balance sheet
--   or income statement, selected by the AccountsScreenKind), listing the
--   appropriate set of accounts, with the appropriate one selected.
--   Screen-specific arguments: the kind of screen, and the account to
--   select if any.
asNew :: AccountsScreenKind -> UIOpts -> Day -> Journal -> Maybe AccountName -> Screen

-- | Update an accounts-like screen's state from these options, reporting
--   date, and journal. The report is restricted and accumulated according
--   to the screen's kind (_assKind).
asUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asDraw :: AccountsScreenState -> 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 :: AccountsScreenState -> UIState -> ReportOpts -> String -> [Widget Name]

-- | Handle events on any accounts-like screen (all accounts, balance
--   sheet, income statement..).
asHandle :: AccountsScreenState -> 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 state should be the ui state's current screen.
asHandleNormalMode :: AccountsScreenState -> 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


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

-- | Make an action like <tt>mkVty mempty</tt>, but reading keyboard input
--   from the controlling terminal's device rather than from stdin. Used
--   when the journal data was read from stdin, which leaves that handle
--   consumed and closed. The terminal is opened once, here; the returned
--   action can be run repeatedly (eg when resuming after a suspend). Unix
--   only; on Windows this is just mkVty.
ttyVtyMaker :: IO (IO Vty)

-- | Open the controlling terminal for reading, without making it our
--   controlling terminal if we have none, and not inherited by child
--   processes. Prefer the terminal's real device path (eg
--   <i>dev</i>ttys003) over <i>dev</i>tty: macOS's kqueue can't wait on
--   the latter, so vty's input thread would block in read() and shutdown
--   would hang until the next key press. Fall back to <i>dev</i>tty if the
--   device can't be opened (eg after su).
openTerminal :: IO Fd

-- | Build hledger-ui's startup state: normalise the options, choose the
--   initial screen, and set up the stack of previous screens as if the
--   user had navigated down to it from the menu. Uses the startup report
--   date (<tt>copts^.rsDay</tt>), so it is deterministic and reusable
--   outside the brick app (eg from tests). Keep synced with msNew.
uiInitialState :: UIOpts -> Journal -> UIState
runBrickUi :: UIOpts -> Journal -> IO ()
brickApp :: Maybe String -> App UIState AppEvent Name
uiHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
uiDraw :: UIState -> [Widget Name]

-- | An overlay layer showing the given (most recent) warning message, and
--   how many more there are, on the screen's bottom line until the next
--   keypress.
warningOverlay :: String -> Int -> 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
