此命令不起作用(在Windows的Command-Box中):
import 'dart:io';
void main() {
print("Hello, World!");
Process.start('cls', [], runInShell: true).then((process) {
stdout.addStream(process.stdout);
stderr.addStream(process.stderr);
});
}
最佳答案
编辑
这似乎有一个答案,为什么它在Windows How to make win32 console recognize ANSI/VT100 escape sequences?上不起作用
原始
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);
}
要么
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
要么
for(int i = 0; i < stdout.terminalLines; i++) {
stdout.writeln();
}
然后,光标位置在底部。
您必须在一些输出之后添加换行符才能将其移到顶部。