用Java覆盖终端上的文本,Console.read * [英] Overwriting text on terminal with Java, issue with Console.read*

查看:233
本文介绍了用Java覆盖终端上的文本,Console.read *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有数百个问题要求如何在控制台上更新已经写入的文本,我知道我可以打印\r字符。

I know there are hundreds of questions asking how to update already written text on console and I know I can do it printing the \r character.

我的问题当我使用Console.readPassword或Console.readLine创建一个新行,后来我不能覆盖它。

My issue comes when I use Console.readPassword or Console.readLine which creates a new line and later I can't overwrite it.

我认为我的问题与一些特别的关于Console.read *方法,但到新行。 \r转到当前行的开始,我需要能够去前一个N行的开始,并从那里开始覆盖。

I think that my issue isn't related to something special about the Console.read* methods but to new lines. \r goes to the start of the current line, I need to be able to go to the start of the previous N line and start overwriting from there. Or just clear the entire screen.

任何想法我该如何做?

>

推荐答案

原则上,这是终端依赖的,简单的Java意味着没有办法为所有控制台这样做。

In principle, this is terminal dependent, and with simple Java means there is no way to do this for all consoles.

许多终端(至少在unixoid系统中)支持 ANSI转义序列,因此您可以在其中写入\\\ [1; 5H)将光标移动到第1行第5列。

Many terminals (at least in unixoid systems) support ANSI-escape sequences, so you can there write something like "\u001B[1;5H" to move the cursor to line 1, columnn 5.

这篇关于用Java覆盖终端上的文本,Console.read *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