imp: ui: can click bottom blank area to go back
This commit is contained in:
		
							parent
							
								
									956ee06591
								
							
						
					
					
						commit
						d0c937a41b
					
				| @ -355,6 +355,9 @@ rsHandle ui@UIState{ | |||||||
|         VtyEvent e | e `elem` moveLeftEvents  -> continue $ popScreen ui |         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. |         -- 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 |         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 |         -- enter transaction screen on RIGHT | ||||||
|         VtyEvent e | e `elem` moveRightEvents -> |         VtyEvent e | e `elem` moveRightEvents -> | ||||||
|  | |||||||
| @ -29,6 +29,7 @@ import Hledger.UI.UIState | |||||||
| import Hledger.UI.UIUtils | import Hledger.UI.UIUtils | ||||||
| import Hledger.UI.Editor | import Hledger.UI.Editor | ||||||
| import Hledger.UI.ErrorScreen | import Hledger.UI.ErrorScreen | ||||||
|  | import Brick.Widgets.Edit (editorText, renderEditor) | ||||||
| 
 | 
 | ||||||
| transactionScreen :: Screen | transactionScreen :: Screen | ||||||
| transactionScreen = TransactionScreen{ | transactionScreen = TransactionScreen{ | ||||||
| @ -59,6 +60,22 @@ tsInit _d _reset ui@UIState{aopts=UIOpts{} | |||||||
|         _                           -> (t, nts) |         _                           -> (t, nts) | ||||||
| tsInit _ _ _ = error "init function called with wrong screen type, should not happen"  -- PARTIAL: | 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 -> [Widget Name] | ||||||
| tsDraw UIState{aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}} | tsDraw UIState{aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}} | ||||||
|               ,ajournal=j |               ,ajournal=j | ||||||
| @ -73,24 +90,17 @@ tsDraw UIState{aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec | |||||||
|     -- Minibuffer e -> [minibuffer e, maincontent] |     -- Minibuffer e -> [minibuffer e, maincontent] | ||||||
|     _          -> [maincontent] |     _          -> [maincontent] | ||||||
|   where |   where | ||||||
|     maincontent = Widget Greedy Greedy $ render $ defaultLayout toplabel bottomlabel txn |     maincontent = Widget Greedy Greedy $ render $ defaultLayout toplabel bottomlabel txneditor | ||||||
|       where |       where | ||||||
|         -- as with print, show amounts with all of their decimal places |         -- as with print, show amounts with all of their decimal places | ||||||
|         t = transactionMapPostingAmounts mixedAmountSetFullPrecision t' |         t = transactionMapPostingAmounts mixedAmountSetFullPrecision t' | ||||||
| 
 | 
 | ||||||
|         txn = str |         -- XXX would like to shrink the editor to the size of the entry, | ||||||
|           $ T.unpack . showTransactionOneLineAmounts |         -- so handler can more easily detect clicks below it | ||||||
|           $ maybe id (transactionApplyValuation prices styles periodlast (_rsDay rspec)) (value_ ropts) |         txneditor =  | ||||||
|           $ case cost_ ropts of |           renderEditor (vBox . map txt) False $  | ||||||
|                 Cost   -> transactionToCost styles t |           editorText TransactionEditor Nothing $  | ||||||
|                 NoCost -> t |           showTxn ropts rspec j 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 |  | ||||||
| 
 | 
 | ||||||
|         toplabel = |         toplabel = | ||||||
|           str "Transaction " |           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 :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
| tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransactions=nts} | 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 |                    ,ajournal=j | ||||||
|                    ,aMode=mode |                    ,aMode=mode | ||||||
|                    } |                    } | ||||||
| @ -185,8 +195,11 @@ tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransaction | |||||||
| 
 | 
 | ||||||
|         -- exit screen on LEFT |         -- 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. |         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 |         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 'l') [MCtrl]) -> redraw ui | ||||||
|         VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui |         VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui | ||||||
|  | |||||||
| @ -83,6 +83,7 @@ data Name = | |||||||
|   | AccountsList |   | AccountsList | ||||||
|   | RegisterViewport |   | RegisterViewport | ||||||
|   | RegisterList |   | RegisterList | ||||||
|  |   | TransactionEditor | ||||||
|   deriving (Ord, Show, Eq) |   deriving (Ord, Show, Eq) | ||||||
| 
 | 
 | ||||||
| data AppEvent = | data AppEvent = | ||||||
|  | |||||||
| @ -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 | In most modern terminals, you can navigate through the screens with a | ||||||
| mouse or touchpad: | mouse or touchpad: | ||||||
| 
 | 
 | ||||||
| - Use mouse wheel or trackpad to scroll lists up and down | - Use mouse wheel or trackpad to scroll up and down | ||||||
| - Left click on list items to go deeper (like the `RIGHT` key) | - Click on list items to go deeper | ||||||
| - Left click on the left-most column go back (like the `LEFT` key). | - Click on the left margin (column 0), or the blank area at bottom of screen, to go back. | ||||||
| 
 | 
 | ||||||
| # KEYS | # KEYS | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user