如何在终端中将光标向上移动? [英] How can I move a cursor up the lines in a terminal?

查看:166
本文介绍了如何在终端中将光标向上移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印以下2个并排的表格:

I'm trying to print 2 side-by-side figures of the form:

@@@ @ @@@

@@@ @@@

@@@ @ @@@

@@@ @@@

@@@ @ @@@

@@@ @@@

打印第一个正方形后,如何将光标移回第一行以开始绘制第二个正方形?

After printing the first square, how can I move my cursor back to the top line, to start drawing my second square?

推荐答案

println语句实际上只是将字符发送到System.out,这取决于您使用哪些工具来查看这些字符,并执行所需的操作

The println statement essentially just sends characters to System.out and it is up to the tool you use to see these characters with, to do what you want to do.

对于终端(CMD.EXE/Terminal.app/etc),惯例是(与打印机一样)具有特殊的序列,这些序列不对应于所看到的字符,而是调用某些操作.历史传统是使用所谓的vt100序列,OS X和Linux下的终端通常可以理解这些序列,而CMD.EXE则不能.如果是这样,您可以使用ncurses库执行所需的操作.

For terminals (CMD.EXE/Terminal.app/etc) the convention is - as with printers - to have special sequences not corresponding to characters seen, but instead invoke some action. The historical tradition is to use so-called vt100 sequences, which terminals under OS X and Linux usually understand, but that CMD.EXE doesn't. If so, you can use an ncurses library to do what you want.

如果没有,一种典型的方法是在打印之前将要打印的整个图片内部构造成双阵列,然后像往常一样打印它.

If not, a typical approach is to build the whole picture you want to print internally in a double array before printing it, and then just print it as you normally do.

这篇关于如何在终端中将光标向上移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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