ui: briefer on-screen help, and a more detailed help dialog
This commit is contained in:
parent
aa75cc69f6
commit
ea180f72a0
@ -23,6 +23,7 @@ import System.FilePath (takeFileName)
|
|||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import Graphics.Vty as Vty
|
import Graphics.Vty as Vty
|
||||||
import Brick
|
import Brick
|
||||||
|
-- import Brick.Widgets.Center
|
||||||
import Brick.Widgets.List
|
import Brick.Widgets.List
|
||||||
import Brick.Widgets.Edit
|
import Brick.Widgets.Edit
|
||||||
import Brick.Widgets.Border (borderAttr)
|
import Brick.Widgets.Border (borderAttr)
|
||||||
@ -108,7 +109,10 @@ asDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
,aScreen=s@AccountsScreen{}
|
,aScreen=s@AccountsScreen{}
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
} =
|
} =
|
||||||
[ui]
|
case mode of
|
||||||
|
Help -> [helpDialog, maincontent]
|
||||||
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
|
_ -> [maincontent]
|
||||||
where
|
where
|
||||||
toplabel = files
|
toplabel = files
|
||||||
<+> nonzero
|
<+> nonzero
|
||||||
@ -143,29 +147,7 @@ asDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
Nothing -> "-"
|
Nothing -> "-"
|
||||||
Just i -> show (i + 1))
|
Just i -> show (i + 1))
|
||||||
total = str $ show $ V.length $ s ^. asList . listElementsL
|
total = str $ show $ V.length $ s ^. asList . listElementsL
|
||||||
|
maincontent = Widget Greedy Greedy $ do
|
||||||
bottomlabel = borderKeysStr [
|
|
||||||
-- ("up/down/pgup/pgdown/home/end", "move")
|
|
||||||
("a", "add")
|
|
||||||
,("-=1234567890", "depth")
|
|
||||||
,("F", "flat?")
|
|
||||||
,("E", "nonzero?")
|
|
||||||
,("C", "cleared?")
|
|
||||||
,("U", "uncleared?")
|
|
||||||
,("R", "real?")
|
|
||||||
,("/", "filter")
|
|
||||||
,("DEL", "unfilter")
|
|
||||||
,("right/enter", "register")
|
|
||||||
,("ESC", "cancel/top")
|
|
||||||
,("g", "reload")
|
|
||||||
,("q", "quit")
|
|
||||||
]
|
|
||||||
|
|
||||||
bottomarea = case mode of
|
|
||||||
Minibuffer ed -> minibuffer ed
|
|
||||||
_ -> bottomlabel
|
|
||||||
|
|
||||||
ui = Widget Greedy Greedy $ do
|
|
||||||
c <- getContext
|
c <- getContext
|
||||||
let
|
let
|
||||||
availwidth =
|
availwidth =
|
||||||
@ -200,7 +182,24 @@ asDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
|
|
||||||
colwidths = (acctwidth, balwidth)
|
colwidths = (acctwidth, balwidth)
|
||||||
|
|
||||||
render $ defaultLayout toplabel bottomarea $ renderList (s ^. asList) (asDrawItem colwidths)
|
render $ defaultLayout toplabel bottomlabel $ renderList (s ^. asList) (asDrawItem colwidths)
|
||||||
|
|
||||||
|
where
|
||||||
|
bottomlabel = case mode of
|
||||||
|
Minibuffer ed -> minibuffer ed
|
||||||
|
_ -> quickhelp
|
||||||
|
quickhelp = borderKeysStr [
|
||||||
|
("h", "help")
|
||||||
|
,("right", "register")
|
||||||
|
,("F", "flat?")
|
||||||
|
,("-+=1234567890", "depth")
|
||||||
|
--,("/", "filter")
|
||||||
|
--,("DEL", "unfilter")
|
||||||
|
--,("ESC", "cancel/top")
|
||||||
|
,("a", "add")
|
||||||
|
,("g", "reload")
|
||||||
|
,("q", "quit")
|
||||||
|
]
|
||||||
|
|
||||||
asDraw _ = error "draw function called with wrong screen type, should not happen"
|
asDraw _ = error "draw function called with wrong screen type, should not happen"
|
||||||
|
|
||||||
@ -253,18 +252,23 @@ asHandle st'@AppState{
|
|||||||
case mode of
|
case mode of
|
||||||
Minibuffer ed ->
|
Minibuffer ed ->
|
||||||
case ev of
|
case ev of
|
||||||
Vty.EvKey Vty.KEsc [] -> continue $ stHideMinibuffer st'
|
Vty.EvKey Vty.KEsc [] -> continue $ stCloseMinibuffer st'
|
||||||
Vty.EvKey Vty.KEnter [] -> continue $ regenerateScreens j d $ stFilter s $ stHideMinibuffer st'
|
Vty.EvKey Vty.KEnter [] -> continue $ regenerateScreens j d $ stFilter s $ stCloseMinibuffer st'
|
||||||
where s = chomp $ unlines $ getEditContents ed
|
where s = chomp $ unlines $ getEditContents ed
|
||||||
ev -> do ed' <- handleEvent ev ed
|
ev -> do ed' <- handleEvent ev ed
|
||||||
continue $ st'{aMode=Minibuffer ed'}
|
continue $ st'{aMode=Minibuffer ed'}
|
||||||
|
|
||||||
_ ->
|
Help ->
|
||||||
|
case ev of
|
||||||
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
|
_ -> helpHandle st ev
|
||||||
|
|
||||||
|
Normal ->
|
||||||
case ev of
|
case ev of
|
||||||
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
-- Vty.EvKey (Vty.KChar 'l') [Vty.MCtrl] -> do
|
-- Vty.EvKey (Vty.KChar 'l') [Vty.MCtrl] -> do
|
||||||
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
||||||
|
Vty.EvKey k [] | k `elem` [Vty.KChar 'h', Vty.KChar '?'] -> continue $ setMode Help st
|
||||||
Vty.EvKey (Vty.KChar 'g') [] -> liftIO (stReloadJournalIfChanged copts d j st) >>= continue
|
Vty.EvKey (Vty.KChar 'g') [] -> liftIO (stReloadJournalIfChanged copts d j st) >>= continue
|
||||||
Vty.EvKey (Vty.KChar 'a') [] -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add copts j >> stReloadJournalIfChanged copts d j st
|
Vty.EvKey (Vty.KChar 'a') [] -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add copts j >> stReloadJournalIfChanged copts d j st
|
||||||
Vty.EvKey (Vty.KChar '-') [] -> continue $ regenerateScreens j d $ decDepth st
|
Vty.EvKey (Vty.KChar '-') [] -> continue $ regenerateScreens j d $ decDepth st
|
||||||
|
|||||||
@ -42,75 +42,48 @@ esInit _ _ _ = error "init function called with wrong screen type, should not ha
|
|||||||
|
|
||||||
esDraw :: AppState -> [Widget]
|
esDraw :: AppState -> [Widget]
|
||||||
esDraw AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{reportopts_=_ropts@ReportOpts{query_=querystr}}},
|
esDraw AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{reportopts_=_ropts@ReportOpts{query_=querystr}}},
|
||||||
aScreen=ErrorScreen{..}} = [ui]
|
aScreen=ErrorScreen{..}
|
||||||
|
,aMode=mode} =
|
||||||
|
case mode of
|
||||||
|
Help -> [helpDialog, maincontent]
|
||||||
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
|
_ -> [maincontent]
|
||||||
where
|
where
|
||||||
toplabel = withAttr ("border" <> "bold") (str "Oops. Please fix this problem then press g to reload")
|
toplabel = withAttr ("border" <> "bold") (str "Oops. Please fix this problem then press g to reload")
|
||||||
-- <+> str " transactions"
|
maincontent = Widget Greedy Greedy $ do
|
||||||
-- <+> borderQueryStr querystr -- no, account transactions report shows all transactions in the acct ?
|
render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError
|
||||||
-- <+> str " and subs"
|
where
|
||||||
-- <+> str " ("
|
bottomlabel = case mode of
|
||||||
-- <+> cur
|
-- Minibuffer ed -> minibuffer ed
|
||||||
-- <+> str "/"
|
_ -> quickhelp
|
||||||
-- <+> total
|
quickhelp = borderKeysStr [
|
||||||
-- <+> str ")"
|
("h", "help")
|
||||||
-- cur = str $ case l^.listSelectedL of
|
,("ESC", "cancel/top")
|
||||||
-- Nothing -> "-"
|
,("g", "reload")
|
||||||
-- Just i -> show (i + 1)
|
,("q", "quit")
|
||||||
-- total = str $ show $ length displayitems
|
|
||||||
-- displayitems = V.toList $ l^.listElementsL
|
|
||||||
bottomlabel = borderKeysStr [
|
|
||||||
-- ("up/down/pgup/pgdown/home/end", "move")
|
|
||||||
("g", "reload")
|
|
||||||
-- ,("left", "return to accounts")
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
-- query = query_ $ reportopts_ $ cliopts_ opts
|
|
||||||
|
|
||||||
ui = Widget Greedy Greedy $ do
|
|
||||||
|
|
||||||
-- calculate column widths, based on current available width
|
|
||||||
-- c <- getContext
|
|
||||||
-- let
|
|
||||||
-- totalwidth = c^.availWidthL
|
|
||||||
-- - 2 -- XXX due to margin ? shouldn't be necessary (cf UIUtils)
|
|
||||||
|
|
||||||
render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError
|
|
||||||
|
|
||||||
esDraw _ = error "draw function called with wrong screen type, should not happen"
|
esDraw _ = error "draw function called with wrong screen type, should not happen"
|
||||||
|
|
||||||
-- drawErrorItem :: (Int,Int,Int,Int,Int) -> Bool -> (String,String,String,String,String) -> Widget
|
|
||||||
-- drawErrorItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected (date,desc,accts,change,bal) =
|
|
||||||
-- Widget Greedy Fixed $ do
|
|
||||||
-- render $
|
|
||||||
-- str (fitString (Just datewidth) (Just datewidth) True True date) <+>
|
|
||||||
-- str " " <+>
|
|
||||||
-- str (fitString (Just descwidth) (Just descwidth) True True desc) <+>
|
|
||||||
-- str " " <+>
|
|
||||||
-- str (fitString (Just acctswidth) (Just acctswidth) True True accts) <+>
|
|
||||||
-- str " " <+>
|
|
||||||
-- withAttr changeattr (str (fitString (Just changewidth) (Just changewidth) True False change)) <+>
|
|
||||||
-- str " " <+>
|
|
||||||
-- withAttr balattr (str (fitString (Just balwidth) (Just balwidth) True False bal))
|
|
||||||
-- where
|
|
||||||
-- changeattr | '-' `elem` change = sel $ "list" <> "amount" <> "decrease"
|
|
||||||
-- | otherwise = sel $ "list" <> "amount" <> "increase"
|
|
||||||
-- balattr | '-' `elem` bal = sel $ "list" <> "balance" <> "negative"
|
|
||||||
-- | otherwise = sel $ "list" <> "balance" <> "positive"
|
|
||||||
-- sel | selected = (<> "selected")
|
|
||||||
-- | otherwise = id
|
|
||||||
|
|
||||||
esHandle :: AppState -> Vty.Event -> EventM (Next AppState)
|
esHandle :: AppState -> Vty.Event -> EventM (Next AppState)
|
||||||
esHandle st@AppState{
|
esHandle st@AppState{
|
||||||
aScreen=s@ErrorScreen{}
|
aScreen=s@ErrorScreen{}
|
||||||
,aopts=UIOpts{cliopts_=copts}
|
,aopts=UIOpts{cliopts_=copts}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
} e = do
|
,aMode=mode
|
||||||
|
} ev =
|
||||||
|
case mode of
|
||||||
|
Help ->
|
||||||
|
case ev of
|
||||||
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
|
_ -> helpHandle st ev
|
||||||
|
|
||||||
|
_ -> do
|
||||||
d <- liftIO getCurrentDay
|
d <- liftIO getCurrentDay
|
||||||
case e of
|
case ev of
|
||||||
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
||||||
|
Vty.EvKey k [] | k `elem` [Vty.KChar 'h', Vty.KChar '?'] -> continue $ setMode Help st
|
||||||
Vty.EvKey (Vty.KChar 'g') [] -> do
|
Vty.EvKey (Vty.KChar 'g') [] -> do
|
||||||
(ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
(ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
||||||
case ej of
|
case ej of
|
||||||
|
|||||||
@ -103,8 +103,11 @@ rsDraw :: AppState -> [Widget]
|
|||||||
rsDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
rsDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
||||||
,aScreen=RegisterScreen{..}
|
,aScreen=RegisterScreen{..}
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
}
|
} =
|
||||||
= [ui]
|
case mode of
|
||||||
|
Help -> [helpDialog, maincontent]
|
||||||
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
|
_ -> [maincontent]
|
||||||
where
|
where
|
||||||
toplabel = withAttr ("border" <> "bold") (str $ T.unpack rsAccount)
|
toplabel = withAttr ("border" <> "bold") (str $ T.unpack rsAccount)
|
||||||
<+> togglefilters
|
<+> togglefilters
|
||||||
@ -134,17 +137,14 @@ rsDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
|
|
||||||
-- query = query_ $ reportopts_ $ cliopts_ opts
|
-- query = query_ $ reportopts_ $ cliopts_ opts
|
||||||
|
|
||||||
ui = Widget Greedy Greedy $ do
|
maincontent = Widget Greedy Greedy $ do
|
||||||
|
|
||||||
-- calculate column widths, based on current available width
|
-- calculate column widths, based on current available width
|
||||||
c <- getContext
|
c <- getContext
|
||||||
let
|
let
|
||||||
totalwidth = c^.availWidthL
|
totalwidth = c^.availWidthL
|
||||||
- 2 -- XXX due to margin ? shouldn't be necessary (cf UIUtils)
|
- 2 -- XXX due to margin ? shouldn't be necessary (cf UIUtils)
|
||||||
|
|
||||||
-- the date column is fixed width
|
-- the date column is fixed width
|
||||||
datewidth = 10
|
datewidth = 10
|
||||||
|
|
||||||
-- multi-commodity amounts rendered on one line can be
|
-- multi-commodity amounts rendered on one line can be
|
||||||
-- arbitrarily wide. Give the two amounts as much space as
|
-- arbitrarily wide. Give the two amounts as much space as
|
||||||
-- they need, while reserving a minimum of space for other
|
-- they need, while reserving a minimum of space for other
|
||||||
@ -160,7 +160,6 @@ rsDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
maxbalwidth = maxamtswidth - maxchangewidth
|
maxbalwidth = maxamtswidth - maxchangewidth
|
||||||
changewidth = min maxchangewidth maxchangewidthseen
|
changewidth = min maxchangewidth maxchangewidthseen
|
||||||
balwidth = min maxbalwidth maxbalwidthseen
|
balwidth = min maxbalwidth maxbalwidthseen
|
||||||
|
|
||||||
-- assign the remaining space to the description and accounts columns
|
-- assign the remaining space to the description and accounts columns
|
||||||
-- maxdescacctswidth = totalwidth - (whitespacewidth - 4) - changewidth - balwidth
|
-- maxdescacctswidth = totalwidth - (whitespacewidth - 4) - changewidth - balwidth
|
||||||
maxdescacctswidth =
|
maxdescacctswidth =
|
||||||
@ -179,28 +178,24 @@ rsDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
acctswidth = maxdescacctswidth - descwidth
|
acctswidth = maxdescacctswidth - descwidth
|
||||||
colwidths = (datewidth,descwidth,acctswidth,changewidth,balwidth)
|
colwidths = (datewidth,descwidth,acctswidth,changewidth,balwidth)
|
||||||
|
|
||||||
bottomlabel = borderKeysStr [
|
render $ defaultLayout toplabel bottomlabel $ renderList rsList (rsDrawItem colwidths)
|
||||||
-- ("up/down/pgup/pgdown/home/end", "move")
|
|
||||||
("left", "back")
|
where
|
||||||
,("a", "add")
|
bottomlabel = case mode of
|
||||||
,("E", "nonzero?")
|
Minibuffer ed -> minibuffer ed
|
||||||
,("C", "cleared?")
|
_ -> quickhelp
|
||||||
,("U", "uncleared?")
|
quickhelp = borderKeysStr [
|
||||||
,("R", "real?")
|
("h", "help")
|
||||||
|
,("left", "back")
|
||||||
|
,("right", "transaction")
|
||||||
,("/", "filter")
|
,("/", "filter")
|
||||||
,("DEL", "unfilter")
|
,("DEL", "unfilter")
|
||||||
,("right/enter", "transaction")
|
--,("ESC", "reset")
|
||||||
,("ESC", "cancel/top")
|
,("a", "add")
|
||||||
,("g", "reload")
|
,("g", "reload")
|
||||||
,("q", "quit")
|
,("q", "quit")
|
||||||
]
|
]
|
||||||
|
|
||||||
bottomarea = case mode of
|
|
||||||
Minibuffer ed -> minibuffer ed
|
|
||||||
_ -> bottomlabel
|
|
||||||
|
|
||||||
render $ defaultLayout toplabel bottomarea $ renderList rsList (rsDrawItem colwidths)
|
|
||||||
|
|
||||||
rsDraw _ = error "draw function called with wrong screen type, should not happen"
|
rsDraw _ = error "draw function called with wrong screen type, should not happen"
|
||||||
|
|
||||||
rsDrawItem :: (Int,Int,Int,Int,Int) -> Bool -> RegisterScreenItem -> Widget
|
rsDrawItem :: (Int,Int,Int,Int,Int) -> Bool -> RegisterScreenItem -> Widget
|
||||||
@ -236,17 +231,22 @@ rsHandle st@AppState{
|
|||||||
case mode of
|
case mode of
|
||||||
Minibuffer ed ->
|
Minibuffer ed ->
|
||||||
case ev of
|
case ev of
|
||||||
Vty.EvKey Vty.KEsc [] -> continue $ stHideMinibuffer st
|
Vty.EvKey Vty.KEsc [] -> continue $ stCloseMinibuffer st
|
||||||
Vty.EvKey Vty.KEnter [] -> continue $ regenerateScreens j d $ stFilter s $ stHideMinibuffer st
|
Vty.EvKey Vty.KEnter [] -> continue $ regenerateScreens j d $ stFilter s $ stCloseMinibuffer st
|
||||||
where s = chomp $ unlines $ getEditContents ed
|
where s = chomp $ unlines $ getEditContents ed
|
||||||
ev -> do ed' <- handleEvent ev ed
|
ev -> do ed' <- handleEvent ev ed
|
||||||
continue $ st{aMode=Minibuffer ed'}
|
continue $ st{aMode=Minibuffer ed'}
|
||||||
|
|
||||||
_ ->
|
Help ->
|
||||||
|
case ev of
|
||||||
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
|
_ -> helpHandle st ev
|
||||||
|
|
||||||
|
Normal ->
|
||||||
case ev of
|
case ev of
|
||||||
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
||||||
|
Vty.EvKey k [] | k `elem` [Vty.KChar 'h', Vty.KChar '?'] -> continue $ setMode Help st
|
||||||
Vty.EvKey (Vty.KChar 'g') [] -> liftIO (stReloadJournalIfChanged copts d j st) >>= continue
|
Vty.EvKey (Vty.KChar 'g') [] -> liftIO (stReloadJournalIfChanged copts d j st) >>= continue
|
||||||
Vty.EvKey (Vty.KChar 'a') [] -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add copts j >> stReloadJournalIfChanged copts d j st
|
Vty.EvKey (Vty.KChar 'a') [] -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add copts j >> stReloadJournalIfChanged copts d j st
|
||||||
Vty.EvKey (Vty.KChar 'E') [] -> scrollTop >> (continue $ regenerateScreens j d $ stToggleEmpty st)
|
Vty.EvKey (Vty.KChar 'E') [] -> scrollTop >> (continue $ regenerateScreens j d $ stToggleEmpty st)
|
||||||
@ -281,4 +281,3 @@ rsHandle st@AppState{
|
|||||||
scrollTop = vScrollToBeginning $ viewportScroll "register"
|
scrollTop = vScrollToBeginning $ viewportScroll "register"
|
||||||
|
|
||||||
rsHandle _ _ = error "event handler called with wrong screen type, should not happen"
|
rsHandle _ _ = error "event handler called with wrong screen type, should not happen"
|
||||||
|
|
||||||
|
|||||||
@ -57,8 +57,12 @@ tsDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
,aScreen=TransactionScreen{
|
,aScreen=TransactionScreen{
|
||||||
tsTransaction=(i,t)
|
tsTransaction=(i,t)
|
||||||
,tsTransactions=nts
|
,tsTransactions=nts
|
||||||
,tsAccount=acct}} =
|
,tsAccount=acct}
|
||||||
[ui]
|
,aMode=mode} =
|
||||||
|
case mode of
|
||||||
|
Help -> [helpDialog, maincontent]
|
||||||
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
|
_ -> [maincontent]
|
||||||
where
|
where
|
||||||
-- datedesc = show (tdate t) ++ " " ++ tdescription t
|
-- datedesc = show (tdate t) ++ " " ++ tdescription t
|
||||||
toplabel =
|
toplabel =
|
||||||
@ -82,40 +86,51 @@ tsDraw AppState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}
|
|||||||
] of
|
] of
|
||||||
[] -> str ""
|
[] -> str ""
|
||||||
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
|
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
|
||||||
bottomlabel = borderKeysStr [
|
maincontent = Widget Greedy Greedy $ do
|
||||||
("left", "back")
|
|
||||||
,("up/down", "prev/next")
|
|
||||||
-- ,("C", "cleared?")
|
|
||||||
-- ,("U", "uncleared?")
|
|
||||||
-- ,("R", "real?")
|
|
||||||
,("g", "reload")
|
|
||||||
,("q", "quit")
|
|
||||||
]
|
|
||||||
ui = Widget Greedy Greedy $ do
|
|
||||||
render $ defaultLayout toplabel bottomlabel $ str $
|
render $ defaultLayout toplabel bottomlabel $ str $
|
||||||
showTransactionUnelidedOneLineAmounts $
|
showTransactionUnelidedOneLineAmounts $
|
||||||
-- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real
|
-- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real
|
||||||
t
|
t
|
||||||
|
where
|
||||||
|
bottomlabel = case mode of
|
||||||
|
-- Minibuffer ed -> minibuffer ed
|
||||||
|
_ -> quickhelp
|
||||||
|
quickhelp = borderKeysStr [
|
||||||
|
("h", "help")
|
||||||
|
,("left", "back")
|
||||||
|
,("up/down", "prev/next")
|
||||||
|
--,("ESC", "cancel/top")
|
||||||
|
-- ,("a", "add")
|
||||||
|
,("g", "reload")
|
||||||
|
,("q", "quit")
|
||||||
|
]
|
||||||
|
|
||||||
tsDraw _ = error "draw function called with wrong screen type, should not happen"
|
tsDraw _ = error "draw function called with wrong screen type, should not happen"
|
||||||
|
|
||||||
tsHandle :: AppState -> Vty.Event -> EventM (Next AppState)
|
tsHandle :: AppState -> Vty.Event -> EventM (Next AppState)
|
||||||
tsHandle
|
tsHandle st@AppState{aScreen=s@TransactionScreen{tsTransaction=(i,t)
|
||||||
st@AppState{aScreen=s@TransactionScreen{tsTransaction=(i,t)
|
|
||||||
,tsTransactions=nts
|
,tsTransactions=nts
|
||||||
,tsAccount=acct}
|
,tsAccount=acct}
|
||||||
,aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
,aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
|
,aMode=mode
|
||||||
}
|
}
|
||||||
e = do
|
ev =
|
||||||
|
case mode of
|
||||||
|
Help ->
|
||||||
|
case ev of
|
||||||
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
|
_ -> helpHandle st ev
|
||||||
|
|
||||||
|
_ -> do
|
||||||
d <- liftIO getCurrentDay
|
d <- liftIO getCurrentDay
|
||||||
let
|
let
|
||||||
(iprev,tprev) = maybe (i,t) ((i-1),) $ lookup (i-1) nts
|
(iprev,tprev) = maybe (i,t) ((i-1),) $ lookup (i-1) nts
|
||||||
(inext,tnext) = maybe (i,t) ((i+1),) $ lookup (i+1) nts
|
(inext,tnext) = maybe (i,t) ((i+1),) $ lookup (i+1) nts
|
||||||
case e of
|
case ev of
|
||||||
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||||
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
Vty.EvKey Vty.KEsc [] -> continue $ resetScreens d st
|
||||||
|
Vty.EvKey k [] | k `elem` [Vty.KChar 'h', Vty.KChar '?'] -> continue $ setMode Help st
|
||||||
Vty.EvKey (Vty.KChar 'g') [] -> do
|
Vty.EvKey (Vty.KChar 'g') [] -> do
|
||||||
d <- liftIO getCurrentDay
|
d <- liftIO getCurrentDay
|
||||||
(ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
(ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
||||||
|
|||||||
@ -73,7 +73,11 @@ data Mode =
|
|||||||
Normal
|
Normal
|
||||||
| Help
|
| Help
|
||||||
| Minibuffer Editor
|
| Minibuffer Editor
|
||||||
deriving (Show)
|
deriving (Show,Eq)
|
||||||
|
|
||||||
|
-- Ignore the editor when comparing Modes.
|
||||||
|
instance Eq Editor where _ == _ = True
|
||||||
|
|
||||||
|
|
||||||
-- | hledger-ui screen types & instances.
|
-- | hledger-ui screen types & instances.
|
||||||
-- Each screen type has generically named initialisation, draw, and event handling functions,
|
-- Each screen type has generically named initialisation, draw, and event handling functions,
|
||||||
|
|||||||
@ -28,7 +28,7 @@ module Hledger.UI.UIUtils
|
|||||||
-- ,stFilter
|
-- ,stFilter
|
||||||
-- ,stResetFilter
|
-- ,stResetFilter
|
||||||
-- ,stShowMinibuffer
|
-- ,stShowMinibuffer
|
||||||
-- ,stHideMinibuffer
|
-- ,stCloseMinibuffer
|
||||||
-- )
|
-- )
|
||||||
where
|
where
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ import Data.Monoid
|
|||||||
import Data.Text.Zipper (gotoEOL)
|
import Data.Text.Zipper (gotoEOL)
|
||||||
import Data.Time.Calendar (Day)
|
import Data.Time.Calendar (Day)
|
||||||
import Brick
|
import Brick
|
||||||
|
import Brick.Widgets.Dialog
|
||||||
-- import Brick.Widgets.List
|
-- import Brick.Widgets.List
|
||||||
import Brick.Widgets.Edit
|
import Brick.Widgets.Edit
|
||||||
import Brick.Widgets.Border
|
import Brick.Widgets.Border
|
||||||
@ -153,14 +154,17 @@ setDepth depth st@AppState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_
|
|||||||
| depth >= maxDepth st = Nothing
|
| depth >= maxDepth st = Nothing
|
||||||
| otherwise = Just depth
|
| otherwise = Just depth
|
||||||
|
|
||||||
-- | Enable the minibuffer, setting its content to the current query with the cursor at the end.
|
-- | Open the minibuffer, setting its content to the current query with the cursor at the end.
|
||||||
stShowMinibuffer st = st{aMode=Minibuffer e}
|
stShowMinibuffer st = setMode (Minibuffer e) st
|
||||||
where
|
where
|
||||||
e = applyEdit gotoEOL $ editor "minibuffer" (str . unlines) (Just 1) oldq
|
e = applyEdit gotoEOL $ editor "minibuffer" (str . unlines) (Just 1) oldq
|
||||||
oldq = query_ $ reportopts_ $ cliopts_ $ aopts st
|
oldq = query_ $ reportopts_ $ cliopts_ $ aopts st
|
||||||
|
|
||||||
-- | Disable the minibuffer, discarding any edit in progress.
|
-- | Close the minibuffer, discarding any edit in progress.
|
||||||
stHideMinibuffer st = st{aMode=Normal}
|
stCloseMinibuffer = setMode Normal
|
||||||
|
|
||||||
|
setMode :: Mode -> AppState -> AppState
|
||||||
|
setMode m st = st{aMode=m}
|
||||||
|
|
||||||
-- | Regenerate the content for the current and previous screens, from a new journal and current date.
|
-- | Regenerate the content for the current and previous screens, from a new journal and current date.
|
||||||
regenerateScreens :: Journal -> Day -> AppState -> AppState
|
regenerateScreens :: Journal -> Day -> AppState -> AppState
|
||||||
@ -188,7 +192,7 @@ popScreen st = st
|
|||||||
|
|
||||||
resetScreens :: Day -> AppState -> AppState
|
resetScreens :: Day -> AppState -> AppState
|
||||||
resetScreens d st@AppState{aScreen=s,aPrevScreens=ss} =
|
resetScreens d st@AppState{aScreen=s,aPrevScreens=ss} =
|
||||||
(sInit topscreen) d True $ stResetDepth $ stResetFilter $ stHideMinibuffer st{aScreen=topscreen, aPrevScreens=[]}
|
(sInit topscreen) d True $ stResetDepth $ stResetFilter $ stCloseMinibuffer st{aScreen=topscreen, aPrevScreens=[]}
|
||||||
where
|
where
|
||||||
topscreen = case ss of _:_ -> last ss
|
topscreen = case ss of _:_ -> last ss
|
||||||
[] -> s
|
[] -> s
|
||||||
@ -203,6 +207,56 @@ screenEnter d scr st = (sInit scr) d True $
|
|||||||
pushScreen scr
|
pushScreen scr
|
||||||
st
|
st
|
||||||
|
|
||||||
|
-- | Draw the help dialog, called when help mode is active.
|
||||||
|
helpDialog =
|
||||||
|
Widget Fixed Fixed $ do
|
||||||
|
c <- getContext
|
||||||
|
render $
|
||||||
|
renderDialog (dialog "help" (Just "Help (h/ESC to close)") Nothing (c^.availWidthL - 2)) $ -- (Just (0,[("ok",())]))
|
||||||
|
padTopBottom 1 $ padLeftRight 1 $
|
||||||
|
hBox [
|
||||||
|
(padLeftRight 1 $
|
||||||
|
vBox [
|
||||||
|
str "MISC"
|
||||||
|
,renderKey ("h", "toggle help")
|
||||||
|
,renderKey ("a", "add transaction")
|
||||||
|
,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 to top")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
,(padLeftRight 1 $
|
||||||
|
vBox [
|
||||||
|
str "FILTERING"
|
||||||
|
,renderKey ("C", "toggle cleared filter")
|
||||||
|
,renderKey ("U", "toggle uncleared filter")
|
||||||
|
,renderKey ("R", "toggle real filter")
|
||||||
|
,renderKey ("E", "toggle nonzero filter")
|
||||||
|
,renderKey ("/", "set a filter query")
|
||||||
|
,renderKey ("DEL/BS", "clear filters")
|
||||||
|
,str "accounts screen:"
|
||||||
|
,renderKey ("F", "toggle flat mode")
|
||||||
|
,renderKey ("-+=1234567890", "")
|
||||||
|
,str " adjust/set depth limit"
|
||||||
|
,str " 0 means no limit"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
where
|
||||||
|
renderKey (key,desc) = withAttr (borderAttr <> "keys") (str key) <+> str " " <+> str desc
|
||||||
|
|
||||||
|
-- | Event handler used when help mode is active.
|
||||||
|
helpHandle st ev =
|
||||||
|
case ev of
|
||||||
|
Vty.EvKey k [] | k `elem` [Vty.KEsc, Vty.KChar 'h'] -> continue $ setMode Normal st
|
||||||
|
_ -> continue st
|
||||||
|
|
||||||
-- | In the EventM monad, get the named current viewport's width and height,
|
-- | In the EventM monad, get the named current viewport's width and height,
|
||||||
-- or (0,0) if the named viewport is not found.
|
-- or (0,0) if the named viewport is not found.
|
||||||
getViewportSize :: Name -> EventM (Int,Int)
|
getViewportSize :: Name -> EventM (Int,Int)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user