imp: ui: add flags to select starting screen

This commit is contained in:
Simon Michael 2022-11-07 16:04:39 -10:00
parent 1a526b82c9
commit a726be0e28
3 changed files with 52 additions and 23 deletions

View File

@ -6,6 +6,7 @@ Released under GPL version 3 or later.
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiWayIf #-}
module Hledger.UI.Main where
@ -140,20 +141,27 @@ runBrickUi uopts0@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=r
-- Choose the initial screen to display.
-- We like to show the balance sheet accounts screen by default,
-- but that can change eg if we can't detect any, or
-- if an account query has been provided at startup.
-- Whichever it is, we also set up a stack of previous screens,
-- but that can change eg if we can't detect any accounts for it,
-- or if an account query has been provided at startup,
-- or if a specific screen has been requested by command line flag.
-- Whichever is the initial screen, we also set up a stack of previous screens,
-- as if you had navigated down to it from the top.
-- (remember, the previous screens list is ordered nearest/lowest first)
rawopts = rawopts_ $ uoCliOpts $ uopts
(prevscrs, currscr) =
dbg1With (showScreenStack "initial" showScreenSelection . uncurry2 (uiState defuiopts nulljournal)) $
case (uoRegister uopts, hasbsaccts, hasacctquery) of
if
| boolopt "menu" rawopts -> ([], menuscr)
| boolopt "all" rawopts -> ([msSetSelectedScreen 0 menuscr], allacctsscr)
| boolopt "bs" rawopts -> ([menuscr], bsacctsscr)
| boolopt "is" rawopts -> ([msSetSelectedScreen 2 menuscr], isacctsscr)
-- With --register=ACCT, the initial screen stack is:
-- 1. menu screen, with ACCTSSCR selected
-- 2. ACCTSSCR (the accounts screen containing ACCT), with ACCT selected
-- 3. register screen for ACCT
(Just apat, _, _) -> ([acctsscr, menuscr'], regscr) -- remember, previous screens are ordered nearest/lowest first
where
-- menu screen, with ACCTSSCR selected
-- ACCTSSCR (the accounts screen containing ACCT), with ACCT selected
-- register screen for ACCT
| Just apat <- uoRegister uopts ->
let
-- the account being requested
acct = fromMaybe (error' $ "--register "++apat++" did not match any account") -- PARTIAL:
. firstMatch $ journalAccountNamesDeclaredOrImplied j
@ -182,16 +190,12 @@ runBrickUi uopts0@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=r
-- the menu screen
menuscr' = msSetSelectedScreen selidx menuscr
in ([acctsscr, menuscr'], regscr)
-- Or with balance sheet accounts detected and no initial account query, it is:
-- 1. menu screen, with balance sheet accounts screen selected
-- 2. balance sheet accounts screen
(Nothing, True, False) -> ([menuscr], bsacctsscr)
-- No balance sheet accounts detected, or an initial account query specified:
| not hasbsaccts || hasacctquery -> ([msSetSelectedScreen 0 menuscr], allacctsscr)
-- Otherwise it is:
-- 1. menu screen, with all accounts screen selected
-- 2. all accounts screen
(Nothing, _, _) -> ([msSetSelectedScreen 0 menuscr], allacctsscr)
| otherwise -> ([menuscr], bsacctsscr)
where
hasbsaccts = any (`elem` accttypes) [Asset, Liability, Equity]

View File

@ -36,7 +36,11 @@ uiflags = [
-- flagNone ["debug-ui"] (setboolopt "rules-file") "run with no terminal output, showing console"
flagNone ["watch","w"] (setboolopt "watch") "watch for data and date changes and reload automatically"
,flagReq ["theme"] (\s opts -> Right $ setopt "theme" s opts) "THEME" ("use this custom display theme ("++intercalate ", " themeNames++")")
,flagReq ["register"] (\s opts -> Right $ setopt "register" s opts) "ACCTREGEX" "start in the (first) matched account's register"
,flagNone ["menu"] (setboolopt "menu") "start in the menu screen"
,flagNone ["all"] (setboolopt "all") "start in the all accounts screen"
,flagNone ["bs"] (setboolopt "bs") "start in the balance sheet accounts screen"
,flagNone ["is"] (setboolopt "is") "start in the income statement accounts screen"
,flagReq ["register"] (\s opts -> Right $ setopt "register" s opts) "ACCTREGEX" "start in the (first matched) account's register"
,flagNone ["change"] (setboolopt "change")
"show period balances (changes) at startup instead of historical balances"
-- ,flagNone ["cumulative"] (setboolopt "cumulative")
@ -53,7 +57,7 @@ uiflags = [
--uimode :: Mode RawOpts
uimode = (mode "hledger-ui" (setopt "command" "ui" def)
"browse accounts, postings and entries in a full-window curses interface"
(argsFlag "[PATTERNS]") []){
(argsFlag "[--menu|--all|--bs|--is|--register=ACCT] [QUERY]") []){
modeGroupFlags = Group {
groupUnnamed = uiflags
,groupHidden = hiddenflags

View File

@ -60,6 +60,18 @@ Any QUERYARGS are interpreted as a hledger search query which filters the data.
`--theme=default|terminal|greenterm`
: use this custom display theme
`--menu`
: start in the menu screen
`--all`
: start in the all accounts screen
`--bs`
: start in the balance sheet accounts screen
`--is`
: start in the income statement accounts screen
`--register=ACCTREGEX`
: start in the (first) matched account's register screen
@ -189,6 +201,16 @@ Additional screen-specific keys are described below.
# SCREENS
hledger-ui can show a number of different screens, described below.
It shows the Balance sheet accounts screen to start with, except in the following situations:
- If no asset/liability/equity accounts can be detected,
or if an account query has been given on the command line,
it starts in the All accounts screen.
- If a starting screen is specified with --menu/--all/--bs/--is/--register
on the command line, it starts there.
## Menu screen
The top-most screen. hledger-ui does not show this screen at startup,
@ -197,13 +219,12 @@ From here you can navigate to three accounts screens:
## All accounts screen
This screen shows all accounts (unless filtered by a query), and their current balances.
It is like the `hledger balance` command.
This screen shows all accounts (possibly filtered by a query), and their current balances.
It is like the `hledger balance` command.
## Balance sheet accounts screen
This is the screen normally shown at startup.
It shows asset, liability and equity accounts, if these can be detected (see [account types](/hledger.html#account-types)).
This screen shows asset, liability and equity accounts, if these can be detected (see [account types](/hledger.html#account-types)).
It always shows historical end balances on some date (not balance changes).
It is like the `hledger balancesheetequity` command.