-
Notifications
You must be signed in to change notification settings - Fork 53
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
Split debug options #2094
Merged
Merged
Split debug options #2094
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
27dbe31
Split debug options
xsebek 54474c1
Fix alphabet
xsebek 274cf88
Remove debugging output
xsebek 5757b8d
Sneakily modify debug options
xsebek 87b8fe7
Add completions
xsebek f2d324d
Make adding cheat slightly nicer
xsebek 67a9b3f
Add extra to exe deps for enumerate
xsebek 226556d
Use Lens.contains
xsebek 0cec03b
Merge branch 'main' into task/xsebek/debug-options
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Sum type representing the Swarm debug options. | ||
module Swarm.TUI.Model.DebugOption ( | ||
DebugOption (..), | ||
debugOptionName, | ||
debugOptionDescription, | ||
readDebugOption, | ||
readDebugOptionList, | ||
) where | ||
|
||
import Data.Foldable (find, foldl') | ||
import Data.List.Extra (enumerate, splitOn, trim) | ||
|
||
data DebugOption | ||
= ToggleCreative | ||
| ToggleWorldEditor | ||
| DebugCESK | ||
| ListAllRobots | ||
| ListRobotIDs | ||
| ShowHiddenGoals | ||
| ShowGoalDialogsInAutoPlay | ||
| ShowTestingScenarios | ||
deriving (Eq, Ord, Show, Enum, Bounded) | ||
|
||
debugOptionName :: DebugOption -> String | ||
debugOptionName = \case | ||
ToggleCreative -> "creative" | ||
ToggleWorldEditor -> "editor" | ||
DebugCESK -> "cesk" | ||
ListAllRobots -> "all_robots" | ||
ListRobotIDs -> "robot_id" | ||
ShowHiddenGoals -> "hidden_goals" | ||
ShowGoalDialogsInAutoPlay -> "autoplay_goals" | ||
ShowTestingScenarios -> "testing" | ||
|
||
debugOptionDescription :: DebugOption -> String | ||
debugOptionDescription = \case | ||
ToggleCreative -> "allow toggling creative mode on/off" | ||
ToggleWorldEditor -> "allow toggling the world editor mode on/off" | ||
DebugCESK -> "allow toggling the CESK debug view on/off" | ||
ListAllRobots -> "list all robots (including system robots) in the robot panel" | ||
ListRobotIDs -> "list robot IDs in the robot panel" | ||
ShowHiddenGoals -> "show hidden objectives in the goal dialog" | ||
ShowGoalDialogsInAutoPlay -> "show goal dialogs when running in autoplay" | ||
ShowTestingScenarios -> "show Testing folder in scenarios menu" | ||
|
||
readDebugOption :: String -> Maybe DebugOption | ||
readDebugOption name = find ((trim name ==) . debugOptionName) enumerate | ||
|
||
readDebugOptionList :: String -> Either String [DebugOption] | ||
readDebugOptionList = foldl' eitherRead (Right []) . splitOn "," | ||
where | ||
eitherRead s o = case (s, readDebugOption o) of | ||
(Left e, _) -> Left e | ||
(_, Nothing) -> Left $ "unknown option '" <> o <> "'" | ||
(Right oss, Just os) -> Right $ os : oss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest something like this:
Then we can get rid of the lambda + record update in the final
return
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have underestimated the powers of ApplicativeDo after last issues. I will try this. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, this is not accepted by ApplicativeDo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xsebek what about
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, that also needs a monad. I suppose it makes sense, how else would you write it in a
a <$> ... <*> ...
style?I added a comment and made the return a bit nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right, because it's referring to
cheatMode
which is the result of a previous action. Actually, I now understand whylet debug = Set.union cheatMode ...
is not accepted either---for the same reason.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I don't even understand why the existing code works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@byorgey I imagine GHC constucts a suitable
a
that puts everything in the right place: