Compare commits
No commits in common. "2d5c4e64712b2b41a8f35b9c7359d84e39894243" and "227401461b99cbca5ab4a315eae3e51dc31a088f" have entirely different histories.
2d5c4e6471
...
227401461b
|
@ -1,8 +1,5 @@
|
||||||
# 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,16 +22,9 @@ 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 (..), halt, showFirstCursor)
|
import Brick.Main (App (..), 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)
|
||||||
|
|
||||||
|
@ -41,21 +34,14 @@ import Mtlstats.Types
|
||||||
-- | The main application
|
-- | The main application
|
||||||
app :: App ProgState () ()
|
app :: App ProgState () ()
|
||||||
app = App
|
app = App
|
||||||
{ appDraw = draw
|
{ appDraw = \s -> [drawController (dispatch s) s]
|
||||||
, 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,17 +24,18 @@ 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 $ linesToWidgetC
|
{ drawController = const $ vBox $ map (hCenter . str)
|
||||||
$ [ ""
|
$ [ ""
|
||||||
, "MONTREAL CANADIENS STATISTICS"
|
, "MONTREAL CANADIENS STATISTICS"
|
||||||
]
|
]
|
||||||
|
|
|
@ -36,6 +36,8 @@ 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
|
||||||
|
@ -85,7 +87,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 linesToWidgetC menuLines
|
in hCenter $ vBox $ map str 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 (KBS, KChar, KEnter, KFun)
|
, Key (KChar, KEnter, KEsc, 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 KBS [])) =
|
promptHandler _ (VtyEvent (EvKey KEsc [])) =
|
||||||
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 (strWidth, 0)) $ str fullStr
|
in showCursor () (Location (0, strWidth)) $ str fullStr
|
||||||
|
|
|
@ -27,11 +27,9 @@ 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
|
||||||
|
@ -124,15 +122,5 @@ 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 . keepBlank)
|
linesToWidget = vBox . map str
|
||||||
|
|
||||||
-- | 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