Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle PoC for GHC 9.4 #1002

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ handleModalEvent = \case
V.EvKey V.KEnter [] -> do
mdialog <- preuse $ uiState . uiModal . _Just . modalDialog
toggleModal QuitModal
case dialogSelection <$> mdialog of
Just (Just QuitButton) -> quitGame
Just (Just KeepPlayingButton) -> toggleModal KeepPlayingModal
Just (Just (StartOverButton currentSeed siPair)) -> restartGame currentSeed siPair
Just (Just (NextButton siPair)) -> saveScenarioInfoOnQuit >> startGame siPair Nothing
case dialogSelection =<< mdialog of
Just (GenericModalName, QuitButton) -> quitGame
Just (GenericModalName, KeepPlayingButton) -> toggleModal KeepPlayingModal
Just (GenericModalName, StartOverButton currentSeed siPair) -> restartGame currentSeed siPair
Just (GenericModalName, NextButton siPair) -> saveScenarioInfoOnQuit >> startGame siPair Nothing
_ -> return ()
ev -> do
Brick.zoom (uiState . uiModal . _Just . modalDialog) (handleDialogEvent ev)
Expand Down
2 changes: 1 addition & 1 deletion src/Swarm/TUI/Model/Menu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ data ButtonSelection

data Modal = Modal
{ _modalType :: ModalType
, _modalDialog :: Dialog ButtonSelection
, _modalDialog :: Dialog ButtonSelection Name
}

makeLenses ''Modal
Expand Down
1 change: 1 addition & 0 deletions src/Swarm/TUI/Model/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ data Name
InfoViewport
| -- | The scrollable viewport for any modal dialog.
ModalViewport
| GenericModalName
deriving (Eq, Ord, Show, Read)
4 changes: 2 additions & 2 deletions src/Swarm/TUI/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ drawMainMessages :: AppState -> Widget Name
drawMainMessages s = renderDialog dial . padBottom Max . scrollList $ drawLogs ls
where
ls = reverse $ s ^. runtimeState . eventLog . notificationsContent
dial = dialog (Just "Messages") Nothing maxModalWindowWidth
dial = dialog (Just $ str "Messages") Nothing maxModalWindowWidth
scrollList = withVScrollBars OnRight . vBox
drawLogs = map (drawLogEntry True)

Expand Down Expand Up @@ -432,7 +432,7 @@ chooseCursor s locs = case s ^. uiState . uiModal of

-- | Render the error dialog window with a given error message
renderErrorDialog :: Text -> Widget Name
renderErrorDialog err = renderDialog (dialog (Just "Error") Nothing (maxModalWindowWidth `min` requiredWidth)) errContent
renderErrorDialog err = renderDialog (dialog (Just $ str "Error") Nothing (maxModalWindowWidth `min` requiredWidth)) errContent
where
errContent = txtWrapWith indent2 {preserveIndentation = True} err
requiredWidth = 2 + maximum (textWidth <$> T.lines err)
Expand Down
22 changes: 12 additions & 10 deletions src/Swarm/TUI/View/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Witch (from, into)

