ui: use a custom application event type
This commit is contained in:
		
							parent
							
								
									015b9570d4
								
							
						
					
					
						commit
						0f1108db07
					
				| @ -247,7 +247,7 @@ asDrawItem (acctwidth, balwidth) selected AccountsScreenItem{..} = | |||||||
|         sel | selected  = (<> "selected") |         sel | selected  = (<> "selected") | ||||||
|             | otherwise = id |             | otherwise = id | ||||||
| 
 | 
 | ||||||
| asHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) | asHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
| asHandle ui0@UIState{ | asHandle ui0@UIState{ | ||||||
|    aScreen=scr@AccountsScreen{..} |    aScreen=scr@AccountsScreen{..} | ||||||
|   ,aopts=UIOpts{cliopts_=copts} |   ,aopts=UIOpts{cliopts_=copts} | ||||||
|  | |||||||
| @ -68,7 +68,7 @@ esDraw UIState{ --aopts=UIOpts{cliopts_=copts@CliOpts{}} | |||||||
| 
 | 
 | ||||||
| esDraw _ = error "draw function called with wrong screen type, should not happen" | esDraw _ = error "draw function called with wrong screen type, should not happen" | ||||||
| 
 | 
 | ||||||
| esHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) | esHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
| esHandle ui@UIState{ | esHandle ui@UIState{ | ||||||
|    aScreen=ErrorScreen{..} |    aScreen=ErrorScreen{..} | ||||||
|   ,aopts=UIOpts{cliopts_=copts} |   ,aopts=UIOpts{cliopts_=copts} | ||||||
|  | |||||||
| @ -23,7 +23,6 @@ import qualified Data.Text as T | |||||||
| import Safe | import Safe | ||||||
| import System.Exit | import System.Exit | ||||||
| 
 | 
 | ||||||
| import qualified Graphics.Vty as V |  | ||||||
| import Brick | import Brick | ||||||
| 
 | 
 | ||||||
| import Hledger | import Hledger | ||||||
| @ -135,7 +134,7 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do | |||||||
|            ,aMode=Normal |            ,aMode=Normal | ||||||
|            } |            } | ||||||
| 
 | 
 | ||||||
|     brickapp :: App (UIState) V.Event Name |     brickapp :: App (UIState) AppEvent Name | ||||||
|     brickapp = App { |     brickapp = App { | ||||||
|         appStartEvent   = return |         appStartEvent   = return | ||||||
|       , appAttrMap      = const theme |       , appAttrMap      = const theme | ||||||
|  | |||||||
| @ -236,7 +236,7 @@ rsDrawItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected Regist | |||||||
|     sel | selected  = (<> "selected") |     sel | selected  = (<> "selected") | ||||||
|         | otherwise = id |         | otherwise = id | ||||||
| 
 | 
 | ||||||
| rsHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) | rsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
| rsHandle ui@UIState{ | rsHandle ui@UIState{ | ||||||
|    aScreen=s@RegisterScreen{..} |    aScreen=s@RegisterScreen{..} | ||||||
|   ,aopts=UIOpts{cliopts_=copts} |   ,aopts=UIOpts{cliopts_=copts} | ||||||
|  | |||||||
| @ -102,7 +102,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} | |||||||
| 
 | 
 | ||||||
| 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 :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) | tsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
| tsHandle ui@UIState{aScreen=s@TransactionScreen{tsTransaction=(i,t) | tsHandle ui@UIState{aScreen=s@TransactionScreen{tsTransaction=(i,t) | ||||||
|                                                 ,tsTransactions=nts |                                                 ,tsTransactions=nts | ||||||
|                                                 ,tsAccount=acct} |                                                 ,tsAccount=acct} | ||||||
|  | |||||||
| @ -39,7 +39,6 @@ Brick.defaultMain brickapp st | |||||||
| module Hledger.UI.UITypes where | module Hledger.UI.UITypes where | ||||||
| 
 | 
 | ||||||
| import Data.Time.Calendar (Day) | import Data.Time.Calendar (Day) | ||||||
| import Graphics.Vty (Event) |  | ||||||
| import Brick | import Brick | ||||||
| import Brick.Widgets.List | import Brick.Widgets.List | ||||||
| import Brick.Widgets.Edit (Editor) | import Brick.Widgets.Edit (Editor) | ||||||
| @ -83,6 +82,8 @@ data Name = | |||||||
|   | RegisterList |   | RegisterList | ||||||
|   deriving (Ord, Show, Eq) |   deriving (Ord, Show, Eq) | ||||||
| 
 | 
 | ||||||
|  | data AppEvent = DummyEvent | ||||||
|  | 
 | ||||||
| -- | 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, | ||||||
| -- and zero or more uniquely named screen state fields, which hold the data for a particular | -- and zero or more uniquely named screen state fields, which hold the data for a particular | ||||||
| @ -92,7 +93,7 @@ data Screen = | |||||||
|     AccountsScreen { |     AccountsScreen { | ||||||
|        sInit   :: Day -> Bool -> UIState -> UIState              -- ^ function to initialise or update this screen's state |        sInit   :: Day -> Bool -> UIState -> UIState              -- ^ function to initialise or update this screen's state | ||||||
|       ,sDraw   :: UIState -> [Widget Name]                             -- ^ brick renderer for this screen |       ,sDraw   :: UIState -> [Widget Name]                             -- ^ brick renderer for this screen | ||||||
|       ,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState)  -- ^ brick event handler for this screen |       ,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)  -- ^ brick event handler for this screen | ||||||
|       -- state fields.These ones have lenses: |       -- state fields.These ones have lenses: | ||||||
|       ,_asList            :: List Name AccountsScreenItem  -- ^ list widget showing account names & balances |       ,_asList            :: List Name AccountsScreenItem  -- ^ list widget showing account names & balances | ||||||
|       ,_asSelectedAccount :: AccountName              -- ^ a backup of the account name from the list widget's selected item (or "") |       ,_asSelectedAccount :: AccountName              -- ^ a backup of the account name from the list widget's selected item (or "") | ||||||
| @ -100,7 +101,7 @@ data Screen = | |||||||
|   | RegisterScreen { |   | RegisterScreen { | ||||||
|        sInit   :: Day -> Bool -> UIState -> UIState |        sInit   :: Day -> Bool -> UIState -> UIState | ||||||
|       ,sDraw   :: UIState -> [Widget Name] |       ,sDraw   :: UIState -> [Widget Name] | ||||||
|       ,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) |       ,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
|       -- |       -- | ||||||
|       ,rsList    :: List Name RegisterScreenItem      -- ^ list widget showing transactions affecting this account |       ,rsList    :: List Name RegisterScreenItem      -- ^ list widget showing transactions affecting this account | ||||||
|       ,rsAccount :: AccountName                       -- ^ the account this register is for |       ,rsAccount :: AccountName                       -- ^ the account this register is for | ||||||
| @ -111,7 +112,7 @@ data Screen = | |||||||
|   | TransactionScreen { |   | TransactionScreen { | ||||||
|        sInit   :: Day -> Bool -> UIState -> UIState |        sInit   :: Day -> Bool -> UIState -> UIState | ||||||
|       ,sDraw   :: UIState -> [Widget Name] |       ,sDraw   :: UIState -> [Widget Name] | ||||||
|       ,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) |       ,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
|       -- |       -- | ||||||
|       ,tsTransaction  :: NumberedTransaction          -- ^ the transaction we are currently viewing, and its position in the list |       ,tsTransaction  :: NumberedTransaction          -- ^ the transaction we are currently viewing, and its position in the list | ||||||
|       ,tsTransactions :: [NumberedTransaction]        -- ^ list of transactions we can step through |       ,tsTransactions :: [NumberedTransaction]        -- ^ list of transactions we can step through | ||||||
| @ -120,7 +121,7 @@ data Screen = | |||||||
|   | ErrorScreen { |   | ErrorScreen { | ||||||
|        sInit   :: Day -> Bool -> UIState -> UIState |        sInit   :: Day -> Bool -> UIState -> UIState | ||||||
|       ,sDraw   :: UIState -> [Widget Name] |       ,sDraw   :: UIState -> [Widget Name] | ||||||
|       ,sHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) |       ,sHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
|       -- |       -- | ||||||
|       ,esError :: String                              -- ^ error message to show |       ,esError :: String                              -- ^ error message to show | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -110,7 +110,7 @@ helpDialog = | |||||||
|     renderKey (key,desc) = withAttr (borderAttr <> "keys") (str key) <+> str " " <+> str desc |     renderKey (key,desc) = withAttr (borderAttr <> "keys") (str key) <+> str " " <+> str desc | ||||||
| 
 | 
 | ||||||
| -- | Event handler used when help mode is active. | -- | Event handler used when help mode is active. | ||||||
| helpHandle :: UIState -> BrickEvent Name Event -> EventM Name (Next UIState) | helpHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState) | ||||||
| helpHandle ui ev = | helpHandle ui ev = | ||||||
|   case ev of |   case ev of | ||||||
|     VtyEvent (EvKey k []) | k `elem` [KEsc, KLeft, KChar 'h', KChar '?'] -> continue $ setMode Normal ui |     VtyEvent (EvKey k []) | k `elem` [KEsc, KLeft, KChar 'h', KChar '?'] -> continue $ setMode Normal ui | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user