How to clear the Terminal screen in Swift?

前端 未结 5 1737
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 19:02

I am writing a BASIC Interpreter for the Command Line in Swift 2, and I cannot find a way to implement the simple command, CLS (clear all text from the Terminal.) Should I s

5条回答
  •  我在风中等你
    2020-12-11 19:34

    This answer applies to Swift 2.1 or earlier only

    To elaborate on Arc676's answer:

    The system command is imported into Swift via the Darwin module on Mac platforms (with other C APIs). On Linux, Glibc replaces Darwin for bridging low-level C APIs to Swift.

    import Glibc
    
    // ...
    
    system("clear")
    

    Or, if the system call is ambiguous, explicitly call Glibc's system (or Darwin on Mac platforms):

    import Glibc
    
    // ...
    
    Glibc.system("clear")
    

提交回复
热议问题