gpt4 book ai didi

dart - 在命令行 Dart 应用程序中清除终端屏幕

转载 作者:行者123 更新时间:2023-12-01 11:40:34 28 4
gpt4 key购买 nike

这个不起作用(在命令框中的 Windows 上):

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();
}

然后光标位置在底部。
您必须在某些输出后添加换行符才能将其移至顶部。

关于dart - 在命令行 Dart 应用程序中清除终端屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21269769/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com