如何清除Swift中的终端屏幕? [英] How to clear the Terminal screen in Swift?
本文介绍了如何清除Swift中的终端屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Swift 2中为命令行编写了一个BASIC解释器,我找不到一种方法来实现简单的命令CLS(清除终端中的所有文本)。我应该在循环中打印空格,还是有一个功能,我不知道,会清除终端屏幕?
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 simply print spaces in a loop, or is there a function I'm not aware of that would clear the Terminal screen?
推荐答案
使用内置的 clear
$ c> system
Use the built-in clear
command either with system
system("clear")
或 popen
(询问Google)
or popen
(ask Google)
或者,使用AppleScript通过命令行模拟按Ctrl + L:
Alternatively, simulate the pressing of Ctrl+L using AppleScript via the command line:
osascript -e 'tell app "terminal" to tell app "system events" to keystroke "l" using {control down}'
这篇关于如何清除Swift中的终端屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文