Compare commits

...

8 Commits

Author SHA1 Message Date
Jonathan Lamothe 2d5c4e6471 fixed spacing on title screen 2023-05-30 19:01:30 -04:00
Jonathan Lamothe 097d51f34b properly centre menu headings 2023-05-30 18:56:44 -04:00
Jonathan Lamothe 166483dc50 fixed missing blank line between menu header and options 2023-05-30 18:45:03 -04:00
Jonathan Lamothe 08e0f96a81 cursor position fix
cursor X and Y coordinates were transposed for the simple string prompts
2023-05-30 18:30:49 -04:00
Jonathan Lamothe afae5ea14a updated ChangeLog 2023-05-30 18:21:56 -04:00
Jonathan Lamothe ea9a9c6a85 bugfix: backspace
backspace functionality was mistakenly mapped to the escape key for some reason
2023-05-30 18:11:54 -04:00
Jonathan Lamothe d40b56da37 bail on CTRL-C 2023-05-30 18:06:32 -04:00
Jonathan Lamothe 5ea2d77921 bugfix: make the whole background blue 2023-05-30 17:58:45 -04:00
6 changed files with 38 additions and 12 deletions

View File

@ -1,5 +1,8 @@
# Changelog for mtlstats
## current
- updated code to use brick instead of ncurses
## 0.16.1
- Don't automatically start a new game on new season

View File

@ -22,9 +22,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats (app) where
import Brick.AttrMap (AttrMap, forceAttrMap)
import Brick.Main (App (..), showFirstCursor)
import Brick.Main (App (..), halt, showFirstCursor)
import Brick.Types (BrickEvent (VtyEvent), Widget)
import Brick.Util (on)
import Brick.Widgets.Core (fill)
import Graphics.Vty.Attributes.Color (blue, white)
import Graphics.Vty.Input.Events
( Event (EvKey)
, Modifier (MCtrl)
, Key (KChar)
)
import Lens.Micro (to)
import Lens.Micro.Mtl (use)
@ -34,14 +41,21 @@ import Mtlstats.Types
-- | The main application
app :: App ProgState () ()
app = App
{ appDraw = \s -> [drawController (dispatch s) s]
{ appDraw = draw
, appChooseCursor = showFirstCursor
, appHandleEvent = handler
, appStartEvent = return ()
, appAttrMap = const myAttrMap
}
draw :: ProgState -> [Widget ()]
draw s =
[ drawController (dispatch s) s
, fill ' '
]
handler :: Handler ()
handler (VtyEvent (EvKey (KChar 'c') [MCtrl])) = halt
handler e = do
c <- use (to dispatch)
handleController c e

View File

@ -24,18 +24,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Control.TitleScreen (titleScreenC) where
import Brick.Types (BrickEvent (VtyEvent))
import Brick.Widgets.Center (hCenter)
import Brick.Widgets.Core (str, vBox)
import Control.Monad.State.Class (modify)
import Data.Char (chr)
import Graphics.Vty.Input.Events (Event (EvKey))
import Mtlstats.Actions
import Mtlstats.Types
import Mtlstats.Util
titleScreenC :: Controller
titleScreenC = Controller
{ drawController = const $ vBox $ map (hCenter . str)
{ drawController = const $ linesToWidgetC
$ [ ""
, "MONTREAL CANADIENS STATISTICS"
]

View File

@ -36,8 +36,6 @@ module Mtlstats.Menu (
import Brick.Main (halt)
import Brick.Types (BrickEvent (VtyEvent), Widget)
import Brick.Widgets.Center (hCenter)
import Brick.Widgets.Core (str, vBox)
import Control.Monad.State.Class (gets, modify)
import Data.Char (toUpper)
import qualified Data.Map as M
@ -87,7 +85,7 @@ menuStateController menuFunc = Controller
drawMenu :: Menu a -> Widget ()
drawMenu m = let
menuLines = lines $ show m
in hCenter $ vBox $ map str menuLines
in linesToWidgetC menuLines
-- | The event handler for a 'Menu'
menuHandler :: Menu a -> Handler a

View File

@ -57,7 +57,7 @@ import Data.Char (isAlphaNum, isDigit, toUpper)
import Graphics.Text.Width (safeWcswidth)
import Graphics.Vty.Input.Events
( Event (EvKey)
, Key (KChar, KEnter, KEsc, KFun)
, Key (KBS, KChar, KEnter, KFun)
)
import Lens.Micro ((^.), (&), (.~), (?~), (%~))
import Lens.Micro.Mtl ((.=), use)
@ -77,7 +77,7 @@ promptHandler p (VtyEvent (EvKey KEnter [])) = do
promptAction p val
promptHandler p (VtyEvent (EvKey (KChar c) [])) =
modify $ inputBuffer %~ promptProcessChar p c
promptHandler _ (VtyEvent (EvKey KEsc [])) =
promptHandler _ (VtyEvent (EvKey KBS [])) =
modify removeChar
promptHandler p (VtyEvent (EvKey k m)) =
promptSpecialKey p k m
@ -406,4 +406,4 @@ drawSimplePrompt :: String -> Renderer
drawSimplePrompt pStr s = let
fullStr = pStr ++ s^.inputBuffer
strWidth = safeWcswidth fullStr
in showCursor () (Location (0, strWidth)) $ str fullStr
in showCursor () (Location (strWidth, 0)) $ str fullStr

View File

@ -27,9 +27,11 @@ module Mtlstats.Util
, slice
, capitalizeName
, linesToWidget
, linesToWidgetC
) where
import Brick.Types (Widget)
import Brick.Widgets.Center (hCenter)
import Brick.Widgets.Core (str, vBox)
import Data.Char (isSpace, toUpper)
import qualified Data.Map as M
@ -122,5 +124,15 @@ capitalizeName ch s = s ++ [ch']
| isSpace c = lockFlag' cs
| otherwise = False
-- | Converts a list of lines to a widget
linesToWidget :: [String] -> Widget ()
linesToWidget = vBox . map str
linesToWidget = vBox . map (str . keepBlank)
-- | Converts a list of lines to a widget with each line horizontally
-- centered
linesToWidgetC :: [String] -> Widget ()
linesToWidgetC = vBox . map (hCenter . str . keepBlank)
keepBlank :: String -> String
keepBlank "" = " "
keepBlank s = s