Search code examples
crystal-lang

Clear terminal / console in Crystal (CLI)


How does one clear the console like with console.clear() in Node, but on Crystal.

I have searched around for a while but there seems to be no solution.


Solution

  • There is no fully standardized and ubiquitous way to clear a terminal. Most terminals recognize a special character sequence, though.

    The string that has worked very reliably (and has been in my Bash aliases) is \33c\e[3J:

    print "\33c\e[3J"