Easily enforce horizontal space use REPL, if printing

If you let something be printed to the REPL, can you enforce that horizontal space is used to the right side of an existing printout?

For example, you have some variables, a small DataFrame and something else; you have printed out the latter; now you want the small DataFrame printed not below it, but next to it; the prompt still moves down as usual (to just below the lowest point of one of those printouts).

I don’t think there is existing functionality for this.

Also, if I understand the requirement correctly, it is not really something the REPL can easily do: display is called and you get your prompt back, and then you want to go back and align the new output for the next expression horizontally?

If you just want to place text representations next to each other, you could define a function that calls show into an IOBuffer, then arranges the results nicely, but you would have to call this explicitly.

Well, why not? Whatever the details underneath, that would be GREAT functionality :stuck_out_tongue:

Can you give a small basic example of how to carry out your idea?

Very rudimentary and probably has some bugs:

function show_side_by_side(io::IO, xs...; gap = 2)
    all_lines = map(x -> split(repr(MIME("text/plain"), x), '\n'), xs)
    widths = map(lines -> maximum(length, lines), all_lines)
    nrows = maximum(length, all_lines)
    nxs = length(all_lines)
    for i in 1:nrows
        for (j, lines) in enumerate(all_lines)
            print(io, rpad(i ≤ length(lines) ? lines[i] : "", widths[j]))
            if j == nxs
                print(io, ' '^gap)

show_side_by_side(xs...; gap = 2) = show_side_by_side(stdout, xs...; gap = gap)


julia> show_side_by_side(ones(2,2), zeros(3, 3))
2×2 Array{Float64,2}:  3×3 Array{Float64,2}:
 1.0  1.0               0.0  0.0  0.0       
 1.0  1.0               0.0  0.0  0.0       
                        0.0  0.0  0.0       

Thank you very much.