Compare commits

...
8 Commits
Author SHA1 Message Date
jlamothe 2d5c4e6471 fixed spacing on title screen 2023-05-30 19:01:30 -04:00
jlamothe 097d51f34b properly centre menu headings 2023-05-30 18:56:44 -04:00
jlamothe 166483dc50 fixed missing blank line between menu header and options 2023-05-30 18:45:03 -04:00
jlamothe 08e0f96a81 cursor position fix
cursor X and Y coordinates were transposed for the simple string prompts
2023-05-30 18:30:49 -04:00
jlamothe afae5ea14a updated ChangeLog 2023-05-30 18:21:56 -04:00
jlamothe ea9a9c6a85 bugfix: backspace
backspace functionality was mistakenly mapped to the escape key for some reason
2023-05-30 18:11:54 -04:00
jlamothe d40b56da37 bail on CTRL-C 2023-05-30 18:06:32 -04:00
jlamothe 5ea2d77921 bugfix: make the whole background blue 2023-05-30 17:58:45 -04:00
6 changed files with 38 additions and 12 deletions
+3
View File
@@ -1,5 +1,8 @@
# Changelog for mtlstats # Changelog for mtlstats
## current
- updated code to use brick instead of ncurses
## 0.16.1 ## 0.16.1
- Don't automatically start a new game on new season - Don't automatically start a new game on new season
+16 -2
View File
@@ -22,9 +22,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats (app) where module Mtlstats (app) where
import Brick.AttrMap (AttrMap, forceAttrMap) 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.Util (on)
import Brick.Widgets.Core (fill)
import Graphics.Vty.Attributes.Color (blue, white) 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 (to)
import Lens.Micro.Mtl (use) import Lens.Micro.Mtl (use)
@@ -34,14 +41,21 @@ import Mtlstats.Types
-- | The main application -- | The main application
app :: App ProgState () () app :: App ProgState () ()
app = App app = App
{ appDraw = \s -> [drawController (dispatch s) s] { appDraw = draw
, appChooseCursor = showFirstCursor , appChooseCursor = showFirstCursor
, appHandleEvent = handler , appHandleEvent = handler
, appStartEvent = return () , appStartEvent = return ()
, appAttrMap = const myAttrMap , appAttrMap = const myAttrMap
} }
draw :: ProgState -> [Widget ()]
draw s =
[ drawController (dispatch s) s
, fill ' '
]
handler :: Handler () handler :: Handler ()
handler (VtyEvent (EvKey (KChar 'c') [MCtrl])) = halt
handler e = do handler e = do
c <- use (to dispatch) c <- use (to dispatch)
handleController c e handleController c e
+2 -3
View File
@@ -24,18 +24,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Control.TitleScreen (titleScreenC) where module Mtlstats.Control.TitleScreen (titleScreenC) where
import Brick.Types (BrickEvent (VtyEvent)) import Brick.Types (BrickEvent (VtyEvent))
import Brick.Widgets.Center (hCenter)
import Brick.Widgets.Core (str, vBox)
import Control.Monad.State.Class (modify) import Control.Monad.State.Class (modify)
import Data.Char (chr) import Data.Char (chr)
import Graphics.Vty.Input.Events (Event (EvKey)) import Graphics.Vty.Input.Events (Event (EvKey))
import Mtlstats.Actions import Mtlstats.Actions
import Mtlstats.Types import Mtlstats.Types
import Mtlstats.Util
titleScreenC :: Controller titleScreenC :: Controller
titleScreenC = Controller titleScreenC = Controller
{ drawController = const $ vBox $ map (hCenter . str) { drawController = const $ linesToWidgetC
$ [ "" $ [ ""
, "MONTREAL CANADIENS STATISTICS" , "MONTREAL CANADIENS STATISTICS"
] ]
+1 -3
View File
@@ -36,8 +36,6 @@ module Mtlstats.Menu (
import Brick.Main (halt) import Brick.Main (halt)
import Brick.Types (BrickEvent (VtyEvent), Widget) 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 Control.Monad.State.Class (gets, modify)
import Data.Char (toUpper) import Data.Char (toUpper)
import qualified Data.Map as M import qualified Data.Map as M
@@ -87,7 +85,7 @@ menuStateController menuFunc = Controller
drawMenu :: Menu a -> Widget () drawMenu :: Menu a -> Widget ()
drawMenu m = let drawMenu m = let
menuLines = lines $ show m menuLines = lines $ show m
in hCenter $ vBox $ map str menuLines in linesToWidgetC menuLines
-- | The event handler for a 'Menu' -- | The event handler for a 'Menu'
menuHandler :: Menu a -> Handler a menuHandler :: Menu a -> Handler a
+3 -3
View File
@@ -57,7 +57,7 @@ import Data.Char (isAlphaNum, isDigit, toUpper)
import Graphics.Text.Width (safeWcswidth) import Graphics.Text.Width (safeWcswidth)
import Graphics.Vty.Input.Events import Graphics.Vty.Input.Events
( Event (EvKey) ( Event (EvKey)
, Key (KChar, KEnter, KEsc, KFun) , Key (KBS, KChar, KEnter, KFun)
) )
import Lens.Micro ((^.), (&), (.~), (?~), (%~)) import Lens.Micro ((^.), (&), (.~), (?~), (%~))
import Lens.Micro.Mtl ((.=), use) import Lens.Micro.Mtl ((.=), use)
@@ -77,7 +77,7 @@ promptHandler p (VtyEvent (EvKey KEnter [])) = do
promptAction p val promptAction p val
promptHandler p (VtyEvent (EvKey (KChar c) [])) = promptHandler p (VtyEvent (EvKey (KChar c) [])) =
modify $ inputBuffer %~ promptProcessChar p c modify $ inputBuffer %~ promptProcessChar p c
promptHandler _ (VtyEvent (EvKey KEsc [])) = promptHandler _ (VtyEvent (EvKey KBS [])) =
modify removeChar modify removeChar
promptHandler p (VtyEvent (EvKey k m)) = promptHandler p (VtyEvent (EvKey k m)) =
promptSpecialKey p k m promptSpecialKey p k m
@@ -406,4 +406,4 @@ drawSimplePrompt :: String -> Renderer
drawSimplePrompt pStr s = let drawSimplePrompt pStr s = let
fullStr = pStr ++ s^.inputBuffer fullStr = pStr ++ s^.inputBuffer
strWidth = safeWcswidth fullStr strWidth = safeWcswidth fullStr
in showCursor () (Location (0, strWidth)) $ str fullStr in showCursor () (Location (strWidth, 0)) $ str fullStr
+13 -1
View File
@@ -27,9 +27,11 @@ module Mtlstats.Util
, slice , slice
, capitalizeName , capitalizeName
, linesToWidget , linesToWidget
, linesToWidgetC
) where ) where
import Brick.Types (Widget) import Brick.Types (Widget)
import Brick.Widgets.Center (hCenter)
import Brick.Widgets.Core (str, vBox) import Brick.Widgets.Core (str, vBox)
import Data.Char (isSpace, toUpper) import Data.Char (isSpace, toUpper)
import qualified Data.Map as M import qualified Data.Map as M
@@ -122,5 +124,15 @@ capitalizeName ch s = s ++ [ch']
| isSpace c = lockFlag' cs | isSpace c = lockFlag' cs
| otherwise = False | otherwise = False
-- | Converts a list of lines to a widget
linesToWidget :: [String] -> 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