Clearing the terminal screen in a command-line Dart app

こ雲淡風輕ζ 提交于 2019-12-06 02:55:47
Günter Zöchbauer

EDIT
This seems to have the answer why it doesn't work on windows How to make win32 console recognize ANSI/VT100 escape sequences?

ORIGINAL

if(Platform.isWindows) {
  // not tested, I don't have Windows
  // may not to work because 'cls' is an internal command of the Windows shell
  // not an executeable
  print(Process.runSync("cls", [], runInShell: true).stdout); 
} else {
  print(Process.runSync("clear", [], runInShell: true).stdout);
}

or

print("\x1B[2J\x1B[0;0H"); // clear entire screen, move cursor to 0;0
print("xxx") // just to show where the cursor is
// http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes

or

for(int i = 0; i < stdout.terminalLines; i++) {
  stdout.writeln();
}

The cursor position is on the bottom then. You have to add newlines after some output to move it to the top.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!