-- | Generate a fresh modal window of the requested type.
generateModal :: AppState -> ModalType -> Modal
generateModal s mt = Modal mt (dialog (Just title) buttons (maxModalWindowWidth `min` requiredWidth))
generateModal s mt = Modal mt (dialog (Just $ str title) buttons (maxModalWindowWidth `min` requiredWidth))
where
currentScenario = s ^. uiState . scenarioRef
currentSeed = s ^. gameState . seed
Expand All @@ -45,27 +45,29 @@ generateModal s mt = Modal mt (dialog (Just title) buttons (maxModalWindowWidth
continueMsg = "Keep playing"
in ( ""
, Just
( 0
, [ (nextMsg, NextButton scene)
( GenericModalName
, [ (nextMsg, GenericModalName, NextButton scene)
| Just scene <- [nextScenario (s ^. uiState . uiMenu)]
]
++ [ (stopMsg, QuitButton)
, (continueMsg, KeepPlayingButton)
++ [ (stopMsg, GenericModalName, QuitButton)
, (continueMsg, GenericModalName, KeepPlayingButton)
]
)
, sum (map length [nextMsg, stopMsg, continueMsg]) + 32
)
DescriptionModal e -> (descriptionTitle e, Nothing, descriptionWidth)
QuitModal ->
let stopMsg = fromMaybe ("Quit to" ++ maybe "" (" " ++) (into @String <$> curMenuName s) ++ " menu") haltingMessage
maybeStartOver = sequenceA ("Start over", StartOverButton currentSeed <$> currentScenario)
maybeStartOver = do
cs <- currentScenario
return ("Start over", GenericModalName, StartOverButton currentSeed cs)
in ( ""
, Just
( 0
( GenericModalName
, catMaybes
[ Just ("Keep playing", CancelButton)
[ Just ("Keep playing", GenericModalName, CancelButton)
, maybeStartOver
, Just (stopMsg, QuitButton)
, Just (stopMsg, GenericModalName, QuitButton)
]
)
, T.length (quitMsg (s ^. uiState . uiMenu)) + 4
Expand All @@ -75,7 +77,7 @@ generateModal s mt = Modal mt (dialog (Just title) buttons (maxModalWindowWidth
Nothing -> "Goal"
Just (scenario, _) -> scenario ^. scenarioName
in (" " <> T.unpack goalModalTitle <> " ", Nothing, 80)
KeepPlayingModal -> ("", Just (0, [("OK", CancelButton)]), 80)
KeepPlayingModal -> ("", Just (GenericModalName, [("OK", GenericModalName, CancelButton)]), 80)

-- | Render the type of the current REPL input to be shown to the user.
drawType :: Polytype -> Widget Name
Expand Down
14 changes: 2 additions & 12 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
extra-deps:
- word-wrap-0.5
- hashable-1.3.5.0
- base-orphans-0.8.6
- fused-effects-lens-1.2.0.1@sha256:675fddf183215b6f3c1f2a0823359a648756435fd1966284e61830ec28ad61fa,1466
- hsnoise-0.0.3@sha256:260b39175b8a3e3b1719ad3987b7d72a3fd7a0fa99be8639b91cf4dc3f1c8796,1476
- brick-1.0@sha256:99242c47aa2fd08424445de9c4437405098dcda5ae74d558648eadd6b069062c,17793
- bimap-0.5.0@sha256:aba506d02a1c93fc2b50dcbe728d2a4d07cca89b7033945418061a0b08576ebd,1889
- simple-enumeration-0.2.1@sha256:8625b269c1650d3dd0e3887351c153049f4369853e0d525219e07480ea004b9f,1178
- fused-effects-lens-1.2.0.1@sha256:675fddf183215b6f3c1f2a0823359a648756435fd1966284e61830ec28ad61fa,1466
- text-zipper-0.12@sha256:e96110598fc25e57a99ffcd8e583351af8b325b813aa5e3bd0adc627e3e02b6b,1472
- vty-5.36@sha256:dfbb78ea924ad0ef66cff4bc223918240234508c3de139b34780038dafb5fc53,20859
- criterion-1.6.0.0@sha256:76280dace017fe1fab4dae35d57992a48e70a3cfcdb2a4563923cd2502a7268c,5403
- criterion-measurement-0.2.0.0@sha256:8c6127b22a53aebc7d5a9dbf8fd870f128b93be3069fe7fed969e4c253cd9626,2121
- witch-1.1.1.0@sha256:053d116eedea78219fdb465ad7903afc0e67c67ca5837508bba9435f4ac239bc,2178
resolver: lts-20.5
resolver: nightly-2023-01-11

6 changes: 3 additions & 3 deletions swarm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ library
build-depends: base >= 4.14 && < 4.18,
aeson >= 2 && < 2.2,
array >= 0.5.4 && < 0.6,
brick >= 1.0 && < 1.5,
brick >= 1.0 && < 1.6,
bytestring >= 0.10 && < 0.12,
clock >= 0.8.2 && < 0.9,
containers >= 0.6.2 && < 0.7,
Expand All @@ -165,9 +165,9 @@ library
http-client-tls >= 0.3 && < 0.4,
http-types >= 0.12 && < 0.13,
lens >= 4.19 && < 5.3,
linear >= 1.21.6 && < 1.22,
linear >= 1.21.6 && < 1.23,
lsp >= 1.2 && < 1.7,
megaparsec >= 9.0 && < 9.3,
megaparsec >= 9.0 && < 9.4,
minimorph >= 0.3 && < 0.4,
mtl >= 2.2.2 && < 2.3,
murmur3 >= 1.0.4 && < 1.1,
Expand Down