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

Improvements to scrolling #1481

Merged
merged 8 commits into from
Sep 3, 2023
Merged

Improvements to scrolling #1481

merged 8 commits into from
Sep 3, 2023

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented Aug 29, 2023

  • Add scrollbars on both the inventory and info panels
  • Get rid of . . . at top and bottom of info panel, since we now have scrollbar as a visual indicator when there is more content
  • Allow scrolling the REPL history (closes Ability to scroll the REPL panel #60)
    • PgUp/PgDown can be used to scroll (Shift+PgUp/Dn were not recognized on my system)
    • Hitting any other key causes the view to jump back to the very bottom
    • A computation finishing + printing an output also causes the view to jump to the bottom
    • The REPL history is cached so that it only gets re-rendered whenever a new history entry (i.e. input or output) is added; this is needed since the history could get quite large.
  • Also, fix the height of the key hint menus to 2 lines, even when the panel-specific menu (second line) is blank, so the world panel does not keep resizing as we move the focus between panels.

Thanks to @jtdaugherty for releasing brick-1.10 with a new ability to specify blank space to the side of scrollbars; see jtdaugherty/brick#484 .

Also towards #1461 .

The spacing + highlighting on the inventory panel is not quite right,
see the discussion at jtdaugherty/brick#484 .

Also fix the size of the key shortcut hint lines to 2 rows, so the
world doesn't keep resizing as we move the panel focus around when
there are or are not panel-specific key shortcuts.
Still needs a mechanism to automatically scroll down to new prompt
when hitting 'enter'.
- when hitting a key other than PgUp/PgDown
- when a computation completes and a result is printed
@byorgey byorgey added the CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. label Aug 29, 2023
@byorgey byorgey requested review from kostmo and xsebek August 29, 2023 19:02
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.

LGTM! I tried it and seems to mostly work well.

Shame that trackpad scrolling does not work for me. Ideally I would not switch panels and just scroll items (with mouse pointer hovering above items) while I have map open.

drawREPL s =
vBox
[ withVScrollBars OnRight . viewport REPLViewport Vertical . vBox $ history <> [currentPrompt]
, vBox mayDebug
Copy link
Member

Choose a reason for hiding this comment

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

This vBox of empty list is a neat trick, I am surprised it does not produce an empty line. 🤔

@byorgey I noticed I can no longer click in the middle of the REPL to focus on it, only the edges work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed I can no longer click in the middle of the REPL to focus on it, only the edges work.

Good catch. I looked into this for a while but can't figure it out. It seems like after making the REPL into a scrollable viewport, click events are no longer generated for any clicks in the interior of the panel. I'm wondering if it's a brick bug. I might just split this out into another issue and investigate it later.

-- | Get only the items from the REPL history that were entered during
-- the current session.
getSessionREPLHistoryItems :: REPLHistory -> [REPLHistItem]
getSessionREPLHistoryItems h = toList $ Seq.drop (h ^. replStart) (h ^. replSeq)
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to use generic list rendering of history as Seq instead of plain vBox of history as list?

Copy link
Member

Choose a reason for hiding this comment

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

@byorgey honestly I might be asking you for a solution to my 10000 messages issue, so feel free to leave it as is. 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there's definitely some things we can do to make it more efficient, converting the entire history to a list and having brick render the whole thing is probably not a good idea. I will look into it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, unfortunately using brick's GenericList rendering machinery will not work, since it assumes that every list item has the same height. Cutting the Seq down to a smaller size before handing it off to brick to render will definitely save time, but to make that work I guess we would have to manually tell brick how big to make the scrollbar. I don't know if that is possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I found a good solution re: efficiency, which is to cache the REPL history so it is only re-rendered every time a new input is entered or a new output becomes available.

@byorgey
Copy link
Member Author

byorgey commented Aug 31, 2023

Shame that trackpad scrolling does not work for me.

Indeed, clearly trackpad scrolling is a thing in some terminal applications, but sadly vty does not seem to support it: https://hackage.haskell.org/package/vty-5.38/docs/Graphics-Vty-Input-Events.html#t:Event

Depends on unreleased `brick` feature; see
jtdaugherty/brick#484 .  We should wait
until it is released before merging this.
I think this is the proper way to do things: we give the entire REPL
history to brick so that it can render the entire thing and thus draw
the scroll bar correctly, scroll through the history with PgUp/PgDown
etc., but we cache it so that it is only re-rendered when the history
changes (i.e. when a new input is entered, or a new output becomes
available).
@byorgey byorgey added merge me Trigger the merge process of the Pull request. and removed merge me Trigger the merge process of the Pull request. labels Sep 3, 2023
@mergify mergify bot merged commit 15dd824 into main Sep 3, 2023
@mergify mergify bot deleted the feature/scroll-repl branch September 3, 2023 04:51
byorgey added a commit that referenced this pull request Sep 4, 2023
This fixes an issue introduced in #1481, where the old REPL history
would still be visible when starting a new scenario until entering a
command for the first time.

Incidentally, this also fixes the issue where the previous world would be
sometimes briefly visible before showing the new world upon starting a
new scenario.
mergify bot pushed a commit that referenced this pull request Sep 5, 2023
Closes #1461.  Errors which used to be displayed in a pop-up window (parse errors, type errors) are now displayed inline in the REPL window instead.

- Get rid of the pop-up error dialog
- Also fix a bug introduced in #1481 where the REPL history would not be properly cleared when first starting a new scenario, because the old cache was still being used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to scroll the REPL panel
2 participants