2014-01-21 50 views
3

這一個不(在一個cmd-Box的在Windows上)工作:清除終端屏幕在命令行鏢應用

import 'dart:io'; 

void main() { 
    print("Hello, World!"); 

    Process.start('cls', [], runInShell: true).then((process) { 
     stdout.addStream(process.stdout); 
     stderr.addStream(process.stderr); 
    }); 
} 

回答

3

編輯
這似乎有答案爲什麼在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); 
} 

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

光標位置是在底部上,然後。 您必須在輸出之後添加換行符以將其移動到頂部。

+0

謝謝Günter的幫助,但你的建議並不令人滿意。 關於1.建議我有和我的解決方案相同的結果。一個好奇的人物'?'被打印。 開2.「?[2J?[0; 0H」已打印。看來,Dart並不支持這種表示法。 3.實際上是最好的解決方案,但它不會清除終端,但滾動'x'線,所以終端似乎是空的 我也試過這個,沒有成功: 'print(Process.runSync(「 cmd「,['C'cls''],runInShell:true).stdout);' – Eugen

+0

我可以驗證2在linux上工作。也許這些字符必須以不同的方式編碼。明天我會看看還有什麼可以嘗試的。 3可以使用,但我知道這是不方便的。在新輸出之後,您必須添加大量換行才能將其移動到屏幕的頂部。 –

+0

@eugen你介意添加評論你是如何解決問題的?你使用ANSICON嗎? –