ui: drop old posting register screen's code
This commit is contained in:
parent
b51f45c675
commit
3fa0ad8eb6
@ -30,7 +30,7 @@ import Hledger.UI.Options
|
|||||||
-- import Hledger.UI.Theme
|
-- import Hledger.UI.Theme
|
||||||
import Hledger.UI.UITypes
|
import Hledger.UI.UITypes
|
||||||
import Hledger.UI.UIUtils
|
import Hledger.UI.UIUtils
|
||||||
import qualified Hledger.UI.RegisterScreen2 as RS2 (screen)
|
import qualified Hledger.UI.RegisterScreen as RS (screen)
|
||||||
|
|
||||||
screen = AccountsScreen{
|
screen = AccountsScreen{
|
||||||
asState = list "accounts" V.empty 1
|
asState = list "accounts" V.empty 1
|
||||||
@ -155,7 +155,7 @@ handleAccountsScreen st@AppState{aargs=args, aScreen=scr@AccountsScreen{asState=
|
|||||||
Vty.EvKey (Vty.KChar '9') [] -> continue $ initAccountsScreen (Just acct) d $ setDepth 9 st
|
Vty.EvKey (Vty.KChar '9') [] -> continue $ initAccountsScreen (Just acct) d $ setDepth 9 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{rs2Acct=acct} st
|
let st' = screenEnter d args RS.screen{rsAcct=acct} st
|
||||||
vScrollToBeginning $ viewportScroll "register"
|
vScrollToBeginning $ viewportScroll "register"
|
||||||
continue st'
|
continue st'
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,6 @@ import Hledger.UI.UITypes
|
|||||||
import Hledger.UI.Theme
|
import Hledger.UI.Theme
|
||||||
import Hledger.UI.AccountsScreen as AS
|
import Hledger.UI.AccountsScreen as AS
|
||||||
-- import Hledger.UI.RegisterScreen as RS
|
-- import Hledger.UI.RegisterScreen as RS
|
||||||
-- import Hledger.UI.RegisterScreen2 as RS2
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
-- The register screen, showing account postings, like the CLI register command.
|
-- The account register screen, showing transactions in an account, like hledger-web's register.
|
||||||
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings, FlexibleContexts #-}
|
||||||
|
|
||||||
module Hledger.UI.RegisterScreen
|
module Hledger.UI.RegisterScreen
|
||||||
(screen)
|
(screen)
|
||||||
@ -9,90 +9,170 @@ 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.Monoid
|
||||||
|
-- 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
|
||||||
import qualified Graphics.Vty as Vty
|
import Graphics.Vty as Vty
|
||||||
import Brick
|
import Brick
|
||||||
import Brick.Widgets.List
|
import Brick.Widgets.List
|
||||||
import Brick.Widgets.Border
|
-- import Brick.Widgets.Border
|
||||||
import Brick.Widgets.Center
|
-- import Brick.Widgets.Border.Style
|
||||||
|
-- import Brick.Widgets.Center
|
||||||
|
-- import Text.Printf
|
||||||
|
|
||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli hiding (progname,prognameandversion,green)
|
import Hledger.Cli hiding (progname,prognameandversion,green)
|
||||||
import Hledger.UI.Options
|
import Hledger.UI.Options
|
||||||
|
-- import Hledger.UI.Theme
|
||||||
import Hledger.UI.UITypes
|
import Hledger.UI.UITypes
|
||||||
import Hledger.UI.UIUtils
|
import Hledger.UI.UIUtils
|
||||||
|
|
||||||
screen = RegisterScreen{
|
screen = RegisterScreen{
|
||||||
rsState = list "register" V.empty 1
|
rsState = list "register" V.empty 1
|
||||||
|
,rsAcct = ""
|
||||||
,sInitFn = initRegisterScreen
|
,sInitFn = initRegisterScreen
|
||||||
,sDrawFn = drawRegisterScreen
|
,sDrawFn = drawRegisterScreen
|
||||||
,sHandleFn = handleRegisterScreen
|
,sHandleFn = handleRegisterScreen
|
||||||
}
|
}
|
||||||
|
|
||||||
initRegisterScreen :: Day -> [String] -> AppState -> AppState
|
initRegisterScreen :: Day -> AppState -> AppState
|
||||||
initRegisterScreen d args st@AppState{aopts=opts, ajournal=j, aScreen=s@RegisterScreen{}} =
|
initRegisterScreen d st@AppState{aargs=args, aopts=opts, ajournal=j, aScreen=s@RegisterScreen{rsAcct=acct}} =
|
||||||
st{aScreen=s{rsState=is'}}
|
st{aScreen=s{rsState=l}}
|
||||||
where
|
|
||||||
is' =
|
|
||||||
listMoveTo (length items) $
|
|
||||||
list (Name "register") (V.fromList items) 1
|
|
||||||
(_label,items) = postingsReport ropts q j
|
|
||||||
where
|
where
|
||||||
|
-- gather arguments and queries
|
||||||
|
ropts = (reportopts_ $ cliopts_ opts)
|
||||||
|
{
|
||||||
|
depth_=Nothing,
|
||||||
|
query_=unwords' args,
|
||||||
|
balancetype_=HistoricalBalance
|
||||||
|
}
|
||||||
|
-- XXX temp
|
||||||
|
thisacctq = Acct $ accountNameToAccountRegex acct -- includes subs
|
||||||
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}
|
||||||
ropts = (reportopts_ cliopts)
|
|
||||||
{ query_=unwords' args }
|
-- run a transactions report, most recent last
|
||||||
cliopts = cliopts_ opts
|
q' =
|
||||||
initRegisterScreen _ _ _ = error "init function called with wrong screen type, should not happen"
|
-- ltrace "q"
|
||||||
|
q
|
||||||
|
thisacctq' =
|
||||||
|
-- ltrace "thisacctq"
|
||||||
|
thisacctq
|
||||||
|
(_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.
|
||||||
|
displayitem (_, t, _issplit, otheracctsstr, change, bal) =
|
||||||
|
(showDate $ tdate t
|
||||||
|
,tdescription t
|
||||||
|
,case splitOn ", " otheracctsstr of
|
||||||
|
[s] -> s
|
||||||
|
ss -> intercalate ", " ss
|
||||||
|
-- _ -> "<split>" -- should do this if accounts field width < 30
|
||||||
|
,showMixedAmountOneLineWithoutPrice change
|
||||||
|
,showMixedAmountOneLineWithoutPrice bal
|
||||||
|
)
|
||||||
|
displayitems = map displayitem items
|
||||||
|
|
||||||
|
-- build the List, moving the selection to the end
|
||||||
|
l = listMoveTo (length items) $
|
||||||
|
list (Name "register") (V.fromList displayitems) 1
|
||||||
|
|
||||||
|
-- (listName someList)
|
||||||
|
|
||||||
|
initRegisterScreen _ _ = error "init function called with wrong screen type, should not happen"
|
||||||
|
|
||||||
drawRegisterScreen :: AppState -> [Widget]
|
drawRegisterScreen :: AppState -> [Widget]
|
||||||
drawRegisterScreen AppState{aopts=_opts, aScreen=RegisterScreen{rsState=is}} = [ui]
|
drawRegisterScreen AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{reportopts_=_ropts@ReportOpts{query_=querystr}}},
|
||||||
|
aScreen=RegisterScreen{rsState=l,rsAcct=acct}} = [ui]
|
||||||
where
|
where
|
||||||
label = str "Posting "
|
toplabel = withAttr ("border" <> "bold") (str acct)
|
||||||
|
<+> str " transactions"
|
||||||
|
-- <+> borderQueryStr querystr -- no, account transactions report shows all transactions in the acct ?
|
||||||
|
-- <+> str " and subs"
|
||||||
|
<+> str " ("
|
||||||
<+> cur
|
<+> cur
|
||||||
<+> str " of "
|
<+> str " of "
|
||||||
<+> total
|
<+> total
|
||||||
<+> str " in this account and subaccounts" -- " <+> str query <+> "and subaccounts"
|
<+> str ")"
|
||||||
cur = str $ case is^.(listSelectedL) of
|
cur = str $ case l^.listSelectedL of
|
||||||
Nothing -> "-"
|
Nothing -> "-"
|
||||||
Just i -> show (i + 1)
|
Just i -> show (i + 1)
|
||||||
total = str $ show $ length $ is^.(listElementsL)
|
total = str $ show $ length displayitems
|
||||||
|
displayitems = V.toList $ l^.listElementsL
|
||||||
|
|
||||||
-- query = query_ $ reportopts_ $ cliopts_ opts
|
-- query = query_ $ reportopts_ $ cliopts_ opts
|
||||||
box = borderWithLabel label $
|
|
||||||
-- hLimit 25 $
|
ui = Widget Greedy Greedy $ do
|
||||||
-- vLimit 15 $
|
|
||||||
renderList is drawRegisterItem
|
-- calculate column widths, based on current available width
|
||||||
ui = box
|
c <- getContext
|
||||||
_ui = vCenter $ vBox [ hCenter box
|
let
|
||||||
, str " "
|
totalwidth = c^.availWidthL
|
||||||
, hCenter $ str "Press Esc to exit."
|
- 2 -- XXX due to margin ? shouldn't be necessary (cf UIUtils)
|
||||||
|
|
||||||
|
-- the date column is fixed width
|
||||||
|
datewidth = 10
|
||||||
|
|
||||||
|
-- multi-commodity amounts rendered on one line can be
|
||||||
|
-- arbitrarily wide. Give the two amounts as much space as
|
||||||
|
-- they need, while reserving a minimum of space for other
|
||||||
|
-- columns and whitespace. If they don't get all they need,
|
||||||
|
-- allocate it to them proportionally to their maximum widths.
|
||||||
|
whitespacewidth = 10 -- inter-column whitespace, fixed width
|
||||||
|
minnonamtcolswidth = datewidth + 2 + 2 -- date column plus at least 2 for desc and accts
|
||||||
|
maxamtswidth = max 0 (totalwidth - minnonamtcolswidth - whitespacewidth)
|
||||||
|
maxchangewidthseen = maximum' $ map (length . fourth5) displayitems
|
||||||
|
maxbalwidthseen = maximum' $ map (length . fifth5) displayitems
|
||||||
|
changewidthproportion = fromIntegral maxchangewidthseen / fromIntegral (maxchangewidthseen + maxbalwidthseen)
|
||||||
|
maxchangewidth = round $ changewidthproportion * fromIntegral maxamtswidth
|
||||||
|
maxbalwidth = maxamtswidth - maxchangewidth
|
||||||
|
changewidth = min maxchangewidth maxchangewidthseen
|
||||||
|
balwidth = min maxbalwidth maxbalwidthseen
|
||||||
|
|
||||||
|
-- assign the remaining space to the description and accounts columns
|
||||||
|
-- maxdescacctswidth = totalwidth - (whitespacewidth - 4) - changewidth - balwidth
|
||||||
|
maxdescacctswidth =
|
||||||
|
-- trace (show (totalwidth, datewidth, changewidth, balwidth, whitespacewidth)) $
|
||||||
|
max 0 (totalwidth - datewidth - changewidth - balwidth - whitespacewidth)
|
||||||
|
-- allocating proportionally.
|
||||||
|
-- descwidth' = maximum' $ map (length . second5) displayitems
|
||||||
|
-- acctswidth' = maximum' $ map (length . third5) displayitems
|
||||||
|
-- descwidthproportion = (descwidth' + acctswidth') / descwidth'
|
||||||
|
-- maxdescwidth = min (maxdescacctswidth - 7) (maxdescacctswidth / descwidthproportion)
|
||||||
|
-- maxacctswidth = maxdescacctswidth - maxdescwidth
|
||||||
|
-- descwidth = min maxdescwidth descwidth'
|
||||||
|
-- acctswidth = min maxacctswidth acctswidth'
|
||||||
|
-- allocating equally.
|
||||||
|
descwidth = maxdescacctswidth `div` 2
|
||||||
|
acctswidth = maxdescacctswidth - descwidth
|
||||||
|
colwidths = (datewidth,descwidth,acctswidth,changewidth,balwidth)
|
||||||
|
|
||||||
|
bottomlabel = borderKeysStr [
|
||||||
|
-- "up/down/pgup/pgdown/home/end: move"
|
||||||
|
"left: return to accounts"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
render $ defaultLayout toplabel bottomlabel $ renderList l (drawRegisterItem colwidths)
|
||||||
|
|
||||||
drawRegisterScreen _ = error "draw function called with wrong screen type, should not happen"
|
drawRegisterScreen _ = error "draw function called with wrong screen type, should not happen"
|
||||||
|
|
||||||
drawRegisterItem :: Bool -> PostingsReportItem -> Widget
|
drawRegisterItem :: (Int,Int,Int,Int,Int) -> Bool -> (String,String,String,String,String) -> Widget
|
||||||
drawRegisterItem sel item =
|
drawRegisterItem (datewidth,descwidth,acctswidth,changewidth,balwidth) _sel (date,desc,accts,change,bal) =
|
||||||
|
Widget Greedy Fixed $ do
|
||||||
-- (w,_) <- getViewportSize "register" -- getCurrentViewportSize
|
render $
|
||||||
-- st@AppState{aopts=opts} <- getAppState
|
str (padright datewidth $ elideRight datewidth date) <+>
|
||||||
-- let opts' = opts{width_=Just $ show w}
|
str " " <+>
|
||||||
|
str (padright descwidth $ elideRight descwidth desc) <+>
|
||||||
let selStr i = if sel
|
str " " <+>
|
||||||
then {- withAttr selectedAttr -} str $ showitem i
|
str (padright acctswidth $ elideLeft acctswidth $ accts) <+>
|
||||||
else str $ showitem i
|
str " " <+>
|
||||||
showitem (_,_,_,p,b) =
|
str (padleft changewidth $ elideLeft changewidth change) <+>
|
||||||
intercalate ", " $ map strip $ lines $
|
str " " <+>
|
||||||
postingsReportItemAsText defcliopts{width_=Just "160"} $ -- XXX
|
str (padleft balwidth $ elideLeft balwidth bal)
|
||||||
mkpostingsReportItem True True PrimaryDate Nothing p b
|
|
||||||
-- fmt = BottomAligned [
|
|
||||||
-- FormatField False (Just 20) Nothing TotalField
|
|
||||||
-- , FormatLiteral " "
|
|
||||||
-- , FormatField True (Just 2) Nothing DepthSpacerField
|
|
||||||
-- , FormatField True Nothing Nothing AccountField
|
|
||||||
-- ]
|
|
||||||
in
|
|
||||||
selStr item
|
|
||||||
|
|
||||||
handleRegisterScreen :: AppState -> Vty.Event -> EventM (Next AppState)
|
handleRegisterScreen :: AppState -> Vty.Event -> EventM (Next AppState)
|
||||||
handleRegisterScreen st@AppState{aopts=_opts,aScreen=s@RegisterScreen{rsState=is}} e = do
|
handleRegisterScreen st@AppState{aopts=_opts,aScreen=s@RegisterScreen{rsState=is}} e = do
|
||||||
|
|||||||
@ -1,189 +0,0 @@
|
|||||||
-- The register screen, showing account postings, like the CLI register command.
|
|
||||||
|
|
||||||
{-# LANGUAGE OverloadedStrings, FlexibleContexts #-}
|
|
||||||
|
|
||||||
module Hledger.UI.RegisterScreen2
|
|
||||||
(screen)
|
|
||||||
where
|
|
||||||
|
|
||||||
import Control.Lens ((^.))
|
|
||||||
-- import Control.Monad.IO.Class (liftIO)
|
|
||||||
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
|
|
||||||
import Graphics.Vty as Vty
|
|
||||||
import Brick
|
|
||||||
import Brick.Widgets.List
|
|
||||||
-- import Brick.Widgets.Border
|
|
||||||
-- import Brick.Widgets.Border.Style
|
|
||||||
-- import Brick.Widgets.Center
|
|
||||||
-- import Text.Printf
|
|
||||||
|
|
||||||
import Hledger
|
|
||||||
import Hledger.Cli hiding (progname,prognameandversion,green)
|
|
||||||
import Hledger.UI.Options
|
|
||||||
-- import Hledger.UI.Theme
|
|
||||||
import Hledger.UI.UITypes
|
|
||||||
import Hledger.UI.UIUtils
|
|
||||||
|
|
||||||
screen = RegisterScreen2{
|
|
||||||
rs2State = list "register" V.empty 1
|
|
||||||
,rs2Acct = ""
|
|
||||||
,sInitFn = initRegisterScreen2
|
|
||||||
,sDrawFn = drawRegisterScreen2
|
|
||||||
,sHandleFn = handleRegisterScreen2
|
|
||||||
}
|
|
||||||
|
|
||||||
initRegisterScreen2 :: Day -> AppState -> AppState
|
|
||||||
initRegisterScreen2 d st@AppState{aargs=args, aopts=opts, ajournal=j, aScreen=s@RegisterScreen2{rs2Acct=acct}} =
|
|
||||||
st{aScreen=s{rs2State=l}}
|
|
||||||
where
|
|
||||||
-- gather arguments and queries
|
|
||||||
ropts = (reportopts_ $ cliopts_ opts)
|
|
||||||
{
|
|
||||||
depth_=Nothing,
|
|
||||||
query_=unwords' args,
|
|
||||||
balancetype_=HistoricalBalance
|
|
||||||
}
|
|
||||||
-- XXX temp
|
|
||||||
thisacctq = Acct $ accountNameToAccountRegex acct -- includes subs
|
|
||||||
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
|
|
||||||
q' =
|
|
||||||
-- ltrace "q"
|
|
||||||
q
|
|
||||||
thisacctq' =
|
|
||||||
-- ltrace "thisacctq"
|
|
||||||
thisacctq
|
|
||||||
(_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.
|
|
||||||
displayitem (_, t, _issplit, otheracctsstr, change, bal) =
|
|
||||||
(showDate $ tdate t
|
|
||||||
,tdescription t
|
|
||||||
,case splitOn ", " otheracctsstr of
|
|
||||||
[s] -> s
|
|
||||||
ss -> intercalate ", " ss
|
|
||||||
-- _ -> "<split>" -- should do this if accounts field width < 30
|
|
||||||
,showMixedAmountOneLineWithoutPrice change
|
|
||||||
,showMixedAmountOneLineWithoutPrice bal
|
|
||||||
)
|
|
||||||
displayitems = map displayitem items
|
|
||||||
|
|
||||||
-- build the List, moving the selection to the end
|
|
||||||
l = listMoveTo (length items) $
|
|
||||||
list (Name "register") (V.fromList displayitems) 1
|
|
||||||
|
|
||||||
-- (listName someList)
|
|
||||||
|
|
||||||
initRegisterScreen2 _ _ = error "init function called with wrong screen type, should not happen"
|
|
||||||
|
|
||||||
drawRegisterScreen2 :: AppState -> [Widget]
|
|
||||||
drawRegisterScreen2 AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{reportopts_=_ropts@ReportOpts{query_=querystr}}},
|
|
||||||
aScreen=RegisterScreen2{rs2State=l,rs2Acct=acct}} = [ui]
|
|
||||||
where
|
|
||||||
toplabel = withAttr ("border" <> "bold") (str acct)
|
|
||||||
<+> str " transactions"
|
|
||||||
-- <+> borderQueryStr querystr -- no, account transactions report shows all transactions in the acct ?
|
|
||||||
-- <+> str " and subs"
|
|
||||||
<+> str " ("
|
|
||||||
<+> cur
|
|
||||||
<+> str " of "
|
|
||||||
<+> total
|
|
||||||
<+> str ")"
|
|
||||||
cur = str $ case l^.listSelectedL of
|
|
||||||
Nothing -> "-"
|
|
||||||
Just i -> show (i + 1)
|
|
||||||
total = str $ show $ length displayitems
|
|
||||||
displayitems = V.toList $ l^.listElementsL
|
|
||||||
|
|
||||||
-- query = query_ $ reportopts_ $ cliopts_ opts
|
|
||||||
|
|
||||||
ui = Widget Greedy Greedy $ do
|
|
||||||
|
|
||||||
-- calculate column widths, based on current available width
|
|
||||||
c <- getContext
|
|
||||||
let
|
|
||||||
totalwidth = c^.availWidthL
|
|
||||||
- 2 -- XXX due to margin ? shouldn't be necessary (cf UIUtils)
|
|
||||||
|
|
||||||
-- the date column is fixed width
|
|
||||||
datewidth = 10
|
|
||||||
|
|
||||||
-- multi-commodity amounts rendered on one line can be
|
|
||||||
-- arbitrarily wide. Give the two amounts as much space as
|
|
||||||
-- they need, while reserving a minimum of space for other
|
|
||||||
-- columns and whitespace. If they don't get all they need,
|
|
||||||
-- allocate it to them proportionally to their maximum widths.
|
|
||||||
whitespacewidth = 10 -- inter-column whitespace, fixed width
|
|
||||||
minnonamtcolswidth = datewidth + 2 + 2 -- date column plus at least 2 for desc and accts
|
|
||||||
maxamtswidth = max 0 (totalwidth - minnonamtcolswidth - whitespacewidth)
|
|
||||||
maxchangewidthseen = maximum' $ map (length . fourth5) displayitems
|
|
||||||
maxbalwidthseen = maximum' $ map (length . fifth5) displayitems
|
|
||||||
changewidthproportion = fromIntegral maxchangewidthseen / fromIntegral (maxchangewidthseen + maxbalwidthseen)
|
|
||||||
maxchangewidth = round $ changewidthproportion * fromIntegral maxamtswidth
|
|
||||||
maxbalwidth = maxamtswidth - maxchangewidth
|
|
||||||
changewidth = min maxchangewidth maxchangewidthseen
|
|
||||||
balwidth = min maxbalwidth maxbalwidthseen
|
|
||||||
|
|
||||||
-- assign the remaining space to the description and accounts columns
|
|
||||||
-- maxdescacctswidth = totalwidth - (whitespacewidth - 4) - changewidth - balwidth
|
|
||||||
maxdescacctswidth =
|
|
||||||
-- trace (show (totalwidth, datewidth, changewidth, balwidth, whitespacewidth)) $
|
|
||||||
max 0 (totalwidth - datewidth - changewidth - balwidth - whitespacewidth)
|
|
||||||
-- allocating proportionally.
|
|
||||||
-- descwidth' = maximum' $ map (length . second5) displayitems
|
|
||||||
-- acctswidth' = maximum' $ map (length . third5) displayitems
|
|
||||||
-- descwidthproportion = (descwidth' + acctswidth') / descwidth'
|
|
||||||
-- maxdescwidth = min (maxdescacctswidth - 7) (maxdescacctswidth / descwidthproportion)
|
|
||||||
-- maxacctswidth = maxdescacctswidth - maxdescwidth
|
|
||||||
-- descwidth = min maxdescwidth descwidth'
|
|
||||||
-- acctswidth = min maxacctswidth acctswidth'
|
|
||||||
-- allocating equally.
|
|
||||||
descwidth = maxdescacctswidth `div` 2
|
|
||||||
acctswidth = maxdescacctswidth - descwidth
|
|
||||||
colwidths = (datewidth,descwidth,acctswidth,changewidth,balwidth)
|
|
||||||
|
|
||||||
bottomlabel = borderKeysStr [
|
|
||||||
-- "up/down/pgup/pgdown/home/end: move"
|
|
||||||
"left: return to accounts"
|
|
||||||
]
|
|
||||||
|
|
||||||
render $ defaultLayout toplabel bottomlabel $ renderList l (drawRegisterItem colwidths)
|
|
||||||
|
|
||||||
drawRegisterScreen2 _ = error "draw function called with wrong screen type, should not happen"
|
|
||||||
|
|
||||||
drawRegisterItem :: (Int,Int,Int,Int,Int) -> Bool -> (String,String,String,String,String) -> Widget
|
|
||||||
drawRegisterItem (datewidth,descwidth,acctswidth,changewidth,balwidth) _sel (date,desc,accts,change,bal) =
|
|
||||||
Widget Greedy Fixed $ do
|
|
||||||
render $
|
|
||||||
str (padright datewidth $ elideRight datewidth date) <+>
|
|
||||||
str " " <+>
|
|
||||||
str (padright descwidth $ elideRight descwidth desc) <+>
|
|
||||||
str " " <+>
|
|
||||||
str (padright acctswidth $ elideLeft acctswidth $ accts) <+>
|
|
||||||
str " " <+>
|
|
||||||
str (padleft changewidth $ elideLeft changewidth change) <+>
|
|
||||||
str " " <+>
|
|
||||||
str (padleft balwidth $ elideLeft balwidth bal)
|
|
||||||
|
|
||||||
handleRegisterScreen2 :: AppState -> Vty.Event -> EventM (Next AppState)
|
|
||||||
handleRegisterScreen2 st@AppState{aopts=_opts,aScreen=s@RegisterScreen2{rs2State=is}} e = do
|
|
||||||
case e of
|
|
||||||
Vty.EvKey Vty.KEsc [] -> halt st
|
|
||||||
Vty.EvKey (Vty.KChar 'q') [] -> halt st
|
|
||||||
Vty.EvKey (Vty.KLeft) [] -> continue $ popScreen st
|
|
||||||
-- Vty.EvKey (Vty.KRight) [] -> error (show curItem) where curItem = listSelectedElement is
|
|
||||||
-- fall through to the list's event handler (handles [pg]up/down)
|
|
||||||
ev -> do
|
|
||||||
is' <- handleEvent ev is
|
|
||||||
continue st{aScreen=s{rs2State=is'}}
|
|
||||||
-- continue =<< handleEventLensed st someLens ev
|
|
||||||
handleRegisterScreen2 _ _ = error "event handler called with wrong screen type, should not happen"
|
|
||||||
@ -31,14 +31,8 @@ data Screen =
|
|||||||
,sDrawFn :: AppState -> [Widget] -- ^ brick renderer to use for this screen
|
,sDrawFn :: AppState -> [Widget] -- ^ brick renderer to use for this screen
|
||||||
}
|
}
|
||||||
| RegisterScreen {
|
| RegisterScreen {
|
||||||
rsState :: List PostingsReportItem
|
rsState :: List (String,String,String,String,String)
|
||||||
,sInitFn :: Day -> AppState -> AppState
|
,rsAcct :: AccountName -- ^ the account we are showing a register for
|
||||||
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState)
|
|
||||||
,sDrawFn :: AppState -> [Widget]
|
|
||||||
}
|
|
||||||
| RegisterScreen2 {
|
|
||||||
rs2State :: List (String,String,String,String,String)
|
|
||||||
,rs2Acct :: AccountName -- ^ the account we are showing a register for
|
|
||||||
,sInitFn :: Day -> AppState -> AppState
|
,sInitFn :: Day -> AppState -> AppState
|
||||||
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState)
|
,sHandleFn :: AppState -> V.Event -> EventM (Next AppState)
|
||||||
,sDrawFn :: AppState -> [Widget]
|
,sDrawFn :: AppState -> [Widget]
|
||||||
|
|||||||
@ -80,6 +80,5 @@ executable hledger-ui
|
|||||||
Hledger.UI.UITypes
|
Hledger.UI.UITypes
|
||||||
Hledger.UI.UIUtils
|
Hledger.UI.UIUtils
|
||||||
Hledger.UI.AccountsScreen
|
Hledger.UI.AccountsScreen
|
||||||
Hledger.UI.RegisterScreen
|
|
||||||
Hledger.UI.RegisterScreen2
|
Hledger.UI.RegisterScreen2
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user