From e1fc3cf254748f5a20295619d1754c367602a8da Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Tue, 9 Jan 2024 10:42:28 +1100 Subject: [PATCH] Avoid hiding view by using display --- up-top/src/Event.hs | 18 +++++++++--------- up-top/src/Types.hs | 8 ++++---- up-top/src/UI.hs | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/up-top/src/Event.hs b/up-top/src/Event.hs index 6fd627c..0c17503 100644 --- a/up-top/src/Event.hs +++ b/up-top/src/Event.hs @@ -10,7 +10,7 @@ import Control.Monad.IO.Class (liftIO) import qualified Data.HashMap.Strict as H import qualified Data.Vector as Vec import Graphics.Vty -import Lens.Micro.Platform hiding (view) +import Lens.Micro.Platform import Types import Up.Model.Account import Up.Model.Category @@ -18,21 +18,21 @@ import Up.Model.Category -- Handling events handleEvent :: BrickEvent Name UEvent -> EventM Name State () handleEvent (VtyEvent e) = do - use (screen . focus . view) >>= \case + use (screen . focus . display) >>= \case MainView lz ViewportMode -> case e of EvKey KEsc [] -> pure () - EvKey (KChar 'k') [] -> modify (setView (MainView (focusLeft lz) NormalMode)) - EvKey (KChar 'j') [] -> modify (setView (MainView (focusRight lz) NormalMode)) - EvKey KUp [] -> modify (setView (MainView (focusLeft lz) NormalMode)) - EvKey KDown [] -> modify (setView (MainView (focusRight lz) NormalMode)) - _ -> modify (setView (MainView lz NormalMode)) + EvKey (KChar 'k') [] -> modify (setDisplay (MainView (focusLeft lz) NormalMode)) + EvKey (KChar 'j') [] -> modify (setDisplay (MainView (focusRight lz) NormalMode)) + EvKey KUp [] -> modify (setDisplay (MainView (focusLeft lz) NormalMode)) + EvKey KDown [] -> modify (setDisplay (MainView (focusRight lz) NormalMode)) + _ -> modify (setDisplay (MainView lz NormalMode)) MainView lz NormalMode -> case e of EvKey KEsc [] -> halt EvKey (KChar 'q') [] -> halt EvKey (KChar '?') [] -> modify setHelpScreen - EvKey (KChar 'w') [MCtrl] -> modify (setView (MainView lz ViewportMode)) + EvKey (KChar 'w') [MCtrl] -> modify (setDisplay (MainView lz ViewportMode)) EvKey KEnter [] -> case lz ^. focus of FocusAccounts -> do aid <- use (accounts . to L.listSelectedElement) >>= \case @@ -40,7 +40,7 @@ handleEvent (VtyEvent e) = do Nothing -> error "" -- TODO: No more monad fail ch <- use reqChan liftIO $ writeBChan ch $ FetchTransaction aid - modify (setView (MainView (focusRight lz) NormalMode)) + modify (setDisplay (MainView (focusRight lz) NormalMode)) _ -> pure () ev -> case lz ^. focus of FocusTransactions -> do diff --git a/up-top/src/Types.hs b/up-top/src/Types.hs index ff8120a..6e07c0e 100644 --- a/up-top/src/Types.hs +++ b/up-top/src/Types.hs @@ -7,7 +7,7 @@ import Brick.BChan import qualified Brick.Widgets.List as L import Data.HashMap.Strict import qualified Data.Text as T -import Lens.Micro.Platform hiding (view) +import Lens.Micro.Platform import Servant.Client (ClientEnv) import Up.Model.Account import Up.Model.Category @@ -96,7 +96,7 @@ data Tag -- A Screen is a tag and a view data Screen = Screen { _tag :: Tag, - _view :: View + _display :: View } makeLenses ''Screen @@ -128,5 +128,5 @@ setMainScreen = setScreen MainTag setHelpScreen :: State -> State setHelpScreen = setScreen HelpTag -setView :: View -> State -> State -setView v st = st & (screen . focus . view) .~ v \ No newline at end of file +setDisplay :: View -> State -> State +setDisplay v st = st & (screen . focus . display) .~ v \ No newline at end of file diff --git a/up-top/src/UI.hs b/up-top/src/UI.hs index 3e58e71..e0bab39 100644 --- a/up-top/src/UI.hs +++ b/up-top/src/UI.hs @@ -1,7 +1,7 @@ module UI where import Brick.Types -import Lens.Micro.Platform hiding (view) +import Lens.Micro.Platform import Types import UI.HelpView @@ -9,6 +9,6 @@ import UI.MainView drawUI :: State -> [Widget Name] drawUI st = - case st ^. (screen . focus . view) of + case st ^. (screen . focus . display) of MainView lz _m -> drawMain st lz HelpView -> drawHelp st