enable scrolling of report

This commit is contained in:
Jonathan Lamothe
2019-10-11 23:13:00 -04:00
parent db8bbd9786
commit a91ed5afb3
6 changed files with 89 additions and 17 deletions

View File

@@ -37,6 +37,7 @@ module Mtlstats.Actions
, awardAssist
, resetGoalData
, assignPMins
, backHome
) where
import Control.Monad.Trans.State (modify)
@@ -229,3 +230,10 @@ assignPMins mins s = fromMaybe s $ do
(psPMin +~ mins)
)
. (selectedPlayer .~ Nothing)
-- | Resets the program state back to the main menu
backHome :: ProgState -> ProgState
backHome
= (progMode .~ MainMenu)
. (inputBuffer .~ "")
. (scrollOffset .~ 0)

View File

@@ -25,7 +25,7 @@ import Control.Monad (join, when)
import Control.Monad.Trans.State (gets, modify)
import Data.Char (toUpper)
import Data.Maybe (fromJust, fromMaybe, isJust)
import Lens.Micro ((^.), (.~))
import Lens.Micro ((^.), (.~), (%~))
import Lens.Micro.Extras (view)
import qualified UI.NCurses as C
@@ -270,16 +270,20 @@ getPMinsC = Controller
reportC :: Controller
reportC = Controller
{ drawController = \s -> do
(_, cols) <- C.windowSize
C.drawString $ report (fromInteger $ pred cols) s
(rows, cols) <- C.windowSize
C.drawString $ unlines $ slice
(s^.scrollOffset)
(fromInteger $ pred rows)
(report (fromInteger $ pred cols) s)
return C.CursorInvisible
, handleController = \e -> do
when
(case e of
C.EventCharacter _ -> True
C.EventSpecialKey _ -> True
_ -> False) $
modify $ progMode .~ MainMenu
case e of
C.EventSpecialKey C.KeyUpArrow -> modify $ scrollOffset %~ pred
C.EventSpecialKey C.KeyDownArrow -> modify $ scrollOffset %~ succ
C.EventSpecialKey C.KeyHome -> modify $ scrollOffset .~ 0
C.EventSpecialKey _ -> modify backHome
C.EventCharacter _ -> modify backHome
_ -> return ()
return True
}

View File

@@ -36,14 +36,14 @@ report
-- ^ The number of columns for the report
-> ProgState
-- ^ The program state
-> String
-> [String]
report width s
= standingsReport width s
++ "\n"
++ [""]
++ gameStatsReport width s
standingsReport :: Int -> ProgState -> String
standingsReport width s = unlines $ fromMaybe [] $ do
standingsReport :: Int -> ProgState -> [String]
standingsReport width s = fromMaybe [] $ do
let
db = s^.database
gs = s^.progMode.gameStateL
@@ -88,8 +88,8 @@ standingsReport width s = unlines $ fromMaybe [] $ do
++ showStats tStats
]
gameStatsReport :: Int -> ProgState -> String
gameStatsReport width s = unlines $ fromMaybe [] $ do
gameStatsReport :: Int -> ProgState -> [String]
gameStatsReport width s = fromMaybe [] $ do
pStats <- mapM
(\(pid, stats) -> do
p <- nth pid $ s^.database.dbPlayers

View File

@@ -19,7 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
-}
module Mtlstats.Util (nth, modifyNth, updateMap) where
module Mtlstats.Util (nth, modifyNth, updateMap, slice) where
import qualified Data.Map as M
@@ -64,3 +64,14 @@ updateMap
updateMap k def f m = let
x = M.findWithDefault def k m
in M.insert k (f x) m
-- | Selects a section of a list
slice
:: Int
-- ^ The index to start at
-> Int
-- ^ The number of elements to take
-> [a]
-- ^ The list to take a subset of
-> [a]
slice offset len = take len . drop offset