{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE LambdaCase #-}
module Hledger.UI.UIUtils (
borderDepthStr
,borderKeysStr
,borderKeysStr'
,borderPeriodStr
,borderQueryStr
,clickFocusStep
,defaultLayout
,helpDialog
,helpHandle
,minibuffer
,moveDownEvents
,moveLeftEvents
,moveRightEvents
,moveUpEvents
,normaliseMovementKeys
,renderToggle
,renderToggle1
,replaceHiddenAccountsNameWith
,scrollSelectionToMiddle
,get'
,put'
,modify'
,suspend
,redraw
,uiInstallWarningCollector
,uiTakeWarnings
,journalIsFromStdin
,reportSpecAddQuery
,reportSpecSetFutureAndForecast
,listScrollPushingSelection
,dbgui
,dbguiIO
,dbguiEv
,dbguiScreensEv
,showScreenId
,showScreenRegisterDescriptions
,showScreenSelection
,mapScreens
,uiNumBlankItems
,showScreenStack
,sendVtyEvents
)
where
import Brick
import Brick.Widgets.Border
import Brick.Widgets.Border.Style
import Brick.Widgets.Dialog
import Brick.Widgets.Edit
import Brick.Widgets.List (List, listSelectedL, listNameL, listItemHeightL, listSelected, listMoveTo, listElements)
import Control.Concurrent.STM (atomically, writeTChan)
import Control.Monad.IO.Class
import Data.Bifunctor (second)
import Data.IORef (IORef, newIORef, atomicModifyIORef')
import Data.List
import Data.Text qualified as T
import Data.Time (NominalDiffTime, UTCTime, addDays, diffUTCTime)
import Graphics.Vty
(Event(..),Key(..),Modifier(..),Button(..),Vty(..),Color,Attr,currentAttr,refresh, displayBounds
,Vty (inputIface), InternalEvent (InputEvent), Input (eventChannel)
)
import Lens.Micro.Platform
import System.IO.Unsafe (unsafePerformIO)
import Hledger
import Hledger.Cli.DocFiles
import Hledger.UI.UITypes
import Data.Vector qualified as V
#ifdef mingw32_HOST_OS
suspendSignal :: IO ()
suspendSignal = return ()
#else
import System.Posix.Signals
suspendSignal :: IO ()
suspendSignal :: IO ()
suspendSignal = Signal -> IO ()
raiseSignal Signal
sigSTOP
#endif
get' :: EventM Name UIState UIState
get' = do
ui <- EventM Name UIState UIState
forall s (m :: * -> *). MonadState s m => m s
get
dbguiEv $ "getting state: " ++
showScreenStack "" showScreenSelection ui
return ui
put' :: UIState -> EventM Name UIState ()
put' UIState
ui = do
[Char] -> EventM Name UIState ()
forall s. [Char] -> EventM Name s ()
dbguiEv ([Char] -> EventM Name UIState ())
-> [Char] -> EventM Name UIState ()
forall a b. (a -> b) -> a -> b
$ [Char]
"putting state: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char] -> (Screen -> [Char]) -> UIState -> [Char]
showScreenStack [Char]
"" Screen -> [Char]
showScreenSelection UIState
ui
UIState -> EventM Name UIState ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put UIState
ui
modify' :: (UIState -> UIState) -> EventM Name UIState ()
modify' UIState -> UIState
f = do
ui <- EventM Name UIState UIState
forall s (m :: * -> *). MonadState s m => m s
get
let ui' = UIState -> UIState
f UIState
ui
dbguiEv $ "getting state: " ++ (showScreenStack "" showScreenSelection ui)
dbguiEv $ "putting state: " ++ (showScreenStack "" showScreenSelection ui')
modify f
suspend :: Ord a => s -> EventM a s ()
suspend :: forall a s. Ord a => s -> EventM a s ()
suspend s
st = IO s -> EventM a s ()
forall n s. Ord n => IO s -> EventM n s ()
suspendAndResume (IO s -> EventM a s ()) -> IO s -> EventM a s ()
forall a b. (a -> b) -> a -> b
$ IO ()
suspendSignal IO () -> IO s -> IO s
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> s -> IO s
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return s
st
redraw :: EventM a s ()
redraw :: forall a s. EventM a s ()
redraw = EventM a s Vty
forall n s. EventM n s Vty
getVtyHandle EventM a s Vty -> (Vty -> EventM a s ()) -> EventM a s ()
forall a b. EventM a s a -> (a -> EventM a s b) -> EventM a s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO () -> EventM a s ()
forall a. IO a -> EventM a s a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> EventM a s ()) -> (Vty -> IO ()) -> Vty -> EventM a s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vty -> IO ()
refresh
{-# NOINLINE uiWarningsRef #-}
uiWarningsRef :: IORef [String]
uiWarningsRef :: IORef [[Char]]
uiWarningsRef = IO (IORef [[Char]]) -> IORef [[Char]]
forall a. IO a -> a
unsafePerformIO (IO (IORef [[Char]]) -> IORef [[Char]])
-> IO (IORef [[Char]]) -> IORef [[Char]]
forall a b. (a -> b) -> a -> b
$ [[Char]] -> IO (IORef [[Char]])
forall a. a -> IO (IORef a)
newIORef []
uiInstallWarningCollector :: IO ()
uiInstallWarningCollector :: IO ()
uiInstallWarningCollector = ([Char] -> IO ()) -> IO ()
setWarningHandler (([Char] -> IO ()) -> IO ()) -> ([Char] -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \[Char]
msg ->
IORef [[Char]] -> ([[Char]] -> ([[Char]], ())) -> IO ()
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef [[Char]]
uiWarningsRef (([[Char]] -> ([[Char]], ())) -> IO ())
-> ([[Char]] -> ([[Char]], ())) -> IO ()
forall a b. (a -> b) -> a -> b
$ \[[Char]]
ws -> ([[Char]]
ws [[Char]] -> [[Char]] -> [[Char]]
forall a. [a] -> [a] -> [a]
++ [[Char]
msg], ())
uiTakeWarnings :: IO [String]
uiTakeWarnings :: IO [[Char]]
uiTakeWarnings = IORef [[Char]] -> ([[Char]] -> ([[Char]], [[Char]])) -> IO [[Char]]
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef [[Char]]
uiWarningsRef (([[Char]] -> ([[Char]], [[Char]])) -> IO [[Char]])
-> ([[Char]] -> ([[Char]], [[Char]])) -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ \[[Char]]
ws -> ([], [[Char]]
ws)
defaultLayout :: Widget Name -> Widget Name -> Widget Name -> Widget Name
defaultLayout :: Widget Name -> Widget Name -> Widget Name -> Widget Name
defaultLayout Widget Name
toplabel Widget Name
bottomlabel =
Widget Name -> Widget Name -> Widget Name -> Widget Name
topBottomBorderWithLabels ([Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
" "Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+>Widget Name
toplabelWidget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+>[Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
" ") ([Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
" "Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+>Widget Name
bottomlabelWidget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+>[Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
" ") (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Int -> Maybe Color -> Widget Name -> Widget Name
margin Int
1 Int
0 Maybe Color
forall a. Maybe a
Nothing
helpDialog :: Widget Name
helpDialog :: Widget Name
helpDialog =
Size -> Size -> RenderM Name (Result Name) -> Widget Name
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed (RenderM Name (Result Name) -> Widget Name)
-> RenderM Name (Result Name) -> Widget Name
forall a b. (a -> b) -> a -> b
$ do
c <- RenderM Name (Context Name)
forall n. RenderM n (Context n)
getContext
render $
withDefAttr (attrName "help") $
renderDialog (dialog (Just $ str "Help (LEFT/ESC/?/q to close help)") Nothing (c^.availWidthL)) $
padTop (Pad 0) $ padLeft (Pad 1) $ padRight (Pad 1) $
vBox [
hBox [
padRight (Pad 1) $
vBox [
withAttr (attrName "help" <> attrName "heading") $ str "Navigation"
,renderKey ("UP/DOWN/PUP/PDN/HOME/END/k/j/C-p/C-n", "")
,str " move selection up/down"
,renderKey ("RIGHT/l/C-f", "show txns, or txn detail")
,renderKey ("LEFT/h/C-b ", "go back/see other screens")
,renderKey ("ESC ", "cancel, or reset app state")
,str " "
,withAttr (attrName "help" <> attrName "heading") $ str "Accounts screens"
,renderKey ("1234567890-+ ", "set/adjust depth limit")
,renderKey ("t ", "toggle accounts tree/list mode")
,renderKey ("H ", "toggle historical balance/change")
,str " "
,withAttr (attrName "help" <> attrName "heading") $ str "Register screens"
,renderKey ("t ", "toggle subaccount txns\n(and accounts tree/list mode)")
,renderKey ("H ", "toggle historical/period total")
,str " "
,withAttr (attrName "help" <> attrName "heading") $ str "Help"
,renderKey ("? ", "toggle this help")
,renderKey ("p/m/i", "while help is open:\nshow manual in pager/man/info")
,str " "
]
,padLeft (Pad 1) $ padRight (Pad 0) $
vBox [
withAttr (attrName "help" <> attrName "heading") $ str "Filtering"
,renderKey ("/ ", "set a filter query")
,renderKey ("F ", "show future & forecast txns")
,renderKey ("R ", "show real/all postings")
,renderKey ("z ", "show nonzero/all amounts")
,renderKey ("U/P/C ", "show unmarked/pending/cleared")
,renderKey ("S-DOWN /S-UP ", "shrink/grow period")
,renderKey ("S-RIGHT/S-LEFT", "next/previous period")
,renderKey ("T ", "set period to today")
,renderKey ("DEL ", "reset filters")
,str " "
,withAttr (attrName "help" <> attrName "heading") $ str "Other"
,renderKey ("a ", "add transaction (hledger add)")
,renderKey ("A ", "add transaction (hledger-iadd)")
,renderKey ("B ", "show amounts/costs")
,renderKey ("E ", "open editor")
,renderKey ("I ", "toggle balance assertions")
,renderKey ("L ", "show/hide lot detail")
,renderKey ("V ", "show amounts/market values")
,renderKey ("g ", "reload data")
,renderKey ("C-l ", "redraw & recenter")
,renderKey ("C-z ", "suspend")
,renderKey ("q ", "quit")
,renderKey ("C-c ", "quit, from anywhere")
]
]
]
where
renderKey :: ([Char], [Char]) -> Widget n
renderKey ([Char]
key,[Char]
desc) = AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr ([Char] -> AttrName
attrName [Char]
"help" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"key") ([Char] -> Widget n
forall n. [Char] -> Widget n
str [Char]
key) Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+> [Char] -> Widget n
forall n. [Char] -> Widget n
str [Char]
" " Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+> [Char] -> Widget n
forall n. [Char] -> Widget n
str [Char]
desc
helpHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
helpHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
helpHandle BrickEvent Name AppEvent
ev = do
ui <- EventM Name UIState UIState
forall s (m :: * -> *). MonadState s m => m s
get
let ui' = UIState
ui{aMode=Normal}
case ev of
VtyEvent Event
e | Event
e Event -> [Event] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Event]
closeHelpEvents -> UIState -> EventM Name UIState ()
put' UIState
ui'
VtyEvent (EvKey (KChar Char
'p') []) -> IO UIState -> EventM Name UIState ()
forall n s. Ord n => IO s -> EventM n s ()
suspendAndResume ([Char] -> Maybe [Char] -> IO ()
runPagerForTopic [Char]
"hledger-ui" Maybe [Char]
forall a. Maybe a
Nothing IO () -> IO UIState -> IO UIState
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> UIState -> IO UIState
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return UIState
ui')
VtyEvent (EvKey (KChar Char
'm') []) -> IO UIState -> EventM Name UIState ()
forall n s. Ord n => IO s -> EventM n s ()
suspendAndResume ([Char] -> Maybe [Char] -> IO ()
runManForTopic [Char]
"hledger-ui" Maybe [Char]
forall a. Maybe a
Nothing IO () -> IO UIState -> IO UIState
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> UIState -> IO UIState
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return UIState
ui')
VtyEvent (EvKey (KChar Char
'i') []) -> IO UIState -> EventM Name UIState ()
forall n s. Ord n => IO s -> EventM n s ()
suspendAndResume ([Char] -> Maybe [Char] -> IO ()
runInfoForTopic [Char]
"hledger-ui" Maybe [Char]
forall a. Maybe a
Nothing IO () -> IO UIState -> IO UIState
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> UIState -> IO UIState
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return UIState
ui')
BrickEvent Name AppEvent
_ -> () -> EventM Name UIState ()
forall a. a -> EventM Name UIState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
closeHelpEvents :: [Event]
closeHelpEvents = [Event]
moveLeftEvents [Event] -> [Event] -> [Event]
forall a. [a] -> [a] -> [a]
++ [Key -> [Modifier] -> Event
EvKey Key
KEsc [], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'?') [], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'q') []]
minibuffer :: T.Text -> Editor String Name -> Widget Name
minibuffer :: AccountName -> Editor [Char] Name -> Widget Name
minibuffer AccountName
string Editor [Char] Name
ed =
AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
forceAttr ([Char] -> AttrName
attrName [Char]
"border" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"minibuffer") (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
[Widget Name] -> Widget Name
forall n. [Widget n] -> Widget n
hBox [AccountName -> Widget Name
forall n. AccountName -> Widget n
txt (AccountName -> Widget Name) -> AccountName -> Widget Name
forall a b. (a -> b) -> a -> b
$ AccountName
string AccountName -> AccountName -> AccountName
forall a. Semigroup a => a -> a -> a
<> AccountName
": ", ([[Char]] -> Widget Name)
-> Bool -> Editor [Char] Name -> Widget Name
forall n t.
(Ord n, Show n, Monoid t, TextWidth t, GenericTextZipper t) =>
([t] -> Widget n) -> Bool -> Editor t n -> Widget n
renderEditor ([Char] -> Widget Name
forall n. [Char] -> Widget n
str ([Char] -> Widget Name)
-> ([[Char]] -> [Char]) -> [[Char]] -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> [Char]
unlines) Bool
True Editor [Char] Name
ed]
borderQueryStr :: String -> Widget Name
borderQueryStr :: [Char] -> Widget Name
borderQueryStr [Char]
"" = [Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
""
borderQueryStr [Char]
qry = [Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
" matching " Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withAttr ([Char] -> AttrName
attrName [Char]
"border" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"query") ([Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
qry)
borderDepthStr :: Maybe Int -> Widget Name
borderDepthStr :: Maybe Int -> Widget Name
borderDepthStr Maybe Int
Nothing = [Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
""
borderDepthStr (Just Int
d) = [Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
" to depth " Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withAttr ([Char] -> AttrName
attrName [Char]
"border" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"query") ([Char] -> Widget Name
forall n. [Char] -> Widget n
str ([Char] -> Widget Name) -> [Char] -> Widget Name
forall a b. (a -> b) -> a -> b
$ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
d)
borderPeriodStr :: String -> Period -> Widget Name
borderPeriodStr :: [Char] -> Period -> Widget Name
borderPeriodStr [Char]
_ Period
PeriodAll = [Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
""
borderPeriodStr [Char]
preposition Period
p = [Char] -> Widget Name
forall n. [Char] -> Widget n
str ([Char]
" "[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++[Char]
preposition[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++[Char]
" ") Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withAttr ([Char] -> AttrName
attrName [Char]
"border" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"query") ([Char] -> Widget Name
forall n. [Char] -> Widget n
str ([Char] -> Widget Name)
-> (AccountName -> [Char]) -> AccountName -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AccountName -> [Char]
T.unpack (AccountName -> Widget Name) -> AccountName -> Widget Name
forall a b. (a -> b) -> a -> b
$ Period -> AccountName
showPeriod Period
p)
borderKeysStr :: [(String,String)] -> Widget Name
borderKeysStr :: [([Char], [Char])] -> Widget Name
borderKeysStr = [([Char], Widget Name)] -> Widget Name
borderKeysStr' ([([Char], Widget Name)] -> Widget Name)
-> ([([Char], [Char])] -> [([Char], Widget Name)])
-> [([Char], [Char])]
-> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([Char], [Char]) -> ([Char], Widget Name))
-> [([Char], [Char])] -> [([Char], Widget Name)]
forall a b. (a -> b) -> [a] -> [b]
map (([Char] -> Widget Name)
-> ([Char], [Char]) -> ([Char], Widget Name)
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second [Char] -> Widget Name
forall n. [Char] -> Widget n
str)
borderKeysStr' :: [(String,Widget Name)] -> Widget Name
borderKeysStr' :: [([Char], Widget Name)] -> Widget Name
borderKeysStr' [([Char], Widget Name)]
keydescs =
[Widget Name] -> Widget Name
forall n. [Widget n] -> Widget n
hBox ([Widget Name] -> Widget Name) -> [Widget Name] -> Widget Name
forall a b. (a -> b) -> a -> b
$
Widget Name -> [Widget Name] -> [Widget Name]
forall a. a -> [a] -> [a]
intersperse Widget Name
forall {n}. Widget n
sep ([Widget Name] -> [Widget Name]) -> [Widget Name] -> [Widget Name]
forall a b. (a -> b) -> a -> b
$
[AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withAttr ([Char] -> AttrName
attrName [Char]
"border" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"key") ([Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
keys) Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> [Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
":" Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> Widget Name
desc | ([Char]
keys, Widget Name
desc) <- [([Char], Widget Name)]
keydescs]
where
sep :: Widget n
sep = [Char] -> Widget n
forall n. [Char] -> Widget n
str [Char]
" "
renderToggle :: Bool -> String -> String -> Widget Name
renderToggle :: Bool -> [Char] -> [Char] -> Widget Name
renderToggle Bool
isright [Char]
l [Char]
r =
let bold :: Widget n -> Widget n
bold = AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr ([Char] -> AttrName
attrName [Char]
"border" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"selected") in
if Bool
isright
then [Char] -> Widget Name
forall n. [Char] -> Widget n
str ([Char]
l[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++[Char]
"/") Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> Widget Name -> Widget Name
forall {n}. Widget n -> Widget n
bold ([Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
r)
else Widget Name -> Widget Name
forall {n}. Widget n -> Widget n
bold ([Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
l) Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> [Char] -> Widget Name
forall n. [Char] -> Widget n
str ([Char]
"/"[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++[Char]
r)
renderToggle1 :: Bool -> String -> Widget Name
renderToggle1 :: Bool -> [Char] -> Widget Name
renderToggle1 Bool
isactive [Char]
l =
let bold :: Widget n -> Widget n
bold = AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr ([Char] -> AttrName
attrName [Char]
"border" AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> [Char] -> AttrName
attrName [Char]
"selected") in
if Bool
isactive
then Widget Name -> Widget Name
forall {n}. Widget n -> Widget n
bold ([Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
l)
else [Char] -> Widget Name
forall n. [Char] -> Widget n
str [Char]
l
replaceHiddenAccountsNameWith :: AccountName -> AccountName -> AccountName
replaceHiddenAccountsNameWith :: AccountName -> AccountName -> AccountName
replaceHiddenAccountsNameWith AccountName
anew AccountName
a | AccountName
a AccountName -> AccountName -> Bool
forall a. Eq a => a -> a -> Bool
== AccountName
hiddenAccountsName = AccountName
anew
| AccountName
a AccountName -> AccountName -> Bool
forall a. Eq a => a -> a -> Bool
== AccountName
"*" = AccountName
anew
| Bool
otherwise = AccountName
a
hiddenAccountsName :: AccountName
hiddenAccountsName = AccountName
"..."
topBottomBorderWithLabels :: Widget Name -> Widget Name -> Widget Name -> Widget Name
topBottomBorderWithLabels :: Widget Name -> Widget Name -> Widget Name -> Widget Name
topBottomBorderWithLabels Widget Name
toplabel Widget Name
bottomlabel Widget Name
body =
Size -> Size -> RenderM Name (Result Name) -> Widget Name
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Greedy (RenderM Name (Result Name) -> Widget Name)
-> RenderM Name (Result Name) -> Widget Name
forall a b. (a -> b) -> a -> b
$ do
c <- RenderM Name (Context Name)
forall n. RenderM n (Context n)
getContext
let (_w,h) = (c^.availWidthL, c^.availHeightL)
h' = Int
h Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2
body' = Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit (Int
h') Widget Name
body
debugmsg =
[Char]
""
render $
hBorderWithLabel (withAttr (attrName "border") $ toplabel <+> str debugmsg)
<=>
body'
<=>
hBorderWithLabel (withAttr (attrName "border") bottomlabel)
margin :: Int -> Int -> Maybe Color -> Widget Name -> Widget Name
margin :: Int -> Int -> Maybe Color -> Widget Name -> Widget Name
margin Int
h Int
v Maybe Color
mcolour Widget Name
w = Size -> Size -> RenderM Name (Result Name) -> Widget Name
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Greedy (RenderM Name (Result Name) -> Widget Name)
-> RenderM Name (Result Name) -> Widget Name
forall a b. (a -> b) -> a -> b
$ do
ctx <- RenderM Name (Context Name)
forall n. RenderM n (Context n)
getContext
let w' = Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit (Context Name
ctxContext Name -> Getting Int (Context Name) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context Name) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
vInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
2) (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
hLimit (Context Name
ctxContext Name -> Getting Int (Context Name) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context Name) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availWidthL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
hInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
2) Widget Name
w
attr = Attr -> (Color -> Attr) -> Maybe Color -> Attr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Attr
currentAttr (\Color
c -> Color
c Color -> Color -> Attr
`on` Color
c) Maybe Color
mcolour
render $
withBorderAttr attr $
withBorderStyle (borderStyleFromChar ' ') $
applyN v (hBorder <=>) $
applyN h (vBorder <+>) $
applyN v (<=> hBorder) $
applyN h (<+> vBorder) $
w'
withBorderAttr :: Attr -> Widget Name -> Widget Name
withBorderAttr :: Attr -> Widget Name -> Widget Name
withBorderAttr Attr
attr = (AttrMap -> AttrMap) -> Widget Name -> Widget Name
forall n. (AttrMap -> AttrMap) -> Widget n -> Widget n
updateAttrMap ([(AttrName, Attr)] -> AttrMap -> AttrMap
applyAttrMappings [([Char] -> AttrName
attrName [Char]
"border", Attr
attr)])
scrollSelectionToMiddle :: Int -> Brick.Widgets.List.List Name item -> EventM Name UIState ()
scrollSelectionToMiddle :: forall item. Int -> List Name item -> EventM Name UIState ()
scrollSelectionToMiddle Int
numitems List Name item
list = do
case List Name item
listList Name item
-> Getting (Maybe Int) (List Name item) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) (List Name item) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL of
Maybe Int
Nothing -> () -> EventM Name UIState ()
forall a. a -> EventM Name UIState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just Int
selectedrow -> do
let name :: Name
name = List Name item
listList Name item -> Getting Name (List Name item) Name -> Name
forall s a. s -> Getting a s a -> a
^.Getting Name (List Name item) Name
forall n1 (t :: * -> *) e n2 (f :: * -> *).
Functor f =>
(n1 -> f n2) -> GenericList n1 t e -> f (GenericList n2 t e)
listNameL
mvp <- Name -> EventM Name UIState (Maybe Viewport)
forall n s. Ord n => n -> EventM n s (Maybe Viewport)
lookupViewport Name
name
pageheight <- dbg4 "pageheight" <$> case mvp of
Just VP{_vpSize :: Viewport -> (Int, Int)
_vpSize=(Int
_,Int
h)} -> Int -> EventM Name UIState Int
forall a. a -> EventM Name UIState a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
h
Maybe Viewport
Nothing -> do
Vty{outputIface} <- EventM Name UIState Vty
forall n s. EventM n s Vty
getVtyHandle
snd <$> liftIO (displayBounds outputIface)
let
itemheight = [Char] -> Int -> Int
forall a. Show a => [Char] -> a -> a
dbg4 [Char]
"itemheight" (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ List Name item
listList Name item -> Getting Int (List Name item) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (List Name item) Int
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Int -> f Int) -> GenericList n t e -> f (GenericList n t e)
listItemHeightL
itemsperpage = [Char] -> Int -> Int
forall a. Show a => [Char] -> a -> a
dbg4 [Char]
"itemsperpage" (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
pageheight Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
itemheight
centeredtop = Int
selectedrow Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
itemsperpage Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2)
maxtop = Int
numitems Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
itemsperpage
toprow = [Char] -> Int -> Int
forall a. Show a => [Char] -> a -> a
dbg4 [Char]
"toprow" (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
centeredtop Int
maxtop)
setTop (viewportScroll name) toprow
moveUpEvents :: [Event]
moveUpEvents = [Key -> [Modifier] -> Event
EvKey Key
KUp [] , Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'k') [], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'p') [Modifier
MCtrl]]
moveDownEvents :: [Event]
moveDownEvents = [Key -> [Modifier] -> Event
EvKey Key
KDown [] , Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'j') [], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'n') [Modifier
MCtrl]]
moveLeftEvents :: [Event]
moveLeftEvents = [Key -> [Modifier] -> Event
EvKey Key
KLeft [] , Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'h') [], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'b') [Modifier
MCtrl]]
moveRightEvents :: [Event]
moveRightEvents = [Key -> [Modifier] -> Event
EvKey Key
KRight [], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'l') [], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'f') [Modifier
MCtrl], Key -> [Modifier] -> Event
EvKey Key
KEnter []]
normaliseMovementKeys :: Event -> Event
normaliseMovementKeys Event
ev
| Event
ev Event -> [Event] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Event]
moveUpEvents = Key -> [Modifier] -> Event
EvKey Key
KUp []
| Event
ev Event -> [Event] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Event]
moveDownEvents = Key -> [Modifier] -> Event
EvKey Key
KDown []
| Event
ev Event -> [Event] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Event]
moveLeftEvents = Key -> [Modifier] -> Event
EvKey Key
KLeft []
| Event
ev Event -> [Event] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Event]
moveRightEvents = Key -> [Modifier] -> Event
EvKey Key
KRight []
| Bool
otherwise = Event
ev
reportSpecAddQuery :: Query -> ReportSpec -> ReportSpec
reportSpecAddQuery :: Query -> ReportSpec -> ReportSpec
reportSpecAddQuery Query
q ReportSpec
rspec =
ReportSpec
rspec{_rsQuery=simplifyQuery $ And [_rsQuery rspec, q]}
reportSpecSetFutureAndForecast :: Maybe DateSpan -> ReportSpec -> ReportSpec
reportSpecSetFutureAndForecast :: Maybe DateSpan -> ReportSpec -> ReportSpec
reportSpecSetFutureAndForecast Maybe DateSpan
fcast ReportSpec
rspec =
ReportSpec
rspec{_rsQuery=simplifyQuery $ And [_rsQuery rspec, periodq, excludeforecastq fcast]}
where
periodq :: Query
periodq = DateSpan -> Query
Date (DateSpan -> Query)
-> (ReportOpts -> DateSpan) -> ReportOpts -> Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Period -> DateSpan
periodAsDateSpan (Period -> DateSpan)
-> (ReportOpts -> Period) -> ReportOpts -> DateSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReportOpts -> Period
period_ (ReportOpts -> Query) -> ReportOpts -> Query
forall a b. (a -> b) -> a -> b
$ ReportSpec -> ReportOpts
_rsReportOpts ReportSpec
rspec
excludeforecastq :: Maybe a -> Query
excludeforecastq (Just a
_) = Query
Any
excludeforecastq Maybe a
Nothing =
[Query] -> Query
And [
Query -> Query
Not (DateSpan -> Query
Date (DateSpan -> Query) -> DateSpan -> Query
forall a b. (a -> b) -> a -> b
$ Maybe EFDay -> Maybe EFDay -> DateSpan
DateSpan (EFDay -> Maybe EFDay
forall a. a -> Maybe a
Just (EFDay -> Maybe EFDay) -> EFDay -> Maybe EFDay
forall a b. (a -> b) -> a -> b
$ Day -> EFDay
Exact (Day -> EFDay) -> Day -> EFDay
forall a b. (a -> b) -> a -> b
$ Integer -> Day -> Day
addDays Integer
1 (Day -> Day) -> Day -> Day
forall a b. (a -> b) -> a -> b
$ ReportSpec -> Day
_rsDay ReportSpec
rspec) Maybe EFDay
forall a. Maybe a
Nothing)
,Query -> Query
Not Query
generatedTransactionTag
]
listScrollPushingSelection :: Name -> Int -> Int -> EventM Name (Brick.Widgets.List.List Name item) ()
listScrollPushingSelection :: forall item. Name -> Int -> Int -> EventM Name (List Name item) ()
listScrollPushingSelection Name
name Int
listheight Int
scrollamt =
Name -> EventM Name (List Name item) (Maybe Viewport)
forall n s. Ord n => n -> EventM n s (Maybe Viewport)
lookupViewport Name
name EventM Name (List Name item) (Maybe Viewport)
-> (Maybe Viewport -> EventM Name (List Name item) ())
-> EventM Name (List Name item) ()
forall a b.
EventM Name (List Name item) a
-> (a -> EventM Name (List Name item) b)
-> EventM Name (List Name item) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe Viewport
Nothing -> () -> EventM Name (List Name item) ()
forall a. a -> EventM Name (List Name item) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just VP{Int
_vpTop :: Int
_vpTop :: Viewport -> Int
_vpTop, _vpSize :: Viewport -> (Int, Int)
_vpSize=(Int
_,Int
vpheight)} -> do
let
lastitem :: Int
lastitem = Int
listheight Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
top :: Int
top = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
listheight Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
vpheight) (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
_vpTop Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
scrollamt
bottom :: Int
bottom = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
lastitem (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
top Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
vpheight Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
Name -> ViewportScroll Name
forall n. n -> ViewportScroll n
viewportScroll Name
name ViewportScroll Name -> forall s. Int -> EventM Name s ()
forall n. ViewportScroll n -> forall s. Int -> EventM n s ()
`vScrollBy` (Int
top Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
_vpTop)
(List Name item -> List Name item)
-> EventM Name (List Name item) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((List Name item -> List Name item)
-> EventM Name (List Name item) ())
-> (List Name item -> List Name item)
-> EventM Name (List Name item) ()
forall a b. (a -> b) -> a -> b
$ \List Name item
list -> case List Name item -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
listSelected List Name item
list of
Just Int
selidx | Int
selidx Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
top -> Int -> List Name item -> List Name item
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
top List Name item
list
| Int
selidx Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
bottom -> Int -> List Name item -> List Name item
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
bottom List Name item
list
Maybe Int
_ -> List Name item
list
dbgui :: String -> a -> a
dbgui :: forall a. [Char] -> a -> a
dbgui = [Char] -> a -> a
forall a. [Char] -> a -> a
dbg1Msg
dbguiIO :: String -> IO ()
dbguiIO :: [Char] -> IO ()
dbguiIO = [Char] -> IO ()
forall (m :: * -> *). MonadIO m => [Char] -> m ()
dbg1MsgIO
journalIsFromStdin :: Journal -> Bool
journalIsFromStdin :: Journal -> Bool
journalIsFromStdin Journal
j = Journal -> [Char]
journalFilePath Journal
j [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"-"
dbguiEv :: String -> EventM Name s ()
dbguiEv :: forall s. [Char] -> EventM Name s ()
dbguiEv [Char]
s = [Char] -> EventM Name s () -> EventM Name s ()
forall a. [Char] -> a -> a
dbg1Msg [Char]
s (EventM Name s () -> EventM Name s ())
-> EventM Name s () -> EventM Name s ()
forall a b. (a -> b) -> a -> b
$ () -> EventM Name s ()
forall a. a -> EventM Name s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
dbguiScreensEv :: String -> (Screen -> String) -> UIState -> EventM Name UIState ()
dbguiScreensEv :: [Char] -> (Screen -> [Char]) -> UIState -> EventM Name UIState ()
dbguiScreensEv [Char]
postfix Screen -> [Char]
showscr UIState
ui = [Char] -> EventM Name UIState ()
forall s. [Char] -> EventM Name s ()
dbguiEv ([Char] -> EventM Name UIState ())
-> [Char] -> EventM Name UIState ()
forall a b. (a -> b) -> a -> b
$ [Char] -> (Screen -> [Char]) -> UIState -> [Char]
showScreenStack [Char]
postfix Screen -> [Char]
showscr UIState
ui
showScreenStack :: String -> (Screen -> String) -> UIState -> String
showScreenStack :: [Char] -> (Screen -> [Char]) -> UIState -> [Char]
showScreenStack [Char]
postfix Screen -> [Char]
showscr UIState
ui = [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [
[Char]
"screen stack"
,if [Char] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
postfix then [Char]
"" else [Char]
", " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
postfix
,[Char]
": "
,[[Char]] -> [Char]
unwords ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ (Screen -> [Char]) -> UIState -> [[Char]]
forall a. (Screen -> a) -> UIState -> [a]
mapScreens Screen -> [Char]
showscr UIState
ui
]
mapScreens :: (Screen -> a) -> UIState -> [a]
mapScreens :: forall a. (Screen -> a) -> UIState -> [a]
mapScreens Screen -> a
f UIState{[Screen]
aPrevScreens :: [Screen]
aPrevScreens :: UIState -> [Screen]
aPrevScreens, Screen
aScreen :: Screen
aScreen :: UIState -> Screen
aScreen} = (Screen -> a) -> [Screen] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Screen -> a
f ([Screen] -> [a]) -> [Screen] -> [a]
forall a b. (a -> b) -> a -> b
$ [Screen] -> [Screen]
forall a. [a] -> [a]
reverse ([Screen] -> [Screen]) -> [Screen] -> [Screen]
forall a b. (a -> b) -> a -> b
$ Screen
aScreen Screen -> [Screen] -> [Screen]
forall a. a -> [a] -> [a]
: [Screen]
aPrevScreens
showScreenId :: Screen -> String
showScreenId :: Screen -> [Char]
showScreenId = \case
MS MenuScreenState
_ -> [Char]
"M"
AS ASS{AccountsScreenKind
_assKind :: AccountsScreenKind
_assKind :: AccountsScreenState -> AccountsScreenKind
_assKind} -> AccountsScreenKind -> [Char]
accountsScreenKindId AccountsScreenKind
_assKind
RS RegisterScreenState
_ -> [Char]
"R"
TS TransactionScreenState
_ -> [Char]
"T"
ES ErrorScreenState
_ -> [Char]
"E"
accountsScreenKindId :: AccountsScreenKind -> String
accountsScreenKindId :: AccountsScreenKind -> [Char]
accountsScreenKindId = \case
AccountsScreenKind
AllAccounts -> [Char]
"A"
AccountsScreenKind
CashAccounts -> [Char]
"C"
AccountsScreenKind
BalancesheetAccounts -> [Char]
"B"
AccountsScreenKind
IncomestatementAccounts -> [Char]
"I"
showScreenRegisterDescriptions :: Screen -> String
showScreenRegisterDescriptions :: Screen -> [Char]
showScreenRegisterDescriptions Screen
scr = case Screen
scr of
RS RegisterScreenState
sst -> ((Screen -> [Char]
showScreenId Screen
scr [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
":") [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$
[Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"," ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ (RegisterScreenItem -> [Char]) -> [RegisterScreenItem] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map (AccountName -> [Char]
T.unpack (AccountName -> [Char])
-> (RegisterScreenItem -> AccountName)
-> RegisterScreenItem
-> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RegisterScreenItem -> AccountName
rsItemDescription) ([RegisterScreenItem] -> [[Char]])
-> [RegisterScreenItem] -> [[Char]]
forall a b. (a -> b) -> a -> b
$
(RegisterScreenItem -> Bool)
-> [RegisterScreenItem] -> [RegisterScreenItem]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Bool -> Bool
not (Bool -> Bool)
-> (RegisterScreenItem -> Bool) -> RegisterScreenItem -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AccountName -> Bool
T.null (AccountName -> Bool)
-> (RegisterScreenItem -> AccountName)
-> RegisterScreenItem
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RegisterScreenItem -> AccountName
rsItemDate) ([RegisterScreenItem] -> [RegisterScreenItem])
-> [RegisterScreenItem] -> [RegisterScreenItem]
forall a b. (a -> b) -> a -> b
$ Vector RegisterScreenItem -> [RegisterScreenItem]
forall a. Vector a -> [a]
V.toList (Vector RegisterScreenItem -> [RegisterScreenItem])
-> Vector RegisterScreenItem -> [RegisterScreenItem]
forall a b. (a -> b) -> a -> b
$ GenericList Name Vector RegisterScreenItem
-> Vector RegisterScreenItem
forall n (t :: * -> *) e. GenericList n t e -> t e
listElements (GenericList Name Vector RegisterScreenItem
-> Vector RegisterScreenItem)
-> GenericList Name Vector RegisterScreenItem
-> Vector RegisterScreenItem
forall a b. (a -> b) -> a -> b
$ RegisterScreenState -> GenericList Name Vector RegisterScreenItem
_rssList RegisterScreenState
sst
Screen
_ -> Screen -> [Char]
showScreenId Screen
scr
showScreenSelection :: Screen -> String
showScreenSelection :: Screen -> [Char]
showScreenSelection = \case
MS MSS{List Name MenuScreenItem
_mssList :: List Name MenuScreenItem
_mssList :: MenuScreenState -> List Name MenuScreenItem
_mssList} -> [Char]
"M" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ ([Char] -> (Int -> [Char]) -> Maybe Int -> [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" Int -> [Char]
forall a. Show a => a -> [Char]
show (Maybe Int -> [Char]) -> Maybe Int -> [Char]
forall a b. (a -> b) -> a -> b
$ List Name MenuScreenItem -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
listSelected List Name MenuScreenItem
_mssList)
AS ASS{AccountsScreenKind
_assKind :: AccountsScreenState -> AccountsScreenKind
_assKind :: AccountsScreenKind
_assKind,List Name AccountsScreenItem
_assList :: List Name AccountsScreenItem
_assList :: AccountsScreenState -> List Name AccountsScreenItem
_assList} -> AccountsScreenKind -> [Char]
accountsScreenKindId AccountsScreenKind
_assKind [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ ([Char] -> (Int -> [Char]) -> Maybe Int -> [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" Int -> [Char]
forall a. Show a => a -> [Char]
show (Maybe Int -> [Char]) -> Maybe Int -> [Char]
forall a b. (a -> b) -> a -> b
$ List Name AccountsScreenItem -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
listSelected List Name AccountsScreenItem
_assList)
RS RSS{GenericList Name Vector RegisterScreenItem
_rssList :: RegisterScreenState -> GenericList Name Vector RegisterScreenItem
_rssList :: GenericList Name Vector RegisterScreenItem
_rssList} -> [Char]
"R" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ ([Char] -> (Int -> [Char]) -> Maybe Int -> [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" Int -> [Char]
forall a. Show a => a -> [Char]
show (Maybe Int -> [Char]) -> Maybe Int -> [Char]
forall a b. (a -> b) -> a -> b
$ GenericList Name Vector RegisterScreenItem -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
listSelected GenericList Name Vector RegisterScreenItem
_rssList)
TS TransactionScreenState
_ -> [Char]
"T"
ES ErrorScreenState
_ -> [Char]
"E"
uiNumBlankItems :: Int
uiNumBlankItems :: Int
uiNumBlankItems
= Int
100
sendVtyEvents :: [Event] -> EventM n s ()
sendVtyEvents :: forall n s. [Event] -> EventM n s ()
sendVtyEvents [Event]
evs = do
input <- Input -> TChan InternalEvent
eventChannel (Input -> TChan InternalEvent)
-> (Vty -> Input) -> Vty -> TChan InternalEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vty -> Input
inputIface (Vty -> TChan InternalEvent)
-> EventM n s Vty -> EventM n s (TChan InternalEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> EventM n s Vty
forall n s. EventM n s Vty
getVtyHandle
liftIO $ atomically $ mapM_ (writeTChan input . InputEvent) evs
clickFocusStep :: UTCTime -> BrickEvent n e -> ClickFocus -> (ClickFocus, Bool)
clickFocusStep :: forall n e.
UTCTime -> BrickEvent n e -> ClickFocus -> (ClickFocus, Bool)
clickFocusStep UTCTime
now BrickEvent n e
ev ClickFocus
cf = case BrickEvent n e
ev of
VtyEvent Event
EvGainedFocus -> (UTCTime -> ClickFocus
FocusGainedAt UTCTime
now, Bool
True)
VtyEvent Event
EvLostFocus -> (ClickFocus
Unfocused, Bool
True)
BrickEvent n e
_ | BrickEvent n e -> Bool
forall {n} {e}. BrickEvent n e -> Bool
isLeftPress BrickEvent n e
ev -> case ClickFocus
cf of
FocusGainedAt UTCTime
t | UTCTime -> UTCTime -> NominalDiffTime
diffUTCTime UTCTime
now UTCTime
t NominalDiffTime -> NominalDiffTime -> Bool
forall a. Ord a => a -> a -> Bool
< NominalDiffTime
activatingClickTime -> (ClickFocus
IgnoringClick, Bool
True)
ClickFocus
IgnoringClick -> (ClickFocus
IgnoringClick, Bool
True)
ClickFocus
_ -> (ClickFocus
Unfocused, Bool
False)
| BrickEvent n e -> Bool
forall {n} {e}. BrickEvent n e -> Bool
isRelease BrickEvent n e
ev -> (ClickFocus
Unfocused, ClickFocus
cf ClickFocus -> ClickFocus -> Bool
forall a. Eq a => a -> a -> Bool
== ClickFocus
IgnoringClick)
| Bool
otherwise -> (ClickFocus
cf, Bool
False)
where
isLeftPress :: BrickEvent n e -> Bool
isLeftPress = \case
MouseDown n
_ Button
BLeft [Modifier]
_ Location
_ -> Bool
True
VtyEvent (EvMouseDown Int
_ Int
_ Button
BLeft [Modifier]
_) -> Bool
True
BrickEvent n e
_ -> Bool
False
isRelease :: BrickEvent n e -> Bool
isRelease = \case
MouseUp{} -> Bool
True
VtyEvent EvMouseUp{} -> Bool
True
BrickEvent n e
_ -> Bool
False
activatingClickTime :: NominalDiffTime
activatingClickTime :: NominalDiffTime
activatingClickTime = NominalDiffTime
0.2