imp:ui: debug output improvements

This commit is contained in:
Simon Michael 2025-09-11 23:25:15 +01:00
parent 7ccc0d5bdd
commit 53bd228973
6 changed files with 22 additions and 15 deletions

View File

@ -69,7 +69,7 @@ asDrawHelper :: UIState -> ReportOpts -> String -> [Widget Name]
asDrawHelper UIState{aScreen=scr, aopts=uopts, ajournal=j, aMode=mode} ropts scrname =
dbgui "asDrawHelper" $
case toAccountsLikeScreen scr of
Nothing -> dbgui "asDrawHelper" $ errorWrongScreenType "draw helper" -- PARTIAL:
Nothing -> dbgui "asDrawHelper" $ errorWrongScreenType "asDrawHelper" -- PARTIAL:
Just (ALS _ ass) -> case mode of
Help -> [helpDialog, maincontent]
_ -> [maincontent]
@ -189,7 +189,7 @@ asHandle ev = do
dbguiEv "asHandle"
ui0@UIState{aScreen=scr, aMode=mode} <- get'
case toAccountsLikeScreen scr of
Nothing -> dbgui "asHandle" $ errorWrongScreenType "event handler" -- PARTIAL:
Nothing -> dbgui "asHandle" $ errorWrongScreenType "asHandle" -- PARTIAL:
Just als@(ALS scons ass) -> do
-- save the currently selected account, in case we leave this screen and lose the selection
put' ui0{aScreen=scons ass{_assSelectedAccount=asSelectedAccount ass}}

View File

@ -104,7 +104,7 @@ esHandle ev = do
VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui
_ -> return ()
_ -> errorWrongScreenType "event handler"
_ -> errorWrongScreenType "esHandle"
-- | Parse the file name, line and column number from a hledger parse error message, if possible.
-- Temporary, we should keep the original parse error location. XXX

View File

@ -87,7 +87,7 @@ msDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=_rspec@Re
,("q", str "quit")
]
msDraw _ = dbgui "msDraw" $ errorWrongScreenType "draw function" -- PARTIAL:
msDraw _ = dbgui "msDraw" $ errorWrongScreenType "msDraw" -- PARTIAL:
-- msDrawItem :: (Int,Int) -> Bool -> MenuScreenItem -> Widget Name
-- msDrawItem (_acctwidth, _balwidth) _selected MenuScreenItem{..} =
@ -257,7 +257,7 @@ msHandle ev = do
MouseUp{} -> return ()
AppEvent _ -> return ()
_ -> dbguiEv "msHandle" >> errorWrongScreenType "event handler"
_ -> dbguiEv "msHandle" >> errorWrongScreenType "msHandle"
msEnterScreen :: Day -> ScreenName -> UIState -> EventM Name UIState ()
msEnterScreen d scrname ui@UIState{ajournal=j, aopts=uopts} = do

View File

@ -49,7 +49,7 @@ rsDraw :: UIState -> [Widget Name]
rsDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}}
,aScreen=RS RSS{..}
,aMode=mode
} = dbgui "rsDraw 1" $
} = dbgui "rsDraw" $
case mode of
Help -> [helpDialog, maincontent]
_ -> [maincontent]
@ -156,7 +156,7 @@ rsDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}}
-- ,("q", "quit")
]
rsDraw _ = dbgui "rsDraw 2" $ errorWrongScreenType "draw function" -- PARTIAL:
rsDraw _ = dbgui "rsDraw" $ errorWrongScreenType "rsDraw" -- PARTIAL:
rsDrawItem :: (Int,Int,Int,Int,Int) -> Bool -> RegisterScreenItem -> Widget Name
rsDrawItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected RegisterScreenItem{..} =
@ -187,7 +187,7 @@ rsDrawItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected Regist
rsHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
rsHandle ev = do
ui0 <- get'
dbguiEv "rsHandle 1"
dbguiEv "rsHandle"
case ui0 of
ui@UIState{
aScreen=RS sst@RSS{..}
@ -332,7 +332,7 @@ rsHandle ev = do
MouseUp{} -> return ()
AppEvent _ -> return ()
_ -> dbgui "rsHandle 2" $ errorWrongScreenType "event handler"
_ -> errorWrongScreenType "rsHandle"
isBlankElement mel = ((rsItemDate . snd) <$> mel) == Just ""

View File

@ -97,7 +97,7 @@ tsDraw UIState{aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec
-- ,("q", "quit")
]
tsDraw _ = errorWrongScreenType "draw function" -- PARTIAL:
tsDraw _ = errorWrongScreenType "tsDraw" -- PARTIAL:
-- Render a transaction suitably for the transaction screen.
showTxn :: ReportOpts -> ReportSpec -> Journal -> Transaction -> T.Text
@ -190,7 +190,7 @@ tsHandle ev = do
VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui
_ -> return ()
_ -> errorWrongScreenType "event handler"
_ -> errorWrongScreenType "tsHandle"
-- | Select a new transaction and update the previous register screen
tsSelect :: Integer -> Transaction -> UIState -> UIState

View File

@ -60,6 +60,7 @@ import Hledger.Cli.CliOptions
import Hledger.UI.UITypes
import Hledger.UI.UIOptions (UIOpts(uoCliOpts))
import Hledger.UI.UIScreens (screenUpdate)
import Hledger.UI.UIUtils (showScreenId)
-- | Make an initial UI state with the given options, journal,
-- parent screen stack if any, and starting screen.
@ -340,12 +341,18 @@ setMode :: Mode -> UIState -> UIState
setMode m ui = ui{aMode=m}
pushScreen :: Screen -> UIState -> UIState
pushScreen scr ui = ui{aPrevScreens=(aScreen ui:aPrevScreens ui)
,aScreen=scr
}
pushScreen scr ui =
dbg1Msg ("pushing screen " <> showScreenId scr)
ui{aPrevScreens=aScreen ui:aPrevScreens ui
,aScreen=scr
}
popScreen :: UIState -> UIState
popScreen ui@UIState{aPrevScreens=s:ss} = ui{aScreen=s, aPrevScreens=ss}
popScreen ui@UIState{aPrevScreens = s : ss} =
dbg1Msg ("popping screen " <> showScreenId (aScreen ui))
ui{aPrevScreens = ss
,aScreen = s
}
popScreen ui = ui
-- | Reset options to their startup values, discard screen navigation history,