简体   繁体   English

Java - 在控制台中重写多行

[英]Java - Rewriting Multiple Lines in the Console

I am running Windows, however the program I am writing needs to be cross compatible with Linux. 我正在运行Windows,但是我编写的程序需要与Linux交叉兼容。

I am aware that you can rewrite (or replace a already written line in the console with another) single lines in the console in both Windows/Linux just by using \\r 我知道只需使用\\ r \\ n就可以在Windows / Linux的控制台中重写(或在控制台中替换已经写入的行)。

System.out.print("Initial line");
System.out.print("\r");
System.out.print("Updated line");

but I would like to rewrite multiple lines like: 但我想重写多行,如:

System.out.print("Line 1");
System.out.print("Line 2");
// magic code
System.out.print("Updated line 1");
System.out.print("Updated line 2");

I would guess that you use something along the lines of \\b, etc but I am at a loss. 我猜你会使用\\ b等等的东西,但我不知所措。 Anyone know how this is done? 有谁知道这是怎么做的? (NO 3RD PARTY LIBRARIES) (非党的第三方图书馆)

@Multrix @Multrix

I see that '\\r' works in both Win/Linux ... 我看到'\\ r'在Win / Linux中都有效...

But, I doubt the carriage return could be selectively returned up-til the previous text portion as you are describing above... 但是,我怀疑回车可以选择性地返回 - 直到上面描述的前一个文本部分...

Because applying '\\r' bring the carriage return all the way back to the beginning of that line... It will only clear if you print more characters after you bring the carriage return back... 因为应用'\\ r'会使回车一直返回到该行的开头...只有在您将回车带回来后再打印更多字符时才会清除...

Hope it helps... 希望能帮助到你...

I am afraid that is not possible. 我担心这是不可能的。 Windows documentation shows it cannot be done. Windows文档显示无法完成。 I know you said no third party libraries, but would you mind trying curses . 我知道你说没有第三方图书馆,但你介意尝试诅咒 That is the only hope I see AFAIK. 这是我看到AFAIK的唯一希望。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM