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

navigable robots table #2140

Merged
merged 18 commits into from
Sep 17, 2024
Merged

navigable robots table #2140

merged 18 commits into from
Sep 17, 2024

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Sep 6, 2024

Towards #1341. Should also be useful for #2133.

Screenshot from 2024-09-09 22-04-10

Uses the brick-tabular-list package to render the F2 robots dialog as a navigable list with tabular formatting. Hitting Tab on a selected row shows details for that robot.

Also:

  • Extracts some record definitions from Swarm.TUI.Model.UI into Swarm.TUI.Model.UI.Gameplay
  • Removes re-export of the Name type from Swarm.TUI.Model
  • Replace uses of maximum with the safer maximum0
  • New applyJust combinator

Testing

Showing a large robots list

scripts/play.sh -i data/scenarios/Challenges/Ranching/beekeeping.yaml --debug all_robots --speed 2 --autoplay

and with extra column:

scripts/play.sh -i data/scenarios/Challenges/Ranching/beekeeping.yaml --debug all_robots,robot_id --speed 2 --autoplay

Showing a small robots list with details view and logs

scripts/play.sh -i data/scenarios/Testing/562-lodestone.yaml --debug all_robots,robot_id --speed 2 --autoplay

Log view:
Screenshot from 2024-09-13 17-25-23

@kostmo kostmo changed the base branch from refactor/ui-dialogs-state-record to main September 7, 2024 06:51
@kostmo kostmo force-pushed the feature/navigable-robot-dialog branch 2 times, most recently from 5435ef4 to 77a20b5 Compare September 7, 2024 07:13
@kostmo kostmo force-pushed the feature/navigable-robot-dialog branch from 3a18bb6 to 76277e2 Compare September 9, 2024 06:09
@kostmo kostmo changed the title WIP navigable table navigable robots table Sep 9, 2024
@kostmo kostmo force-pushed the feature/navigable-robot-dialog branch from 76277e2 to 7cc7b13 Compare September 9, 2024 06:20
@kostmo kostmo added the T-UI Involves the user interface. label Sep 9, 2024
@kostmo kostmo force-pushed the feature/navigable-robot-dialog branch 6 times, most recently from deb58d0 to e3d0920 Compare September 14, 2024 01:29
@kostmo kostmo marked this pull request as ready for review September 14, 2024 01:33
@kostmo kostmo force-pushed the feature/navigable-robot-dialog branch from e3d0920 to b75438e Compare September 14, 2024 03:41
xsebek
xsebek previously requested changes Sep 14, 2024
Copy link
Member

@xsebek xsebek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat. 👍

I have some nitpicks about the refactoring. It would have been nicer if that was a separate Pull Request, so that the changes here were easier to see.

The view seems to work well, but I was initially confused by the controls. It would be nice if there was a hint in UI about which keyboard shortcuts are used to control it.

src/swarm-tui/Swarm/TUI/Model.hs Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/Model/UI/Gameplay.hs Outdated Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot.hs Outdated Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot/Details.hs Outdated Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot/Type.hs Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot/Type.hs Outdated Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot/Type.hs Outdated Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot.hs Outdated Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot.hs Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/View/Robot.hs Outdated Show resolved Hide resolved
@kostmo kostmo requested a review from xsebek September 15, 2024 18:04
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

I agree the controls seem a bit confusing. To be consistent with the rest of the UI, I think Tab should only switch between focus within a single panel, not change which panel is displayed. I suggest having Enter on a highlighted robot open the robot details panel (instead of Tab), then Tab within the robot details panel just switches between the different things to focus in that panel; Esc will close it and return to the list of all robots.

@@ -273,6 +280,10 @@ applyWhen :: Bool -> (a -> a) -> a -> a
applyWhen True f x = f x
applyWhen False _ x = x

