Way to clear console in julia

; clear

↑ It works, equivalent to Ctrl + L, but can’t be used in automated code.

Base.run(`clear`)


It doesn’t work, at least window 10, powershell.(I never checked in linux terminal)

Do you know any other way to clc(not necessary elegant or simple, whatever just works)?

1 Like

I think you want Clear with a capital C. See here.

Do you mean this?

Bummer. I’m not on windows right now so I can’t test things out. Hopefully someone with more expertise can help.

1 Like

You may try:

julia> print("\033c")
7 Likes

I’m not sure that’s portable.

I tracked down what Julia does on CTRL-L (and below in file is only implemented on Unix/Linux):

Probably works too on macOS, can anyone CTRL-L on Windows (and in WSL2)?

I suppose Julia can and should support same for Windows, and could export the function for programs to use.

I use this and it works, at least on Linux. I never had a chance to test it on Windows or MacOS

import REPL
terminal = REPL.Terminals.TTYTerminal("", stdin, stdout, stderr)
REPL.Terminals.clear(terminal)

I can confirm that it works on both Windows (running Julia in Windows Terminal) and Linux (running Julia in a GNOME Terminal window).

Great! But I believe that’s I think because Windows Terminal got “modernized” to use ancient Unix tech. :slight_smile: If you want to support older Windows or just not with Windows Terminal, that may not apply. But going to the shell, i.e.:

julia> run(`cls`)

should always run on Windows (but not on Linux, why it would help for Juliato add it as a cross-platform option), even in PowerShell: Clear-Host (Microsoft.PowerShell.Core) - PowerShell | Microsoft Docs

Well, it works! and i totally agree with Way to clear console in julia - #9 by Palli .

I checked only on Windows, but with CMD, PowerShell and Windows-Terminal and all worked.