Compare commits
8 Commits
227401461b
...
2d5c4e6471
Author | SHA1 | Date | |
---|---|---|---|
Jonathan Lamothe | 2d5c4e6471 | ||
Jonathan Lamothe | 097d51f34b | ||
Jonathan Lamothe | 166483dc50 | ||
Jonathan Lamothe | 08e0f96a81 | ||
Jonathan Lamothe | afae5ea14a | ||
Jonathan Lamothe | ea9a9c6a85 | ||
Jonathan Lamothe | d40b56da37 | ||
Jonathan Lamothe | 5ea2d77921 |
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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"
|
||||||
]
|
]
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user