OhMyREPL.jl icon indicating copy to clipboard operation
OhMyREPL.jl copied to clipboard

Would like numbered REPL prompts

Open eschnett opened this issue 2 years ago • 3 comments

Sometimes it would be convenient if the REPL prompts (julia>) were numbered, starting from 1 when the session begins.

For example, when I receive a large output in the Julia REPL, I might need to scroll back to find the previous prompt. Numbered prompts would help here.

See https://github.com/JuliaLang/julia/issues/46310.

eschnett avatar Aug 11 '22 13:08 eschnett

I use OhMyREPL.input_prompt! to show the curent time in the prompt, and tried to adapt that for this purpose.

        let _replcounter = 1
          OhMyREPL.input_prompt!(:green) do 
            "$(_replcounter): julia> "
          end
          OhMyREPL.output_prompt!() do
            _replcounter += 1
            ""
          end
        end

(in startup.jl)

The let block allows us to keep state between calls to the function, and so allowing the counter to update.

Placing the _replcounter += 1 line in input_prompt! would lead to the counter to be updated for every character typed in the REPL. So I instead placed it in output_prompt!.

This means that the counter is updated only when there's output - lines where output is suppressed with ;, and empty lines where I press enter without typing anything (which I have a habit of doing), don't update the counter.

1: julia> x = 10
10

2: julia> y = 20;

2: julia> z = 30
30

3: julia> 

3: julia> 

I don't know if there's a better way of accomplishing this using the internals of REPL and OhMyREPL, this is just my attempt at it using the tools I know of!

digital-carver avatar Aug 12 '22 18:08 digital-carver

See https://github.com/KristofferC/OhMyREPL.jl/pull/270.

I also have some local work to make Out[3] work when entered in the REPL.

KristofferC avatar Aug 13 '22 05:08 KristofferC

https://github.com/JuliaLang/julia/pull/46781 does this natively in the Julia REPL now.

KristofferC avatar Sep 19 '22 08:09 KristofferC