在Linux控制台中返回一行? [英] Go back up a line in a linux console?

查看:623
本文介绍了在Linux控制台中返回一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以回去行,并用 \r 覆盖其内容。

现在我该如何进入上一行要改变这一点?

或者是否有一种方法可以打印到控制台窗口中的特定光标位置?

I know I can go back the line and overwrite its contents with \r.
Now how can I go up into the previous line to change that?
Or is there even a way to print to a specific cursor location in the console window?

我的目标是创建一些自刷新多行控制台应用程序与PHP。

My goal is to create some self-refreshing multiline console app with PHP.

推荐答案

使用 ANSI转义代码来移动光标。例如: Esc [1 F 。要将Escape字符放在字符串中,您需要以数字方式指定其值,例如\x1B [1F

Use ANSI escape codes to move the cursor. For example: Esc [ 1 F. To put the Escape character in a string you'll need to specify its value numerically, for example "\x1B[1F"

As sujoy建议,您可以使用 PHP ncurses 以获取更抽象的方法来移动光标。

As sujoy suggests, you can use PHP ncurses for a more abstract way to move the cursor.

虽然大多数控制台允许使用ANSI转义码,但其他类型的终端使用不同的字符序列, ncurses 标准化的API,是终端独立的。如果你有兴趣,快速查看 / etc / termcap (然后 man terminfo )。

Whilst most "consoles" allow ANSI escape codes, other sorts of terminal use different character sequences, ncurses provides a standardised API that is terminal independent. Have a quick look at /etc/termcap (and then man terminfo) if you are interested.

更新: Lars Wirzenius的回答有一个有用的背景摘要。几年前,我还写了一篇关于终端的短文。

Update: Lars Wirzenius' answer has a useful summary of the background. Some years ago I also wrote a short article on terminals.

这篇关于在Linux控制台中返回一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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