imp: ui: add flags to select starting screen
This commit is contained in:
parent
1a526b82c9
commit
a726be0e28
@ -6,6 +6,7 @@ Released under GPL version 3 or later.
|
|||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE MultiWayIf #-}
|
||||||
|
|
||||||
module Hledger.UI.Main where
|
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.
|
-- Choose the initial screen to display.
|
||||||
-- We like to show the balance sheet accounts screen by default,
|
-- We like to show the balance sheet accounts screen by default,
|
||||||
-- but that can change eg if we can't detect any, or
|
-- but that can change eg if we can't detect any accounts for it,
|
||||||
-- if an account query has been provided at startup.
|
-- or if an account query has been provided at startup,
|
||||||
-- Whichever it is, we also set up a stack of previous screens,
|
-- 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.
|
-- 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) =
|
(prevscrs, currscr) =
|
||||||
dbg1With (showScreenStack "initial" showScreenSelection . uncurry2 (uiState defuiopts nulljournal)) $
|
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:
|
-- With --register=ACCT, the initial screen stack is:
|
||||||
-- 1. menu screen, with ACCTSSCR selected
|
-- menu screen, with ACCTSSCR selected
|
||||||
-- 2. ACCTSSCR (the accounts screen containing ACCT), with ACCT selected
|
-- ACCTSSCR (the accounts screen containing ACCT), with ACCT selected
|
||||||
-- 3. register screen for ACCT
|
-- register screen for ACCT
|
||||||
(Just apat, _, _) -> ([acctsscr, menuscr'], regscr) -- remember, previous screens are ordered nearest/lowest first
|
| Just apat <- uoRegister uopts ->
|
||||||
where
|
let
|
||||||
-- the account being requested
|
-- the account being requested
|
||||||
acct = fromMaybe (error' $ "--register "++apat++" did not match any account") -- PARTIAL:
|
acct = fromMaybe (error' $ "--register "++apat++" did not match any account") -- PARTIAL:
|
||||||
. firstMatch $ journalAccountNamesDeclaredOrImplied j
|
. firstMatch $ journalAccountNamesDeclaredOrImplied j
|
||||||
@ -182,16 +190,12 @@ runBrickUi uopts0@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=r
|
|||||||
|
|
||||||
-- the menu screen
|
-- the menu screen
|
||||||
menuscr' = msSetSelectedScreen selidx menuscr
|
menuscr' = msSetSelectedScreen selidx menuscr
|
||||||
|
in ([acctsscr, menuscr'], regscr)
|
||||||
|
|
||||||
-- Or with balance sheet accounts detected and no initial account query, it is:
|
-- No balance sheet accounts detected, or an initial account query specified:
|
||||||
-- 1. menu screen, with balance sheet accounts screen selected
|
| not hasbsaccts || hasacctquery -> ([msSetSelectedScreen 0 menuscr], allacctsscr)
|
||||||
-- 2. balance sheet accounts screen
|
|
||||||
(Nothing, True, False) -> ([menuscr], bsacctsscr)
|
|
||||||
|
|
||||||
-- Otherwise it is:
|
| otherwise -> ([menuscr], bsacctsscr)
|
||||||
-- 1. menu screen, with all accounts screen selected
|
|
||||||
-- 2. all accounts screen
|
|
||||||
(Nothing, _, _) -> ([msSetSelectedScreen 0 menuscr], allacctsscr)
|
|
||||||
|
|
||||||
where
|
where
|
||||||
hasbsaccts = any (`elem` accttypes) [Asset, Liability, Equity]
|
hasbsaccts = any (`elem` accttypes) [Asset, Liability, Equity]
|
||||||
|
|||||||
@ -36,7 +36,11 @@ uiflags = [
|
|||||||
-- flagNone ["debug-ui"] (setboolopt "rules-file") "run with no terminal output, showing console"
|
-- 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"
|
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 ["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")
|
,flagNone ["change"] (setboolopt "change")
|
||||||
"show period balances (changes) at startup instead of historical balances"
|
"show period balances (changes) at startup instead of historical balances"
|
||||||
-- ,flagNone ["cumulative"] (setboolopt "cumulative")
|
-- ,flagNone ["cumulative"] (setboolopt "cumulative")
|
||||||
@ -53,7 +57,7 @@ uiflags = [
|
|||||||
--uimode :: Mode RawOpts
|
--uimode :: Mode RawOpts
|
||||||
uimode = (mode "hledger-ui" (setopt "command" "ui" def)
|
uimode = (mode "hledger-ui" (setopt "command" "ui" def)
|
||||||
"browse accounts, postings and entries in a full-window curses interface"
|
"browse accounts, postings and entries in a full-window curses interface"
|
||||||
(argsFlag "[PATTERNS]") []){
|
(argsFlag "[--menu|--all|--bs|--is|--register=ACCT] [QUERY]") []){
|
||||||
modeGroupFlags = Group {
|
modeGroupFlags = Group {
|
||||||
groupUnnamed = uiflags
|
groupUnnamed = uiflags
|
||||||
,groupHidden = hiddenflags
|
,groupHidden = hiddenflags
|
||||||
|
|||||||
@ -60,6 +60,18 @@ Any QUERYARGS are interpreted as a hledger search query which filters the data.
|
|||||||
`--theme=default|terminal|greenterm`
|
`--theme=default|terminal|greenterm`
|
||||||
: use this custom display theme
|
: 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`
|
`--register=ACCTREGEX`
|
||||||
: start in the (first) matched account's register screen
|
: start in the (first) matched account's register screen
|
||||||
|
|
||||||
@ -189,6 +201,16 @@ Additional screen-specific keys are described below.
|
|||||||
|
|
||||||
# SCREENS
|
# 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
|
## Menu screen
|
||||||
|
|
||||||
The top-most screen. hledger-ui does not show this screen at startup,
|
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
|
## All accounts screen
|
||||||
|
|
||||||
This screen shows all accounts (unless filtered by a query), and their current balances.
|
This screen shows all accounts (possibly filtered by a query), and their current balances.
|
||||||
It is like the `hledger balance` command.
|
It is like the `hledger balance` command.
|
||||||
|
|
||||||
## Balance sheet accounts screen
|
## Balance sheet accounts screen
|
||||||
|
|
||||||
This is the screen normally shown at startup.
|
This screen shows asset, liability and equity accounts, if these can be detected (see [account types](/hledger.html#account-types)).
|
||||||
It 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 always shows historical end balances on some date (not balance changes).
|
||||||
It is like the `hledger balancesheetequity` command.
|
It is like the `hledger balancesheetequity` command.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user