From d0c937a41b9fb6d3be672cf6b552c3666ef30962 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 18 Nov 2021 23:09:52 -1000 Subject: [PATCH] imp: ui: can click bottom blank area to go back --- hledger-ui/Hledger/UI/RegisterScreen.hs | 3 ++ hledger-ui/Hledger/UI/TransactionScreen.hs | 45 ++++++++++++++-------- hledger-ui/Hledger/UI/UITypes.hs | 1 + hledger-ui/hledger-ui.m4.md | 6 +-- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/hledger-ui/Hledger/UI/RegisterScreen.hs b/hledger-ui/Hledger/UI/RegisterScreen.hs index c0b0ee09a..cf6ac5925 100644 --- a/hledger-ui/Hledger/UI/RegisterScreen.hs +++ b/hledger-ui/Hledger/UI/RegisterScreen.hs @@ -355,6 +355,9 @@ rsHandle ui@UIState{ VtyEvent e | e `elem` moveLeftEvents -> continue $ popScreen ui -- or on a click in the app's left margin. This is a VtyEvent since not in a clickable widget. VtyEvent (EvMouseUp x _y (Just BLeft)) | x==0 -> continue $ popScreen ui + -- or on clicking a blank list item. + MouseUp _ (Just BLeft) Location{loc=(_,y)} | clickeddate == "" -> continue $ popScreen ui + where clickeddate = maybe "" rsItemDate $ listElements rsList !? y -- enter transaction screen on RIGHT VtyEvent e | e `elem` moveRightEvents -> diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index 6af71eb49..6f86853e9 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -29,6 +29,7 @@ import Hledger.UI.UIState import Hledger.UI.UIUtils import Hledger.UI.Editor import Hledger.UI.ErrorScreen +import Brick.Widgets.Edit (editorText, renderEditor) transactionScreen :: Screen transactionScreen = TransactionScreen{ @@ -59,6 +60,22 @@ tsInit _d _reset ui@UIState{aopts=UIOpts{} _ -> (t, nts) tsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL: +-- Render a transaction suitably for the transaction screen. +showTxn :: ReportOpts -> ReportSpec -> Journal -> Transaction -> T.Text +showTxn ropts rspec j t = + showTransactionOneLineAmounts + $ maybe id (transactionApplyValuation prices styles periodlast (_rsDay rspec)) (value_ ropts) + $ case cost_ ropts of + Cost -> transactionToCost styles t + NoCost -> t + -- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real + where + prices = journalPriceOracle (infer_prices_ ropts) j + styles = journalCommodityStyles j + periodlast = + fromMaybe (error' "TransactionScreen: expected a non-empty journal") $ -- PARTIAL: shouldn't happen + reportPeriodOrJournalLastDay rspec j + tsDraw :: UIState -> [Widget Name] tsDraw UIState{aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}} ,ajournal=j @@ -73,24 +90,17 @@ tsDraw UIState{aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec -- Minibuffer e -> [minibuffer e, maincontent] _ -> [maincontent] where - maincontent = Widget Greedy Greedy $ render $ defaultLayout toplabel bottomlabel txn + maincontent = Widget Greedy Greedy $ render $ defaultLayout toplabel bottomlabel txneditor where -- as with print, show amounts with all of their decimal places t = transactionMapPostingAmounts mixedAmountSetFullPrecision t' - txn = str - $ T.unpack . showTransactionOneLineAmounts - $ maybe id (transactionApplyValuation prices styles periodlast (_rsDay rspec)) (value_ ropts) - $ case cost_ ropts of - Cost -> transactionToCost styles t - NoCost -> t - -- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real - where - prices = journalPriceOracle (infer_prices_ ropts) j - styles = journalCommodityStyles j - periodlast = - fromMaybe (error' "TransactionScreen: expected a non-empty journal") $ -- PARTIAL: shouldn't happen - reportPeriodOrJournalLastDay rspec j + -- XXX would like to shrink the editor to the size of the entry, + -- so handler can more easily detect clicks below it + txneditor = + renderEditor (vBox . map txt) False $ + editorText TransactionEditor Nothing $ + showTxn ropts rspec j t toplabel = str "Transaction " @@ -134,7 +144,7 @@ tsDraw _ = error "draw function called with wrong screen type, should not happen tsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransactions=nts} - ,aopts=UIOpts{uoCliOpts=copts} + ,aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}} ,ajournal=j ,aMode=mode } @@ -185,8 +195,11 @@ tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransaction -- exit screen on LEFT VtyEvent e | e `elem` moveLeftEvents -> continue . popScreen $ tsSelect i t ui -- Probably not necessary to tsSelect here, but it's safe. - -- or on a click in the app's left margin. This is a VtyEvent since not in a clickable widget. + -- or on a click in the app's left margin. VtyEvent (EvMouseUp x _y (Just BLeft)) | x==0 -> continue . popScreen $ tsSelect i t ui + -- or on clicking the blank area below the transaction. + MouseUp _ (Just BLeft) Location{loc=(_,y)} | y+1 > numentrylines -> continue . popScreen $ tsSelect i t ui + where numentrylines = length (T.lines $ showTxn ropts rspec j t) - 1 VtyEvent (EvKey (KChar 'l') [MCtrl]) -> redraw ui VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui diff --git a/hledger-ui/Hledger/UI/UITypes.hs b/hledger-ui/Hledger/UI/UITypes.hs index afaf3462e..bd790453a 100644 --- a/hledger-ui/Hledger/UI/UITypes.hs +++ b/hledger-ui/Hledger/UI/UITypes.hs @@ -83,6 +83,7 @@ data Name = | AccountsList | RegisterViewport | RegisterList + | TransactionEditor deriving (Ord, Show, Eq) data AppEvent = diff --git a/hledger-ui/hledger-ui.m4.md b/hledger-ui/hledger-ui.m4.md index 0fa0c2754..27f5cb24e 100644 --- a/hledger-ui/hledger-ui.m4.md +++ b/hledger-ui/hledger-ui.m4.md @@ -93,9 +93,9 @@ which should contain one command line option/argument per line. In most modern terminals, you can navigate through the screens with a mouse or touchpad: -- Use mouse wheel or trackpad to scroll lists up and down -- Left click on list items to go deeper (like the `RIGHT` key) -- Left click on the left-most column go back (like the `LEFT` key). +- Use mouse wheel or trackpad to scroll up and down +- Click on list items to go deeper +- Click on the left margin (column 0), or the blank area at bottom of screen, to go back. # KEYS