ui: add vi-style movement keys, use ? for help (#357)

This commit is contained in:
Simon Michael 2016-06-24 18:48:14 -07:00
parent 529d55dd54
commit dbeb4e3020
8 changed files with 122 additions and 109 deletions

View File

@ -186,7 +186,7 @@ asDraw UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
Minibuffer ed -> minibuffer ed
_ -> quickhelp
quickhelp = borderKeysStr [
("h", "help")
("?", "help")
,("right", "register")
,("F", "flat?")
,("-+0123456789", "depth")
@ -265,7 +265,7 @@ asHandle ui0@UIState{
EvKey (KChar 'q') [] -> halt ui
-- EvKey (KChar 'l') [MCtrl] -> do
EvKey KEsc [] -> continue $ resetScreens d ui
EvKey (KChar c) [] | c `elem` ['h','?'] -> continue $ setMode Help ui
EvKey (KChar c) [] | c `elem` ['?'] -> continue $ setMode Help ui
EvKey (KChar 'g') [] -> liftIO (uiReloadJournalIfChanged copts d j ui) >>= continue
EvKey (KChar 'a') [] -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add copts j >> uiReloadJournalIfChanged copts d j ui
EvKey (KChar 'E') [] -> suspendAndResume $ void (runEditor endPos (journalFilePath j)) >> uiReloadJournalIfChanged copts d j ui
@ -289,18 +289,22 @@ asHandle ui0@UIState{
EvKey (KChar 'R') [] -> scrollTop >> (continue $ regenerateScreens j d $ toggleReal ui)
EvKey (KChar '/') [] -> continue $ regenerateScreens j d $ showMinibuffer ui
EvKey k [] | k `elem` [KBS, KDel] -> (continue $ regenerateScreens j d $ resetFilter ui)
EvKey (KLeft) [] -> continue $ popScreen ui
EvKey k [] | k `elem` [KRight, KEnter] -> scrollTopRegister >> continue (screenEnter d scr ui)
EvKey k [] | k `elem` [KLeft, KChar 'h'] -> continue $ popScreen ui
EvKey k [] | k `elem` [KRight, KChar 'l', KEnter] -> scrollTopRegister >> continue (screenEnter d scr ui)
where
scr = rsSetAccount selacct registerScreen
-- fall through to the list's event handler (handles up/down)
ev -> do
newitems <- handleEvent ev (scr ^. asList)
continue $ ui{aScreen=scr & asList .~ newitems
& asSelectedAccount .~ selacct
}
-- continue =<< handleEventLensed ui someLens ev
ev -> do
let ev' = case ev of
EvKey (KChar 'k') [] -> EvKey (KUp) []
EvKey (KChar 'j') [] -> EvKey (KDown) []
_ -> ev
newitems <- handleEvent ev' (scr ^. asList)
continue $ ui{aScreen=scr & asList .~ newitems
& asSelectedAccount .~ selacct
}
-- continue =<< handleEventLensed ui someLens ev
where
-- Encourage a more stable scroll position when toggling list items.

View File

@ -186,7 +186,7 @@ rsDraw UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
Minibuffer ed -> minibuffer ed
_ -> quickhelp
quickhelp = borderKeysStr [
("h", "help")
("?", "help")
,("left", "back")
,("right", "transaction")
,("/", "filter")
@ -247,7 +247,7 @@ rsHandle ui@UIState{
case ev of
EvKey (KChar 'q') [] -> halt ui
EvKey KEsc [] -> continue $ resetScreens d ui
EvKey (KChar c) [] | c `elem` ['h','?'] -> continue $ setMode Help ui
EvKey (KChar c) [] | c `elem` ['?'] -> continue $ setMode Help ui
EvKey (KChar 'g') [] -> liftIO (uiReloadJournalIfChanged copts d j ui) >>= continue
EvKey (KChar 'a') [] -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add copts j >> uiReloadJournalIfChanged copts d j ui
EvKey (KChar 'E') [] -> suspendAndResume $ void (runEditor pos f) >> uiReloadJournalIfChanged copts d j ui
@ -262,8 +262,8 @@ rsHandle ui@UIState{
EvKey (KChar 'R') [] -> scrollTop >> (continue $ regenerateScreens j d $ toggleReal ui)
EvKey (KChar '/') [] -> (continue $ regenerateScreens j d $ showMinibuffer ui)
EvKey k [] | k `elem` [KBS, KDel] -> (continue $ regenerateScreens j d $ resetFilter ui)
EvKey (KLeft) [] -> continue $ popScreen ui
EvKey k [] | k `elem` [KRight, KEnter] -> do
EvKey k [] | k `elem` [KLeft, KChar 'h'] -> continue $ popScreen ui
EvKey k [] | k `elem` [KRight, KChar 'l', KEnter] -> do
case listSelectedElement rsList of
Just (_, RegisterScreenItem{rsItemTransaction=t}) ->
let
@ -276,9 +276,14 @@ rsHandle ui@UIState{
,tsAccount=rsAccount} ui
Nothing -> continue ui
-- fall through to the list's event handler (handles [pg]up/down)
ev -> do newitems <- handleEvent ev rsList
continue ui{aScreen=s{rsList=newitems}}
-- continue =<< handleEventLensed ui someLens ev
ev -> do
let ev' = case ev of
EvKey (KChar 'k') [] -> EvKey (KUp) []
EvKey (KChar 'j') [] -> EvKey (KDown) []
_ -> ev
newitems <- handleEvent ev' rsList
continue ui{aScreen=s{rsList=newitems}}
-- continue =<< handleEventLensed ui someLens ev
where
-- Encourage a more stable scroll position when toggling list items (cf AccountsScreen.hs)
scrollTop = vScrollToBeginning $ viewportScroll "register"

View File

@ -89,7 +89,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
-- Minibuffer ed -> minibuffer ed
_ -> quickhelp
quickhelp = borderKeysStr [
("h", "help")
("?", "help")
,("left", "back")
,("up/down", "prev/next")
--,("ESC", "cancel/top")
@ -124,7 +124,7 @@ tsHandle ui@UIState{aScreen=s@TransactionScreen{tsTransaction=(i,t)
case ev of
EvKey (KChar 'q') [] -> halt ui
EvKey KEsc [] -> continue $ resetScreens d ui
EvKey (KChar c) [] | c `elem` ['h','?'] -> continue $ setMode Help ui
EvKey (KChar c) [] | c `elem` ['?'] -> continue $ setMode Help ui
EvKey (KChar 'E') [] -> suspendAndResume $ void (runEditor pos f) >> uiReloadJournalIfChanged copts d j ui
where
(pos,f) = let GenericSourcePos f l c = tsourcepos t in (Just (l, Just c),f)
@ -160,9 +160,9 @@ tsHandle ui@UIState{aScreen=s@TransactionScreen{tsTransaction=(i,t)
-- EvKey (KChar 'E') [] -> continue $ regenerateScreens j d $ stToggleEmpty ui
-- EvKey (KChar 'C') [] -> continue $ regenerateScreens j d $ stToggleCleared ui
-- EvKey (KChar 'R') [] -> continue $ regenerateScreens j d $ stToggleReal ui
EvKey KUp [] -> continue $ regenerateScreens j d ui{aScreen=s{tsTransaction=(iprev,tprev)}}
EvKey KDown [] -> continue $ regenerateScreens j d ui{aScreen=s{tsTransaction=(inext,tnext)}}
EvKey KLeft [] -> continue ui''
EvKey k [] | k `elem` [KUp, KChar 'k'] -> continue $ regenerateScreens j d ui{aScreen=s{tsTransaction=(iprev,tprev)}}
EvKey k [] | k `elem` [KDown, KChar 'j'] -> continue $ regenerateScreens j d ui{aScreen=s{tsTransaction=(inext,tnext)}}
EvKey k [] | k `elem` [KLeft, KChar 'h'] -> continue ui''
where
ui'@UIState{aScreen=scr} = popScreen ui
ui'' = ui'{aScreen=rsSelect (fromIntegral i) scr}

View File

@ -34,25 +34,25 @@ helpDialog =
Widget Fixed Fixed $ do
c <- getContext
render $
renderDialog (dialog "help" (Just "Help (h/ESC to close)") Nothing (c^.availWidthL - 2)) $ -- (Just (0,[("ok",())]))
renderDialog (dialog "help" (Just "Help (?/LEFT/ESC to close)") Nothing (c^.availWidthL - 2)) $ -- (Just (0,[("ok",())]))
padTopBottom 1 $ padLeftRight 1 $
vBox [
hBox [
padLeftRight 1 $
vBox [
str "MISC"
,renderKey ("h", "toggle help")
str "NAVIGATION"
,renderKey ("UP/DOWN/k/j/PGUP/PGDN/HOME/END", "")
,str " move selection"
,renderKey ("RIGHT/l/ENTER", "drill down")
,renderKey ("LEFT/h", "previous screen")
,renderKey ("ESC", "cancel / reset")
,str " "
,str "MISC"
,renderKey ("?", "toggle help")
,renderKey ("a", "add transaction")
,renderKey ("E", "open editor")
,renderKey ("g", "reload data")
,renderKey ("q", "quit")
,str " "
,str "NAVIGATION"
,renderKey ("UP/DOWN/PGUP/PGDN/HOME/END", "")
,str " move selection"
,renderKey ("RIGHT/ENTER", "drill down")
,renderKey ("LEFT", "previous screen")
,renderKey ("ESC", "cancel / reset")
]
,padLeftRight 1 $
vBox [
@ -89,7 +89,7 @@ helpDialog =
helpHandle :: UIState -> Event -> EventM (Next UIState)
helpHandle ui ev =
case ev of
EvKey k [] | k `elem` [KEsc, KChar 'h', KChar '?'] -> continue $ setMode Normal ui
EvKey k [] | k `elem` [KEsc, KLeft, KChar 'h', KChar '?'] -> continue $ setMode Normal ui
EvKey (KChar 't') [] -> suspendAndResume $ runHelp >> return (setMode Normal ui)
EvKey (KChar 'm') [] -> suspendAndResume $ runMan >> return (setMode Normal ui)
EvKey (KChar 'i') [] -> suspendAndResume $ runInfo >> return (setMode Normal ui)

View File

@ -217,15 +217,17 @@ be "TAG:multi:level:account:name".
.RE
.SH KEYS
.PP
\f[C]h\f[] shows a help dialog listing all keys.
\f[C]?\f[] shows a help dialog listing all keys.
(Some but not all of these also appear in the quick help at the bottom
of each screen.) Press \f[C]h\f[] again (or \f[C]ESCAPE\f[]) to close
it.
of each screen.) Press \f[C]?\f[] again (or \f[C]ESCAPE\f[], or
\f[C]LEFT\f[]) to close it.
.PP
The cursor keys navigate: \f[C]right\f[] (or \f[C]enter\f[]) goes
deeper, \f[C]left\f[] returns to the previous screen,
\f[C]up\f[]/\f[C]down\f[]/\f[C]page\ up\f[]/\f[C]page\ down\f[]/\f[C]home\f[]/\f[C]end\f[]
move up and down through lists.
Vi\-style \f[C]h\f[]/\f[C]j\f[]/\f[C]k\f[]/\f[C]l\f[] movement keys are
also supported.
.PP
\f[C]/\f[] lets you set or change the filter query, which limits the
data shown on most screens (in addition to the quick filters described

View File

@ -152,13 +152,14 @@ File: hledger-ui.1.info, Node: KEYS, Next: SCREENS, Prev: OPTIONS, Up: Top
2 KEYS
******
`h' shows a help dialog listing all keys. (Some but not all of these
also appear in the quick help at the bottom of each screen.) Press `h'
again (or `ESCAPE') to close it.
`?' shows a help dialog listing all keys. (Some but not all of these
also appear in the quick help at the bottom of each screen.) Press `?'
again (or `ESCAPE', or `LEFT') to close it.
The cursor keys navigate: `right' (or `enter') goes deeper, `left'
returns to the previous screen, `up'/`down'/`page up'/`page
down'/`home'/`end' move up and down through lists.
down'/`home'/`end' move up and down through lists. Vi-style
`h'/`j'/`k'/`l' movement keys are also supported.
`/' lets you set or change the filter query, which limits the data
shown on most screens (in addition to the quick filters described
@ -334,15 +335,15 @@ Node: OPTIONS825
Ref: #options924
Node: KEYS3800
Ref: #keys3897
Node: SCREENS5391
Ref: #screens5478
Node: Accounts screen5568
Ref: #accounts-screen5698
Node: Register screen7003
Ref: #register-screen7160
Node: Transaction screen8981
Ref: #transaction-screen9141
Node: Error screen10008
Ref: #error-screen10132
Node: SCREENS5461
Ref: #screens5548
Node: Accounts screen5638
Ref: #accounts-screen5768
Node: Register screen7073
Ref: #register-screen7230
Node: Transaction screen9051
Ref: #transaction-screen9211
Node: Error screen10078
Ref: #error-screen10202

End Tag Table

View File

@ -75,14 +75,15 @@ _reportingoptions_
# KEYS
`h` shows a help dialog listing all keys.
`?` shows a help dialog listing all keys.
(Some but not all of these also appear in the quick help at the bottom of each screen.)
Press `h` again (or `ESCAPE`) to close it.
Press `?` again (or `ESCAPE`, or `LEFT`) to close it.
The cursor keys navigate:
`right` (or `enter`) goes deeper,
`left` returns to the previous screen,
`up`/`down`/`page up`/`page down`/`home`/`end` move up and down through lists.
Vi-style `h`/`j`/`k`/`l` movement keys are also supported.
`/` lets you set or change the [filter query](/hledger.html#queries),
which limits the data shown on most screens (in addition to the quick

View File

@ -141,36 +141,36 @@ OPTIONS
name will be "TAG:multi:level:account:name".
KEYS
h shows a help dialog listing all keys. (Some but not all of these
also appear in the quick help at the bottom of each screen.) Press h
again (or ESCAPE) to close it.
? shows a help dialog listing all keys. (Some but not all of these
also appear in the quick help at the bottom of each screen.) Press ?
again (or ESCAPE, or LEFT) to close it.
The cursor keys navigate: right (or enter) goes deeper, left returns to
the previous screen, up/down/page up/page down/home/end move up and
down through lists.
down through lists. Vi-style h/j/k/l movement keys are also supported.
/ lets you set or change the filter query, which limits the data shown
on most screens (in addition to the quick filters described below).
While editing the query you can use typical command-line edit keys
(ctrl-a/e/k), press enter to set the new filter, or press escape to
/ lets you set or change the filter query, which limits the data shown
on most screens (in addition to the quick filters described below).
While editing the query you can use typical command-line edit keys
(ctrl-a/e/k), press enter to set the new filter, or press escape to
cancel.
BACKSPACE or DELETE clears any filters in effect.
ESCAPE removes any filters currently in effect, and jumps to the top
screen. Or, it cancels a minibuffer edit or help dialog if one is
ESCAPE removes any filters currently in effect, and jumps to the top
screen. Or, it cancels a minibuffer edit or help dialog if one is
active.
g reloads from the data file(s) and updates the current screen and any
g reloads from the data file(s) and updates the current screen and any
previous screens. (With large files, there can be a noticeable pause.)
a runs command-line hledger's add command, and reloads the updated
a runs command-line hledger's add command, and reloads the updated
file. This allows some basic data entry.
E runs $HLEDGER_UI_EDITOR, or $EDITOR, or a default (emacs) on the
journal file. When invoked from the register and transaction screens,
E runs $HLEDGER_UI_EDITOR, or $EDITOR, or a default (emacs) on the
journal file. When invoked from the register and transaction screens,
the cursor will be positioned at the current transaction. When invoked
from the error screen, the cursor will be at the error location (if
from the error screen, the cursor will be at the error location (if
possible).
q quits the application.
@ -179,31 +179,31 @@ KEYS
SCREENS
Accounts screen
This is normally the first screen displayed. It lists accounts and
their balances, like hledger's balance command. By default, it shows
all accounts and their latest ending balances. if you specify a query
on the command line, it shows just the matched accounts and the bal-
This is normally the first screen displayed. It lists accounts and
their balances, like hledger's balance command. By default, it shows
all accounts and their latest ending balances. if you specify a query
on the command line, it shows just the matched accounts and the bal-
ances from matched transactions.
Account names are normally indented to show the hierarchy (tree mode).
Account names are normally indented to show the hierarchy (tree mode).
To see less detail, set a depth limit by pressing a number key, 1 to 9.
0 shows even less detail, collapsing all accounts to a single total. -
and + (or =) decrease and increase the depth limit. To remove the
depth limit, set it higher than the maximum account depth, or press
and + (or =) decrease and increase the depth limit. To remove the
depth limit, set it higher than the maximum account depth, or press
ESCAPE.
F toggles flat mode on and off. In flat mode, accounts are listed
without indentation (and account registers will exclude subaccounts,
F toggles flat mode on and off. In flat mode, accounts are listed
without indentation (and account registers will exclude subaccounts,
see below).
C toggles cleared mode, in which uncleared transactions and postings
are not shown. U toggles uncleared mode, in which only uncleared
C toggles cleared mode, in which uncleared transactions and postings
are not shown. U toggles uncleared mode, in which only uncleared
transactions/postings are shown.
R toggles real mode, in which virtual postings are ignored.
Z toggles nonzero mode, in which only accounts with nonzero balances
are shown (hledger-ui shows zero items by default, unlike command-line
Z toggles nonzero mode, in which only accounts with nonzero balances
are shown (hledger-ui shows zero items by default, unlike command-line
hledger).
Press right or enter to view an account's transactions register.
@ -212,15 +212,15 @@ SCREENS
This screen shows the transactions affecting a particular account, like
a check register. Each line represents one transaction and shows:
o the other account(s) involved, in abbreviated form. (If there are
both real and virtual postings, it shows only the accounts affected
o the other account(s) involved, in abbreviated form. (If there are
both real and virtual postings, it shows only the accounts affected
by real postings.)
o the overall change to the current account's balance; positive for an
o the overall change to the current account's balance; positive for an
inflow to this account, negative for an outflow.
o the current account's historic balance (if no query other than a date
limit is in effect) or the running total starting from zero (other-
limit is in effect) or the running total starting from zero (other-
wise), after the transaction.
Eg, these will show historic balances:
@ -235,45 +235,45 @@ SCREENS
$ hledger-ui --begin 'this month' desc:market
$ hledger-ui --register checking --cleared
Normally the register screen shows transactions in the current account
and any of its subaccounts (inclusive mode). If it was entered from
accounts screen in flat mode, it shows transactions affecting this
Normally the register screen shows transactions in the current account
and any of its subaccounts (inclusive mode). If it was entered from
accounts screen in flat mode, it shows transactions affecting this
account specifically, without considering subaccounts (exclusive mode).
As on the accounts screen you can toggle this with the F key.
C toggles cleared mode, in which uncleared transactions and postings
are not shown. U toggles uncleared mode, in which only uncleared
C toggles cleared mode, in which uncleared transactions and postings
are not shown. U toggles uncleared mode, in which only uncleared
transactions/postings are shown.
R toggles real mode, in which virtual postings are ignored.
Z toggles nonzero mode, in which only transactions posting a nonzero
change are shown (hledger-ui shows zero items by default, unlike com-
Z toggles nonzero mode, in which only transactions posting a nonzero
change are shown (hledger-ui shows zero items by default, unlike com-
mand-line hledger).
Press right (or enter) to view the selected transaction in detail.
Transaction screen
This screen shows a single transaction, as a general journal entry,
similar to hledger's print command and journal format (hledger_jour-
This screen shows a single transaction, as a general journal entry,
similar to hledger's print command and journal format (hledger_jour-
nal(5)).
The transaction's date(s) and any cleared flag, transaction code,
description, comments, along with all of its account postings are
shown. Simple transactions have two postings, but there can be more
The transaction's date(s) and any cleared flag, transaction code,
description, comments, along with all of its account postings are
shown. Simple transactions have two postings, but there can be more
(or in certain cases, fewer).
up and down will step through all transactions listed in the previous
account register screen. In the title bar, the numbers in parentheses
show your position within that account register. They will vary
up and down will step through all transactions listed in the previous
account register screen. In the title bar, the numbers in parentheses
show your position within that account register. They will vary
depending on which account register you came from (remember most trans-
actions appear in multiple account registers). The #N number preceding
them is the transaction's position within the complete unfiltered jour-
nal, which is a more stable id (at least until the next reload).
Error screen
This screen will appear if there is a problem, such as a parse error,
when you press g to reload. Once you have fixed the problem, press g
This screen will appear if there is a problem, such as a parse error,
when you press g to reload. Once you have fixed the problem, press g
again to reload and resume normal operation. (Or, you can press escape
to cancel the reload attempt.)
@ -281,17 +281,17 @@ ENVIRONMENT
COLUMNS The screen width to use. Default: the full terminal width.
LEDGER_FILE The journal file path when not specified with -f. Default:
~/.hledger.journal (on windows, perhaps C:/Users/USER/.hledger.jour-
~/.hledger.journal (on windows, perhaps C:/Users/USER/.hledger.jour-
nal).
FILES
Reads data from one or more files in hledger journal, timeclock, time-
dot, or CSV format specified with -f, or $LEDGER_FILE, or
$HOME/.hledger.journal (on windows, perhaps
Reads data from one or more files in hledger journal, timeclock, time-
dot, or CSV format specified with -f, or $LEDGER_FILE, or
$HOME/.hledger.journal (on windows, perhaps
C:/Users/USER/.hledger.journal).
BUGS
The need to precede options with -- when invoked from hledger is awk-
The need to precede options with -- when invoked from hledger is awk-
ward.
-f- doesn't work (hledger-ui can't read from stdin).
@ -302,14 +302,14 @@ BUGS
which may cause a noticeable pause. Also there is no visual indication
that this is in progress.
The register screen's switching between historic balance and running
The register screen's switching between historic balance and running
total based on query arguments may be confusing, and there is no column
heading to indicate which is being displayed.
REPORTING BUGS
Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel
Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel
or hledger mail list)
@ -323,7 +323,7 @@ COPYRIGHT
SEE ALSO
hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1),
hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1),
hledger_csv(5), hledger_journal(5), hledger_timeclock(5), hledger_time-
dot(5), ledger(1)