Skip to content

Conversation

KronosTheLate
Copy link
Contributor

@KronosTheLate KronosTheLate commented Jun 13, 2023

This PR adds defaults to the functions defined in REPL.Terminals. Specifically, it makes Base.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 and crestore, 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 in TerminalMenus.jl and Term.jl use something like this, or would benefit from it.

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.
@KronosTheLate KronosTheLate changed the title Set default for TextTerminal Set default TextTerminal, add csave and crestore Jun 13, 2023
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.
@KronosTheLate
Copy link
Contributor Author

KronosTheLate commented Jun 13, 2023

This could perhaps be interesting to use/improve to you @FedeClaudi ?

@KronosTheLate
Copy link
Contributor Author

KronosTheLate commented Jun 13, 2023

The current check-error is related to documentation:

Installing known registries into `/cache/build/default-amdci4-0/julialang/julia-master/doc/deps`
ERROR: LoadError: UndefVarError: `active_repl` not defined
Stacktrace:
  [1] ERROR: UndefVarError: `active_repl` not defined
Stacktrace:
  [1] make[2]: *** [Makefile:47: html] Error 1
make[2]: Leaving directory '/cache/build/default-amdci4-0/julialang/julia-master/doc'
make[1]: *** [/cache/build/default-amdci4-0/julialang/julia-master/Makefile:113: docs] Error 2
make: *** [Makefile:491: binary-dist] Error 2
🚨 Error: The command exited with status 2

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.

@KronosTheLate
Copy link
Contributor Author

I was considering if it had been more appropriate to define something like

active_terminal() = Base.active_repl.t

, and use active_terminal() instead of Base.active_repl.tas default terminal. However, it felt wrong to makeactive_terminala function, whenactive_replis an instance of a struct. Perhaps the best solution would be to defineactive_terminal = Base.active_repl.t`, but I did not feel comfortable adding a new variable like this. The naming and the location of the definition should be correct, and I do not feel capable of knowing what correct would be here.

Speaking of the correct naming and location - It feels weird to have active_repl be defined in base, and not in REPL. Not sure what to do about that, though, if anything.

@FedeClaudi
Copy link

@KronosTheLate this would indeed be helpful in Term.jl, especially the saving/loading which I always found to be a bit finicky. Great job.

@KronosTheLate
Copy link
Contributor Author

Bump

@DilumAluthge
Copy link
Member

@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.

@DilumAluthge DilumAluthge self-assigned this Sep 28, 2025
@DilumAluthge DilumAluthge added the REPL Julia's REPL (Read Eval Print Loop) label Sep 28, 2025
@DilumAluthge
Copy link
Member

Looks like the main merge conflict is probably just from the file being renamed in #59590.

@KronosTheLate
Copy link
Contributor Author

Would this be merged if I resolved that conflict?

@KronosTheLate
Copy link
Contributor Author

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.

@giordano
Copy link
Member

Rebase complete.

This is chiefly messed up

image

@KronosTheLate
Copy link
Contributor Author

KronosTheLate commented Oct 11, 2025

Rebase complete.

This is chiefly messed up
image

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.

@KronosTheLate
Copy link
Contributor Author

Ended up re-implementing in #59813.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

REPL Julia's REPL (Read Eval Print Loop)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants