Compare commits
No commits in common. "2d5c4e64712b2b41a8f35b9c7359d84e39894243" and "227401461b99cbca5ab4a315eae3e51dc31a088f" have entirely different histories.
2d5c4e6471
...
227401461b
|
@ -1,8 +1,5 @@
|
|||
# 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
|
||||
|
||||
|
|
|
@ -22,16 +22,9 @@ 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 (..), halt, showFirstCursor)
|
||||
import Brick.Types (BrickEvent (VtyEvent), Widget)
|
||||
import Brick.Main (App (..), showFirstCursor)
|
||||
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)
|
||||
|
||||
|
@ -41,21 +34,14 @@ import Mtlstats.Types
|
|||
-- | The main application
|
||||
app :: App ProgState () ()
|
||||
app = App
|
||||
{ appDraw = draw
|
||||
{ appDraw = \s -> [drawController (dispatch s) s]
|
||||
, 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
|
||||
|
|
|
@ -24,17 +24,18 @@ 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 $ linesToWidgetC
|
||||
{ drawController = const $ vBox $ map (hCenter . str)
|
||||
$ [ ""
|
||||
, "MONTREAL CANADIENS STATISTICS"
|
||||
]
|
||||
|
|
|
@ -36,6 +36,8 @@ 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
|
||||
|
@ -85,7 +87,7 @@ menuStateController menuFunc = Controller
|
|||
drawMenu :: Menu a -> Widget ()
|
||||
drawMenu m = let
|
||||
menuLines = lines $ show m
|
||||
in linesToWidgetC menuLines
|
||||
in hCenter $ vBox $ map str menuLines
|
||||
|
||||
-- | The event handler for a 'Menu'
|
||||
menuHandler :: Menu a -> Handler a
|
||||
|
|
|
@ -57,7 +57,7 @@ import Data.Char (isAlphaNum, isDigit, toUpper)
|
|||
import Graphics.Text.Width (safeWcswidth)
|
||||
import Graphics.Vty.Input.Events
|
||||
( Event (EvKey)
|
||||
, Key (KBS, KChar, KEnter, KFun)
|
||||
, Key (KChar, KEnter, KEsc, 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 KBS [])) =
|
||||
promptHandler _ (VtyEvent (EvKey KEsc [])) =
|
||||
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 (strWidth, 0)) $ str fullStr
|
||||
in showCursor () (Location (0, strWidth)) $ str fullStr
|
||||
|
|
|
@ -27,11 +27,9 @@ 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
|
||||
|
@ -124,15 +122,5 @@ 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 . 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
|
||||
linesToWidget = vBox . map str
|
||||
|
|
Loading…
Reference in New Issue
Block a user