dev: ui: debug logging improvements, export screenRegisterDescriptions

This commit is contained in:
Simon Michael 2022-10-28 21:52:15 -10:00
parent d948198303
commit 778b660919
2 changed files with 45 additions and 36 deletions

View File

@ -149,8 +149,11 @@ uiReloadJournal copts d ui = do
ej <- ej <-
let copts' = enableForecastPreservingPeriod ui copts let copts' = enableForecastPreservingPeriod ui copts
in runExceptT $ journalReload copts' in runExceptT $ journalReload copts'
-- dlogUiTraceIO $ ("uiReloadJournal before reload: "++) $ pshow' $ map tdescription $ jtxns $ ajournal ui
return $ case ej of return $ case ej of
Right j -> regenerateScreens j d ui Right j ->
-- dlogUiTrace (("uiReloadJournal after reload: "++) $ pshow' $ map tdescription $ jtxns j) $
regenerateScreens j d ui
Left err -> Left err ->
case ui of case ui of
UIState{aScreen=ES _} -> ui{aScreen=esNew err} UIState{aScreen=ES _} -> ui{aScreen=esNew err}

View File

@ -27,8 +27,6 @@ module Hledger.UI.UIUtils (
,get' ,get'
,put' ,put'
,modify' ,modify'
,mapScreens
,screenId
,suspend ,suspend
,redraw ,redraw
,reportSpecAddQuery ,reportSpecAddQuery
@ -38,6 +36,9 @@ module Hledger.UI.UIUtils (
,dlogUiTraceIO ,dlogUiTraceIO
,dlogUiTraceM ,dlogUiTraceM
,dlogUiScreenStack ,dlogUiScreenStack
,screenRegisterDescriptions
,screenId
,mapScreens
,uiDebugLevel ,uiDebugLevel
,uiNumBlankItems ,uiNumBlankItems
) )
@ -48,7 +49,7 @@ import Brick.Widgets.Border
import Brick.Widgets.Border.Style import Brick.Widgets.Border.Style
import Brick.Widgets.Dialog import Brick.Widgets.Dialog
import Brick.Widgets.Edit import Brick.Widgets.Edit
import Brick.Widgets.List (List, listSelectedL, listNameL, listItemHeightL, listSelected, listMoveDown, listMoveUp, GenericList) import Brick.Widgets.List (List, listSelectedL, listNameL, listItemHeightL, listSelected, listMoveDown, listMoveUp, GenericList, listElements)
import Control.Monad.IO.Class import Control.Monad.IO.Class
import Data.Bifunctor (second) import Data.Bifunctor (second)
import Data.List import Data.List
@ -67,6 +68,7 @@ import Hledger.Cli.DocFiles
import Hledger.UI.UITypes import Hledger.UI.UITypes
import Data.Vector (Vector) import Data.Vector (Vector)
import qualified Data.Vector as V
-- | On posix platforms, send the system STOP signal to suspend the -- | On posix platforms, send the system STOP signal to suspend the
-- current program. On windows, does nothing. -- current program. On windows, does nothing.
@ -86,47 +88,33 @@ suspendSignal = raiseSignal sigSTOP
get' = do get' = do
x <- get x <- get
dlogUiTraceM $ "getting state: " ++ (head $ lines $ pshow $ aScreen x) dlogUiTraceM $ "getting state: " ++ (head $ lines $ pshow $ aScreen x)
-- ++ " " ++ (show $ map tdescription $ jtxns $ ajournal x)
-- dlogUiTraceM $ ("query: "++) $ pshow' $ x & aopts & uoCliOpts & reportspec_ & _rsQuery -- dlogUiTraceM $ ("query: "++) $ pshow' $ x & aopts & uoCliOpts & reportspec_ & _rsQuery
-- dlogUiScreenStack "" "" screenId x -- dlogUiScreenStack "getting" screenId x
-- dlogUiScreenStack "getting " "with register descriptions: " showscreenregisterdescriptions x -- dlogUiScreenStack "getting, with register descriptions" screenRegisterDescriptions x
return x return x
put' x = do put' x = do
dlogUiTraceM $ "putting state: " ++ (head $ lines $ pshow $ aScreen x) dlogUiTraceM $ "putting state: " ++ (head $ lines $ pshow $ aScreen x)
-- ++ " " ++ (show $ map tdescription $ jtxns $ ajournal x)
-- dlogUiTraceM $ ("query: "++) $ pshow' $ x & aopts & uoCliOpts & reportspec_ & _rsQuery -- dlogUiTraceM $ ("query: "++) $ pshow' $ x & aopts & uoCliOpts & reportspec_ & _rsQuery
-- dlogUiScreenStack "" "" screenId x -- dlogUiScreenStack "putting" screenId x
-- dlogUiScreenStack "putting " "with register descriptions: " showscreenregisterdescriptions x -- dlogUiScreenStack "putting, with register descriptions" screenRegisterDescriptions x
put x put x
modify' f = do modify' f = do
x <- get x <- get
let x' = f x let x' = f x
dlogUiTraceM $ "modifying state: " ++ (head $ lines $ pshow $ aScreen x') dlogUiTraceM $ "modifying state: " ++ (head $ lines $ pshow $ aScreen x')
-- ++ " " ++ (show $ map tdescription $ jtxns $ ajournal x')
-- dlogUiTraceM $ ("from: "++) $ pshow' $ x & aopts & uoCliOpts & reportspec_ & _rsQuery -- dlogUiTraceM $ ("from: "++) $ pshow' $ x & aopts & uoCliOpts & reportspec_ & _rsQuery
-- dlogUiTraceM $ ("to: "++) $ pshow' $ x' & aopts & uoCliOpts & reportspec_ & _rsQuery -- dlogUiTraceM $ ("to: "++) $ pshow' $ x' & aopts & uoCliOpts & reportspec_ & _rsQuery
-- dlogUiScreenStack "getting" "" screenId x -- dlogUiScreenStack "getting" screenId x
-- dlogUiScreenStack "putting" "" screenId x' -- dlogUiScreenStack "putting" screenId x'
-- dlogUiScreenStack "getting " "with register descriptions: " showscreenregisterdescriptions x -- dlogUiScreenStack "getting, with register descriptions" screenRegisterDescriptions x
-- dlogUiScreenStack "putting " "with register descriptions: " showscreenregisterdescriptions x' -- dlogUiScreenStack "putting, with register descriptions" screenRegisterDescriptions x'
modify f modify f
-- showscreenregisterdescriptions :: Screen -> String
-- showscreenregisterdescriptions scr = case scr of
-- MS _ -> "M" -- menu
-- AS _ -> "A" -- all accounts
-- BS _ -> "B" -- bs accounts
-- IS _ -> "I" -- is accounts
-- RS sst -> ("R:" ++) $ -- menu
-- intercalate "," $ map (T.unpack . rsItemDescription) $
-- takeWhile (not . T.null . rsItemDate) $ Data.Vector.toList $ listElements $ _rssList sst
-- TS _ -> "T" -- transaction
-- ES _ -> "E" -- error
-- | Run a function on each screen in a UIState's screen "stack",
-- from topmost screen down to currently-viewed screen.
mapScreens :: (Screen -> a) -> UIState -> [a]
mapScreens f UIState{aPrevScreens, aScreen} = map f $ reverse $ aScreen : aPrevScreens
-- | On posix platforms, suspend the program using the STOP signal, -- | On posix platforms, suspend the program using the STOP signal,
-- like control-z in bash, returning to the original shell prompt, -- like control-z in bash, returning to the original shell prompt,
-- and when resumed, continue where we left off. -- and when resumed, continue where we left off.
@ -465,15 +453,33 @@ dlogUiTraceIO s = dlogUiTrace s $ return ()
dlogUiTraceM :: String -> EventM Name UIState () dlogUiTraceM :: String -> EventM Name UIState ()
dlogUiTraceM s = dlogUiTrace s $ return () dlogUiTraceM s = dlogUiTrace s $ return ()
-- | Like dlogUiTraceM, but log a prefix, "screen stack", a postfix, -- | Like dlogUiTraceM, but log a compact view of the current screen stack,
-- and a compact view of the current screen stack,
-- from topmost screen to currently-viewed screen, -- from topmost screen to currently-viewed screen,
-- with each screen rendered by the given rendering function. -- with each screen rendered by the given rendering function
-- (and with the given extra label if any).
-- Useful for inspecting states across the whole screen stack. -- Useful for inspecting states across the whole screen stack.
-- To just show the stack: @dlogUiScreenStack "" "" screenId ui@ -- To just show the stack: @dlogUiScreenStack "" screenId ui@
dlogUiScreenStack :: String -> String -> (Screen -> String) -> UIState -> EventM Name UIState () dlogUiScreenStack :: String -> (Screen -> String) -> UIState -> EventM Name UIState ()
dlogUiScreenStack prefix postfix showscr ui = dlogUiScreenStack postfix showscr ui =
dlogUiTraceM $ prefix ++ "screen stack: " ++ postfix ++ (unwords $ mapScreens showscr ui) dlogUiTraceM $ concat [
"screen stack"
,if null postfix then "" else " (" ++ postfix ++ ")"
,": "
,unwords $ mapScreens showscr ui
]
-- | Run a function on each screen in a UIState's screen "stack",
-- from topmost screen down to currently-viewed screen.
mapScreens :: (Screen -> a) -> UIState -> [a]
mapScreens f UIState{aPrevScreens, aScreen} = map f $ reverse $ aScreen : aPrevScreens
-- Show a screen's compact id, plus for register screens, the transaction descriptions.
screenRegisterDescriptions :: Screen -> String
screenRegisterDescriptions scr = case scr of
RS sst -> ((screenId scr ++ ":") ++) $ -- menu
intercalate "," $ map (T.unpack . rsItemDescription) $
takeWhile (not . T.null . rsItemDate) $ V.toList $ listElements $ _rssList sst
_ -> screenId scr
-- Show a screen's compact id (first letter of its constructor). -- Show a screen's compact id (first letter of its constructor).
screenId :: Screen -> String screenId :: Screen -> String