-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Set default TextTerminal, add csave
and crestore
#50154
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
Set default TextTerminal, add csave
and crestore
#50154
Conversation
This PR adds defaults to the functions defined in `REPL.Terminals`. Specifically, it makes `Base.active_repl.t` the default terminal. The defaults are added in the generic fallbacks. The branch name is related to the original thought behind this PR, but I could not get consistent results in testing for that. The idea was to use "\x1b[s" and "\x1b[u" to save and return to cursor positions. This worked initally, but then not, for reasons I could not understand. Help with implementing that would also be appreciated.
After more testing, it figured out that the functions worked all along. I they just had no effect when I was saving and going to the final line in the terminal. So this PR adds csave and crestore - the only functions with docstrings in this module. The use print instead of write, as returning the number of returned chars written is generally just noise, and provides no useful information, as it is the same return value each time the functions are run.
This removes trailing whitespace in the docstrings, which caused a test to fail.
csave
and crestore
As `active_repl` is imported from Base, it should not be needed to annotate the variable. This is done in an attempt to fix the failing test, stating that "active_repl" is not defined.
This could perhaps be interesting to use/improve to you @FedeClaudi ? |
The current check-error is related to documentation:
I can not find anything about the docs in https://github.com/KronosTheLate/julia/edit/add_save_and_return_cursor/stdlib/REPL/docs/src/index.md. I will need help in pinpointing where this goes wrong, and how to fix it. |
I was considering if it had been more appropriate to define something like
, and use Speaking of the correct naming and location - It feels weird to have |
@KronosTheLate this would indeed be helpful in Term.jl, especially the saving/loading which I always found to be a bit finicky. Great job. |
Bump |
@KronosTheLate Can you rebase and fix the merge conflicts? Once you have done that, ping me, and I will try to recruit someone to review this PR. |
Looks like the main merge conflict is probably just from the file being renamed in #59590. |
Would this be merged if I resolved that conflict? |
Rebase complete. I had to choose between a bunch of stuff that I did not implement. I think I initially was choosing the main branch istead of feature branches, but the same merge conficts kept appearing for each subsequent feature branch. So i ended up going for the feature branches instead, and that seemed to cause progress with the merge conflicts. This does however require a keen reviewer, as it is quite possible I messed something up. It is also possible that scrapping this PR, and manually re-implementing the initial 6 commits is a faster and cleaner way to the goal. Anyone who known what they are doing have my blessing to make any changes they want to in order to fix my messy rebase. |
Gosh darn it. So I suppose that manually reimplementing my 6 commits would be the best path forward? EDIT: I was able to undo the rebase. Can someone else rebase this for me? I had to choose between so many conflicts that I do not know either side of, in files I never edited. |
08a1815
to
4f73065
Compare
Ended up re-implementing in #59813. |
This PR adds defaults to the functions defined in
REPL.Terminals
. Specifically, it makesBase.active_repl.t
the default terminal for all relevant functions (someone please verify that I did not overlook one). In my view, adding defaults greatly enhances usability, as users can not be expected to dig into this undocumented module, sorting out how to construct a handle to a terminal (related: https://discourse.julialang.org/t/how-to-get-a-handle-to-the-terminal/99592/3).The defaults are added in the generic fallbacks. This is maybe unclear, as the defaults are defined in methods in which they are not generally used (most of the fallbacks are
error("Unimplemented")
). But it reduces the number of code lines, and I feel it is mentally neat to define fallback and default in the same location, even if they apply to different situations.The branch name is related to the original thought behind this PR, but I could not get consistent results in testing for that. The idea was to use "\x1b[s" and "\x1b[u" to save and return to cursor positions. This worked initially, but then not, for reasons I could not understand. Help with implementing that would also be appreciated.EDIT.
The branch name is now valid, as explained in commit number 4. This means that this PR now adds the two functions
csave
andcrestore
, which are immensely useful for creating updating displays of e.g. a terminal plot. The functions have docstrings (as the only functions in this module), and are exported. I am sure a lot of terminal wizardry like the one used inTerminalMenus.jl
andTerm.jl
use something like this, or would benefit from it.