Julia: How to clear console
Asked Answered
V

4

27

I am using Julia Studio and would like to know the command for clearing the console of text and memory like imports or variables? Something like matlabs "clc" and "clear" commands.

Vincevincelette answered 24/10, 2014 at 13:17 Comment(0)
D
21

To clear the console, you can go into the shell and run clear (or cls) from there:

julia> ;
shell> clear
During answered 24/6, 2020 at 1:55 Comment(3)
That's the elegant way to do that!Nutty
ERROR: IOError: could not spawn clear: no such file or directory (ENOENT)Penultimate
@CTZStef: your console's equivalent of UNIX's clear command must be in your path. If you are using Windows, you can try cls. What system are you using?During
P
17

To clear Julia REPL, press Ctrl + L.

Pugh answered 16/11, 2021 at 7:56 Comment(1)
Nice to clear the screen, but do not free the memory.Protonema
C
3

As mentioned workspace() provides a fresh Main. One can clear variables (and the screen) with the following:


function clear()
    Base.run(`clear`)
    for var in names(Main)
        try
            eval(parse("$var=0"))
        catch e
        end
    end
    gc()
end

Variable definitions are permanent but can be nulled. To free types and the like wrap them in modules. For more info see the first two questions here.

Cronyism answered 26/5, 2016 at 12:11 Comment(2)
TERM environment variable not set. failed process: Process(`clear`, ProcessExited(1)) [1]Novelty
gc() not found. This needs to be updatedSulphurous
M
2

can try this:

function clc()
    if Sys.iswindows()
        return read(run(`powershell cls`), String)
    elseif Sys.isunix()
        return read(run(`clear`), String)
    elseif Sys.islinux()
        return read(run(`printf "\033c"`), String)
    end
end

use like:

clc();
Melonie answered 9/10, 2022 at 2:44 Comment(1)
In my case, read(run(powershell cls), String) is great. Thanks!Presentable

© 2022 - 2024 — McMap. All rights reserved.