applyJust :: Maybe (a -> a) -> a -> a
applyJust Nothing x = x
applyJust (Just f) x = f x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple thoughts/observations on applyJust:

  1. applyJust = fromMaybe id
  2. It can be generalized to compose :: Foldable t => t (a -> a) -> a -> a; compose = foldr (.) id.
    I am not sure whether it is worth changing anything based on these observations but I thought they were at least worth mentioning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I was also intrigued by this helper function.

Is any variant of this function available in our dependencies? 🤔 The only hoogle hit is thread from some alternative prelude.

src/swarm-engine/Swarm/Game/State/Initialize.hs Outdated Show resolved Hide resolved
Copy link
Member

@xsebek xsebek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kostmo for going through my comments. 👍

I like @byorgey's suggestion for the controls, I kept hitting Enter and closing the modal.

Comment on lines 14 to 15
tabControlFooter :: Widget Name
tabControlFooter = hCenter $ withAttr italicAttr $ txt "NOTE: [Tab] toggles focus between panes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make this polymorphic in the Name it could go to Swarm.TUI.View.Util, I think.

But maybe we will need a common set of shared view parts anyway.

@@ -8,52 +8,14 @@
-- SPDX-License-Identifier: BSD-3-Clause
module Swarm.TUI.Model.UI (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't follow this consistently (yet), but it might be nice to re-export the whole Swarm.TUI.Model.UI.Gameplay here, so that there are fewer changes in the imports.

It's a drop of water in the ocean though, so feel free to ignore this suggestion.

@xsebek xsebek mentioned this pull request Sep 15, 2024
mergify bot pushed a commit that referenced this pull request Sep 15, 2024
* use `watch` to avoid busy-waiting for the bit seed to grow

Prompted by #2140, which shows hundreds of `ishere` calls.

| Before | After |
|--------|--------|
| <img width="143" alt="Screenshot 2024-09-15 at 10 02 51 PM" src="https://github.com/user-attachments/assets/174827e4-9371-4405-a6c2-dd20233e4588"> | <img width="143" alt="Screenshot 2024-09-15 at 10 01 32 PM" src="https://github.com/user-attachments/assets/a1d02d16-487c-46d0-b5f1-5aaf4da111cb"> |

This should make the testing scenario take 0.1s from previous 0.5s. You can test it with:
```sh
cabal run swarm-integration -O0 -- -p '/Testing\/562-lodestone/
```
@kostmo kostmo marked this pull request as draft September 15, 2024 22:39
@kostmo kostmo force-pushed the feature/navigable-robot-dialog branch from 479a682 to cbaaf22 Compare September 15, 2024 23:46
@kostmo kostmo marked this pull request as ready for review September 15, 2024 23:46
@kostmo
Copy link
Member Author

kostmo commented Sep 15, 2024

Tab should only switch between focus within a single panel, not change which panel is displayed. I suggest having Enter on a highlighted robot open the robot details panel (instead of Tab), then Tab within the robot details panel just switches between the different things to focus in that panel; Esc will close it and return to the list of all robots.

I have now updated the controls to behave as described. It feels a bit hacky though---perhaps at some point we would introduce the concept of a "stack" of dialogs so that things like the Esc would simply pop the top dialog from the stack, rather than special-casing logic for it.

@kostmo kostmo dismissed xsebek’s stale review September 17, 2024 00:16

Suggestions addressed

@kostmo kostmo requested a review from xsebek September 17, 2024 00:16
Copy link
Member

@xsebek xsebek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works nicely, thanks @kostmo. 👍

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Sep 17, 2024
@mergify mergify bot merged commit 671fd0f into main Sep 17, 2024
12 checks passed
@mergify mergify bot deleted the feature/navigable-robot-dialog branch September 17, 2024 18:28
@kostmo kostmo mentioned this pull request Oct 15, 2024
mergify bot pushed a commit that referenced this pull request Oct 15, 2024
Continuing with the replacements started in this discussion: #2140 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request. T-UI Involves the user interface.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants