-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Improve the API of REPL.TerminalMenus #35915
Conversation
OK, the more I dug the more I found to fix. I tackled this because I was looking to create a new menu type, which gave me an opportunity to exercise the abstraction API. Perhaps not surprisingly I discovered some issues. Two issues are:
I've tried to clean this up here, but it's still not the API we probably want for 2.0:
But I don't see a non-breaking way to get to either of these. So this does the next best thing (?) and passes a copy of these settings back to I think I've set this up so that all users of the legacy interface should continue to work, but that's not actually tested. |
This removes 80 invalidations, ref JuliaLang/julia#35915 This will be breaking so I've bumped the version in anticipation. We might want to merge this only when we're ready to release the next breaking version.
This removes 80 invalidations, ref JuliaLang/julia#35915 This will be breaking so I've bumped the version in anticipation. We might want to merge this only when we're ready to release the next breaking version.
This eliminates camelCase, fixes a typo (which unfortunately was documented), adds a `const` and type info to the CONFIG dict, and does some renaming/consolidation. Finally, it eliminates a dangerous escape hatch from one of the tests.
The old `writeLine` forced the user to take the (undocumented) step of looking up the cursor character in the internal CONFIG Dict. We can use the name change as an opportunity to improve the API.
The only way `options` was being used was to count the number, so it seems a bit silly to force the user to pass a vector. This will make it easier to support dynamic menus.
For menus whose number of options might change as a consequence of user input (e.g., foldable menus), this prevents indexing errors.
This should enhance the support for dynamic menus that might change the number of options offered.
ca72b97
to
70a5f63
Compare
I think this has reached a satisfying point. Changes since the last update:
With one important exception, this Thoughts? |
Nice to see this moving forward! I was just wondering if we could use this chance for incorporating upstream changes made after split (merge?) circa early 2018. A notable change I can think of is single choice menu (nick-paul/TerminalMenus.jl#20) which was a sole reason prevented me from using the REPL version of this package. |
That can be viewed as a bugfix, so it would be fine to put that in any time. That said, you might as well wait for this to merge? |
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.
Looks like a nice improvement to the API to me.
Thanks, @KristofferC! |
Added NEWS, will merge if CI passes. |
(about the news, if this indeed allows for adding default option/s, shouldn't that be mentioned in the news?) |
Maybe. I'm not actually sure what you mean by "adding default options," can you clarify? Note docs for TerminalMenus are at https://docs.julialang.org/en/v1.6-dev/stdlib/REPL/#TerminalMenus-1. Amazingly, they've already been updated for this PR. |
I'm only asking because this #32349 closed by this PR. As stated in that issue, default options would allow for the prompt to have the cursor already set to some default option for the |
Oh, got it. Yes, I suppose the individual API additions are NEWS-worthy. See if #36210 helps (and feel free to edit it). |
Perfect! Thank you very much. |
This overhaul of the `AbstractMenu` extension interface of `REPL.TerminalMenus` addresses several concerns: - Printing the "paging" navigation indicators was handled by TerminalMenus, but the subtype methods were expected to print the cursor indicator and, for multiple-selection menus, the selection status indicators in a manner that preserved alignment. There was no obvious reason for the inconsistency. - Printing these indicators relied on accessing a mutable private global variable in TerminalMenus. It was therefore not possible to use different settings simultaneously for two different menus (e.g. a main menu and its submenus). - The API required that subtype methods supply a list of strings for each menu-option when really it only needed to know how many options were available. This was particularly problematic for large, dynamic menus whose options might change and for which lists of options would have to be reallocated regularly but were then thrown away after checking their length. This deprecates the old interface in a backward-compatible manner, so is non-breaking.
I'm late to discover the wonders of TerminalMenus and I was delighted to find this PR when faced with the limitations of the API in Julia 1.5. However, I still see one glaring omission, namely that the Things that would be possible with a controllable cursor include jumping to a related option after a custom key press or seamlessly moving into a submenu related to the option at the cursor. Ideally the cursor should have been a mandatory field in the menu struct. That's not possible to introduce now with respect to backwards compatibility of course. One possibility is to use a @timholy, any thoughts? |
I agree that it would have been nice to allow As an alternative to supporting an arbitrary |
Ah, a |
This eliminates camelCase,
fixes a typo (which unfortunately was documented), adds aconst
and type info to the CONFIG dict, and does some renaming/consolidation. Finally, it eliminates a dangerous escape hatch from one of the tests.EDIT: the most recent version fixes #31414, fixes #32349, closes #30043, and closes #32344