English 中文(简体)
如何迅速清除终端屏幕?
原标题:How to clear the Terminal screen in Swift?

我正在迅速为指挥线撰写一份BASIC Interpreter,我无法找到执行简单指挥的方法,即CLS(从终点站删除所有案文)。 我是否应该简单地在休息室中印刷空间,或者是否有一个功能,我不知道这一点,会清楚地看到终端屏幕?

最佳回答

使用<代码>clear 指挥系统

system("clear")

缩略语

或者,模拟Ctrl+的迫切性 L. 通过指挥线使用 Apple果:

osascript -e  tell app "terminal" to tell app "system events" to keystroke "l" using {control down} 

EDIT:system ,在快速的更新用户中已不复存在。 见

问题回答

您可以采用以下ANSI序列:

print("u{001B}[2J")

......在<代码>u{001B}上, 亚太经社会E[2J明确。

该守则对载于<条码>明令/代码>的指令发出同步呼吁。 这在<代码>readLine()上引起了问题,因为它使用快速<密码>印刷了通过<代码>clear退回的越航顺序。

var cls = Process()
var out = Pipe()
cls.launchPath = "/usr/bin/clear"
cls.standardOutput = out
cls.launch()
cls.waitUntilExit()
        print (String(data: out.fileHandleForReading.readDataToEndOfFile(), encoding: String.Encoding.utf8) ?? "")

这对我的工作是迅速进行的。

var clearScreen = Process()
clearScreen.launchPath = "/usr/bin/clear"
clearScreen.arguments = []
clearScreen.launch()
clearScreen.waitUntilExit()

你们能够以这种挫折感创建一种功能。

func clearScreen(completion:@escaping (Bool) -> () ) {
        let clearScreen = Process()
        clearScreen.launchPath = "/usr/bin/clear"
        clearScreen.arguments = []
        clearScreen.terminationHandler = { task in completion(true) }
        clearScreen.launch()
        clearScreen.waitUntilExit()
}

if you are inside the REPL just type

:明确





相关问题
2 mysql instances in MAC

i recently switched to mac. first and foremost i installed xampp. then for django-python-mysql connectivity, i "somehow" ended up installing a seperate MySQL. now the seperate mysql installation is ...

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

Switching J2SE versions on Mac OS (SnowLeopard)

My current JDK on Mac OS (10.6) is set to 1.6 and I d like to switch to 1.5. A listing of /System/Library/Frameworks/JavaVM.framework/Versions/ shows: lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 ...

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

export to MP3 from quicktime API

A question for Apple,QT programmers. Would like to know if it s possible to export a Movie object to MP3 using the QuickTime API. Preferably the ConvertMovieToFile function. I ve looked at ...

热门标签