From db62fbb542426d19d840fcb77e4b158c8afc182e Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 5 Mar 2020 16:45:40 -0500 Subject: [PATCH] output report to a text file (report.txt) --- ChangeLog.md | 1 + src/Mtlstats/Config.hs | 8 ++++++++ src/Mtlstats/Control/NewGame.hs | 13 +++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 344232d..61a10d3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,7 @@ ## current - Fixed a bug that was causing shutouts to not be recorded +- Output report to a text file (report.txt) ## 0.13.0 - Added autocomplete to player position prompt diff --git a/src/Mtlstats/Config.hs b/src/Mtlstats/Config.hs index 5b8423a..db1dc1a 100644 --- a/src/Mtlstats/Config.hs +++ b/src/Mtlstats/Config.hs @@ -44,3 +44,11 @@ maxAssists = 2 -- | The length of a typical game (in minutes) gameLength :: Int gameLength = 60 + +-- | Report output filename +reportFilename :: FilePath +reportFilename = "report.txt" + +-- | Number of columns in report file +reportCols :: Int +reportCols = 79 diff --git a/src/Mtlstats/Control/NewGame.hs b/src/Mtlstats/Control/NewGame.hs index a788862..0dd424b 100644 --- a/src/Mtlstats/Control/NewGame.hs +++ b/src/Mtlstats/Control/NewGame.hs @@ -21,13 +21,15 @@ along with this program. If not, see . module Mtlstats.Control.NewGame (newGameC) where -import Control.Monad.Trans.State (gets, modify) +import Control.Monad.IO.Class (liftIO) +import Control.Monad.Trans.State (get, gets, modify) import Data.Maybe (fromJust, fromMaybe, isJust) import Lens.Micro ((^.), (.~)) import qualified UI.NCurses as C import Mtlstats.Actions import Mtlstats.Actions.NewGame +import Mtlstats.Config import Mtlstats.Control.NewGame.GoalieInput import Mtlstats.Format import Mtlstats.Handlers @@ -211,9 +213,12 @@ reportC = Controller C.EventSpecialKey C.KeyUpArrow -> modify scrollUp C.EventSpecialKey C.KeyDownArrow -> modify scrollDown C.EventSpecialKey C.KeyHome -> modify $ scrollOffset .~ 0 - C.EventSpecialKey _ -> modify backHome - C.EventCharacter _ -> modify backHome - _ -> return () + + C.EventCharacter '\n' -> do + get >>= liftIO . writeFile reportFilename . unlines . report reportCols + modify backHome + + _ -> return () return True }