Skip to content

Commit

Permalink
Fix layout of REPL completions with newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Liozou committed Jun 29, 2022
1 parent a8d1d36 commit 380c397
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ end

# Show available completions
function show_completions(s::PromptState, completions::Vector{String})
colmax = maximum(map(length, completions))
colmax = any(contains('\n'), completions) ? width(terminal(s))-2 : maximum(map(length, completions))
num_cols = max(div(width(terminal(s)), colmax+2), 1)
entries_per_col, r = divrem(length(completions), num_cols)
entries_per_col += r != 0
Expand Down
14 changes: 14 additions & 0 deletions stdlib/REPL/test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -906,3 +906,17 @@ end
@test get_last_word("a[b[]]") == "b"
@test get_last_word("a[]") == "a[]"
end

@testset "issue #45836" begin
term = FakeTerminal(IOBuffer(), IOBuffer(), IOBuffer())
promptstate = REPL.LineEdit.init_state(term, REPL.LineEdit.mode(new_state()))
strings = ["abcdef", "123456", "ijklmn"]
REPL.LineEdit.show_completions(promptstate, strings)
completion = String(take!(promptstate.terminal.out_stream))
@test completion == "\033[0B\n\rabcdef\r\033[8C123456\r\033[16Cijklmn\n"
strings2 = ["abcdef", "123456\nijklmn"]
promptstate = REPL.LineEdit.init_state(term, REPL.LineEdit.mode(new_state()))
REPL.LineEdit.show_completions(promptstate, strings2)
completion2 = String(take!(promptstate.terminal.out_stream))
@test completion2 == "\033[0B\n\rabcdef\n\r123456\nijklmn\n"
end

0 comments on commit 380c397

Please sign in to comment.