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