mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-27 04:13:11 +03:00
ui: reg: track current account better, nicer title
This commit is contained in:
parent
055d820ec7
commit
db83ff1000
@ -104,7 +104,7 @@ drawAccountsItem fmt _sel item =
|
||||
render $ str $ showitem item
|
||||
|
||||
handleAccountsScreen :: AppState -> Vty.Event -> EventM (Next AppState)
|
||||
handleAccountsScreen st@AppState{aScreen=scr@AccountsScreen{asState=is}} e = do
|
||||
handleAccountsScreen st@AppState{aargs=args, aScreen=scr@AccountsScreen{asState=is}} e = do
|
||||
d <- liftIO getCurrentDay
|
||||
-- c <- getContext
|
||||
-- let h = c^.availHeightL
|
||||
@ -114,13 +114,13 @@ handleAccountsScreen st@AppState{aScreen=scr@AccountsScreen{asState=is}} e = do
|
||||
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
||||
Vty.EvKey (Vty.KLeft) [] -> continue $ popScreen st
|
||||
Vty.EvKey (Vty.KRight) [] -> do
|
||||
let st' = screenEnter d args RS2.screen st
|
||||
let st' = screenEnter d args RS2.screen{rs2Acct=acct} st
|
||||
vScrollToBeginning $ viewportScroll "register"
|
||||
continue st'
|
||||
where
|
||||
args = case listSelectedElement is of
|
||||
Just (_, ((acct, _, _), _)) -> ["acct:"++accountNameToAccountRegex acct]
|
||||
Nothing -> []
|
||||
acct = case listSelectedElement is of
|
||||
Just (_, ((a, _, _), _)) -> a
|
||||
Nothing -> ""
|
||||
|
||||
-- Vty.EvKey (Vty.KPageDown) [] -> continue $ st{aScreen=scr{asState=moveSel h is}}
|
||||
-- Vty.EvKey (Vty.KPageUp) [] -> continue $ st{aScreen=scr{asState=moveSel (-h) is}}
|
||||
|
@ -8,8 +8,9 @@ where
|
||||
|
||||
import Control.Lens ((^.))
|
||||
-- import Control.Monad.IO.Class (liftIO)
|
||||
-- import Data.List
|
||||
import Data.List
|
||||
import Data.List.Split (splitOn)
|
||||
import Data.Monoid
|
||||
-- import Data.Maybe
|
||||
import Data.Time.Calendar (Day)
|
||||
import qualified Data.Vector as V
|
||||
@ -30,13 +31,14 @@ import Hledger.UI.UIUtils
|
||||
|
||||
screen = RegisterScreen2{
|
||||
rs2State = list "register" V.empty 1
|
||||
,rs2Acct = ""
|
||||
,sInitFn = initRegisterScreen2
|
||||
,sDrawFn = drawRegisterScreen2
|
||||
,sHandleFn = handleRegisterScreen2
|
||||
}
|
||||
|
||||
initRegisterScreen2 :: Day -> [String] -> AppState -> AppState
|
||||
initRegisterScreen2 d args st@AppState{aopts=opts, ajournal=j, aScreen=s@RegisterScreen2{}} =
|
||||
initRegisterScreen2 d args st@AppState{aopts=opts, ajournal=j, aScreen=s@RegisterScreen2{rs2Acct=acct}} =
|
||||
st{aScreen=s{rs2State=l}}
|
||||
where
|
||||
-- gather arguments and queries
|
||||
@ -46,14 +48,13 @@ initRegisterScreen2 d args st@AppState{aopts=opts, ajournal=j, aScreen=s@Registe
|
||||
balancetype_=HistoricalBalance
|
||||
}
|
||||
-- XXX temp
|
||||
curacct = drop 5 $ head args -- should be "acct:..."
|
||||
thisacctq = Acct $ curacct -- XXX why is this excluding subs: accountNameToAccountRegex curacct
|
||||
thisacctq = Acct $ accountNameToAccountRegex acct -- XXX why is this excluding subs: accountNameToAccountRegex curacct
|
||||
q = queryFromOpts d ropts
|
||||
-- query_="cur:\\$"} -- XXX limit to one commodity to ensure one-line items
|
||||
--{query_=unwords' $ locArgs l}
|
||||
|
||||
-- run a transactions report, most recent last
|
||||
(_label,items') = accountTransactionsReport ropts j thisacctq q
|
||||
(_label,items') = accountTransactionsReport ropts j q thisacctq
|
||||
items = reverse items'
|
||||
|
||||
-- pre-render all items; these will be the List elements. This helps calculate column widths.
|
||||
@ -78,13 +79,18 @@ initRegisterScreen2 d args st@AppState{aopts=opts, ajournal=j, aScreen=s@Registe
|
||||
initRegisterScreen2 _ _ _ = error "init function called with wrong screen type, should not happen"
|
||||
|
||||
drawRegisterScreen2 :: AppState -> [Widget]
|
||||
drawRegisterScreen2 AppState{aopts=_opts, aScreen=RegisterScreen2{rs2State=l}} = [ui]
|
||||
drawRegisterScreen2 AppState{aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{reportopts_=_ropts@ReportOpts{query_=querystr}}},
|
||||
aargs=_args, aScreen=RegisterScreen2{rs2State=l,rs2Acct=acct}} = [ui]
|
||||
where
|
||||
label = str "Transaction "
|
||||
label = str "Transactions in "
|
||||
<+> withAttr ("border" <> "bold") (str acct)
|
||||
<+> borderQuery querystr
|
||||
-- <+> str " and subs"
|
||||
<+> str " ("
|
||||
<+> cur
|
||||
<+> str " of "
|
||||
<+> total
|
||||
<+> str " to/from this account" -- " <+> str query <+> "and subaccounts"
|
||||
<+> str ")"
|
||||
cur = str $ case l^.listSelectedL of
|
||||
Nothing -> "-"
|
||||
Just i -> show (i + 1)
|
||||
|
@ -22,7 +22,7 @@ data AppState = AppState {
|
||||
|
||||
-- | Types of screen available within the app, along with their state.
|
||||
-- Screen types are distinguished by their constructor and by the type
|
||||
-- of their state (hence the unique accessor names for the latter).
|
||||
-- of their state (which must have unique accessor names).
|
||||
data Screen =
|
||||
AccountsScreen {
|
||||
asState :: List BalanceReportItem -- ^ the screen's state (data being displayed and widget state)
|
||||
@ -38,6 +38,7 @@ data Screen =
|
||||
}
|
||||
| RegisterScreen2 {
|
||||
rs2State :: List (String,String,String,String,String)
|
||||
,rs2Acct :: AccountName -- ^ the account we are showing a register for
|
||||
,sInitFn :: Day -> [String] -> AppState -> AppState
|
||||
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState)
|
||||
,sDrawFn :: AppState -> [Widget]
|
||||
|
Loading…
Reference in New Issue
Block a user