Clear terminal window

How can I programmatically clear the terminal window, equivalent to pressing Ctrl+l?

run(`clear`)

2 Likes

Thanks!
I’ll add a semicolon ; to avoid the printed output. (there’s still an extraneous empty line left on my terminal, but that’s fine).

write(stdin.buffer, 0x0C) works on both linux and Windows.

1 Like

For completeness, it also works on macOS:

clear

This is not doing what I expected it to do though

julia> for i in 1:10
           write(stdin.buffer, 0x0C)
           println("test", i)
       end
1 Like

What are you expecting that to do?

I’d expected that to go (very quickly, prob. not visible) from test1 to test10 and test10 still be visible at the end.
Instead I end with a cleared terminal.

You should probably use something like

julia> for i in 1:10
           print("\e[0;0H\e[2J")
           println("test", i)
           sleep(0.1)
       end

for that.

4 Likes