haddock fixes
This commit is contained in:
parent
68682fa0ee
commit
59c9dde458
51
UICommand.hs
51
UICommand.hs
@ -21,29 +21,32 @@ helpmsg = "Welcome to hledger. (b)alances, (r)egister, (p)rint entries, (l)edger
|
|||||||
|
|
||||||
instance Show Vty where show v = "a Vty"
|
instance Show Vty where show v = "a Vty"
|
||||||
|
|
||||||
|
-- | The application state when running the ui command.
|
||||||
data AppState = AppState {
|
data AppState = AppState {
|
||||||
av :: Vty -- the vty context
|
av :: Vty -- ^ the vty context
|
||||||
,aw :: Int -- window width
|
,aw :: Int -- ^ window width
|
||||||
,ah :: Int -- window height
|
,ah :: Int -- ^ window height
|
||||||
,amsg :: String -- status message
|
,amsg :: String -- ^ status message
|
||||||
,aopts :: [Opt] -- command-line opts
|
,aopts :: [Opt] -- ^ command-line opts
|
||||||
,aargs :: [String] -- command-line args
|
,aargs :: [String] -- ^ command-line args
|
||||||
,aledger :: Ledger -- parsed ledger
|
,aledger :: Ledger -- ^ parsed ledger
|
||||||
,abuf :: [String] -- lines of the current buffered view
|
,abuf :: [String] -- ^ lines of the current buffered view
|
||||||
,alocs :: [Loc] -- user's navigation trail within the UI
|
,alocs :: [Loc] -- ^ user's navigation trail within the UI
|
||||||
-- never null, head is current location
|
-- ^ never null, head is current location
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
-- | A location within the user interface.
|
||||||
data Loc = Loc {
|
data Loc = Loc {
|
||||||
scr :: Screen -- ui screen
|
scr :: Screen -- ^ one of the available screens
|
||||||
,sy :: Int -- viewport y scroll position
|
,sy :: Int -- ^ viewport y scroll position
|
||||||
,cy :: Int -- cursor y position
|
,cy :: Int -- ^ cursor y position
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
data Screen = BalanceScreen -- like "hledger balance".. shows accounts
|
-- | The screens available within the user interface.
|
||||||
| RegisterScreen -- like "hledger register".. shows transactions
|
data Screen = BalanceScreen -- ^ like hledger balance, shows accounts
|
||||||
| PrintScreen -- like "hledger print".. shows entries
|
| RegisterScreen -- ^ like hledger register, shows transactions
|
||||||
| LedgerScreen -- shows the raw ledger
|
| PrintScreen -- ^ like hledger print, shows entries
|
||||||
|
| LedgerScreen -- ^ shows the raw ledger
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
-- | Run the interactive text ui.
|
-- | Run the interactive text ui.
|
||||||
@ -131,20 +134,25 @@ updateCursorY f a = setCursorY (f $ cursorY a) a
|
|||||||
updateScrollY f a = setScrollY (f $ scrollY a) a
|
updateScrollY f a = setScrollY (f $ scrollY a) a
|
||||||
updatePosY f a = setPosY (f $ posY a) a
|
updatePosY f a = setPosY (f $ posY a) a
|
||||||
|
|
||||||
|
resize :: Int -> Int -> AppState -> AppState
|
||||||
resize x y a = setCursorY cy' a{aw=x,ah=y}
|
resize x y a = setCursorY cy' a{aw=x,ah=y}
|
||||||
where
|
where
|
||||||
cy = cursorY a
|
cy = cursorY a
|
||||||
cy' = min cy (y-2)
|
cy' = min cy (y-2)
|
||||||
|
|
||||||
|
moveToTop :: AppState -> AppState
|
||||||
moveToTop a = setPosY 0 a
|
moveToTop a = setPosY 0 a
|
||||||
|
|
||||||
|
moveToBottom :: AppState -> AppState
|
||||||
moveToBottom a = setPosY (length $ abuf a) a
|
moveToBottom a = setPosY (length $ abuf a) a
|
||||||
|
|
||||||
|
moveUpAndPushEdge :: AppState -> AppState
|
||||||
moveUpAndPushEdge a@AppState{alocs=(Loc{sy=sy,cy=cy}:_)}
|
moveUpAndPushEdge a@AppState{alocs=(Loc{sy=sy,cy=cy}:_)}
|
||||||
| cy > 0 = updateCursorY (subtract 1) a
|
| cy > 0 = updateCursorY (subtract 1) a
|
||||||
| sy > 0 = updateScrollY (subtract 1) a
|
| sy > 0 = updateScrollY (subtract 1) a
|
||||||
| otherwise = a
|
| otherwise = a
|
||||||
|
|
||||||
|
moveDownAndPushEdge :: AppState -> AppState
|
||||||
moveDownAndPushEdge a@AppState{alocs=(Loc{sy=sy,cy=cy}:_)}
|
moveDownAndPushEdge a@AppState{alocs=(Loc{sy=sy,cy=cy}:_)}
|
||||||
| sy+cy >= bh = a
|
| sy+cy >= bh = a
|
||||||
| cy < ph-1 = updateCursorY (+1) a
|
| cy < ph-1 = updateCursorY (+1) a
|
||||||
@ -156,6 +164,7 @@ moveDownAndPushEdge a@AppState{alocs=(Loc{sy=sy,cy=cy}:_)}
|
|||||||
-- | Scroll down by page height or until we can just see the last line,
|
-- | Scroll down by page height or until we can just see the last line,
|
||||||
-- without moving the cursor, or if we are already scrolled as far as
|
-- without moving the cursor, or if we are already scrolled as far as
|
||||||
-- possible then move the cursor to the last line.
|
-- possible then move the cursor to the last line.
|
||||||
|
nextpage :: AppState -> AppState
|
||||||
nextpage (a@AppState{abuf=b})
|
nextpage (a@AppState{abuf=b})
|
||||||
| sy < bh-jump = setScrollY sy' a
|
| sy < bh-jump = setScrollY sy' a
|
||||||
| otherwise = setCursorY (bh-sy) a
|
| otherwise = setCursorY (bh-sy) a
|
||||||
@ -168,6 +177,7 @@ nextpage (a@AppState{abuf=b})
|
|||||||
-- | Scroll up by page height or until we can just see the first line,
|
-- | Scroll up by page height or until we can just see the first line,
|
||||||
-- without moving the cursor, or if we are scrolled as far as possible
|
-- without moving the cursor, or if we are scrolled as far as possible
|
||||||
-- then move the cursor to the first line.
|
-- then move the cursor to the first line.
|
||||||
|
prevpage :: AppState -> AppState
|
||||||
prevpage (a@AppState{abuf=b})
|
prevpage (a@AppState{abuf=b})
|
||||||
| sy > 0 = setScrollY sy' a
|
| sy > 0 = setScrollY sy' a
|
||||||
| otherwise = setCursorY 0 a
|
| otherwise = setCursorY 0 a
|
||||||
@ -206,7 +216,7 @@ enter scr@LedgerScreen a = updateData $ pushLoc Loc{scr=scr,sy=0,cy=0} a
|
|||||||
|
|
||||||
resetTrailAndEnter scr a = enter scr $ clearLocs a
|
resetTrailAndEnter scr a = enter scr $ clearLocs a
|
||||||
|
|
||||||
-- | Regenerate the display data based on current UI location.
|
-- | Regenerate the display data appropriate for the current screen.
|
||||||
updateData :: AppState -> AppState
|
updateData :: AppState -> AppState
|
||||||
updateData a@AppState{aopts=opts,aargs=args,aledger=l}
|
updateData a@AppState{aopts=opts,aargs=args,aledger=l}
|
||||||
| scr == BalanceScreen = a{abuf=lines $ showBalanceReport opts [] l, aargs=[]}
|
| scr == BalanceScreen = a{abuf=lines $ showBalanceReport opts [] l, aargs=[]}
|
||||||
@ -252,9 +262,8 @@ accountNameAt buf lineno = accountNameFromComponents anamecomponents
|
|||||||
myindent = indentof x
|
myindent = indentof x
|
||||||
indentof = length . takeWhile (==' ')
|
indentof = length . takeWhile (==' ')
|
||||||
|
|
||||||
-- currentEntry/scrollToEntry doesn't work
|
|
||||||
-- | If on the print screen, move the cursor to highlight the specified entry
|
-- | If on the print screen, move the cursor to highlight the specified entry
|
||||||
-- (or a reasonable guess).
|
-- (or a reasonable guess). Doesn't work.
|
||||||
scrollToEntry :: Entry -> AppState -> AppState
|
scrollToEntry :: Entry -> AppState -> AppState
|
||||||
scrollToEntry e a@AppState{abuf=buf} = setCursorY cy $ setScrollY sy a
|
scrollToEntry e a@AppState{abuf=buf} = setCursorY cy $ setScrollY sy a
|
||||||
where
|
where
|
||||||
@ -266,7 +275,7 @@ scrollToEntry e a@AppState{abuf=buf} = setCursorY cy $ setScrollY sy a
|
|||||||
|
|
||||||
-- | Get the entry containing the transaction currently highlighted by the
|
-- | Get the entry containing the transaction currently highlighted by the
|
||||||
-- cursor on the register screen (or best guess). Results undefined while
|
-- cursor on the register screen (or best guess). Results undefined while
|
||||||
-- on other screens.
|
-- on other screens. Doesn't work.
|
||||||
currentEntry :: AppState -> Entry
|
currentEntry :: AppState -> Entry
|
||||||
currentEntry a@AppState{aledger=l,abuf=buf} = entryContainingTransaction a t
|
currentEntry a@AppState{aledger=l,abuf=buf} = entryContainingTransaction a t
|
||||||
where
|
where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user