在 C++ unix 中清除终端屏幕的一部分? [英] Clear part of terminal screen in C++ unix?

查看:29
本文介绍了在 C++ unix 中清除终端屏幕的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将内容输出到终端窗口,然后只清除其中的一部分(如上半场或四分之一等),而不是其余部分.有没有办法做到这一点?我正在使用系统(清除"),但这清除了所有内容.我宁愿不使用 ncurses.任何帮助表示赞赏.

I want to output stuff onto the terminal window and then only clear part of it (like first half or quarter etc) and not the rest. Is there a way I can do this? I was using system("clear"), but that clears everything. I'd prefer to NOT use ncurses. Any help is appreciated.

推荐答案

如果你需要一个通用的解决方案,那么它会以某种方式涉及到终端中,通过使用特殊字符,用空格覆盖要删除的部分并恢复应该仍然可见的部分.

If you need a general solution, then it will somehow involve going back in the terminal, by using special characters, overwrite the part that you want to delete with blanks and restore the part, that should still be visible.

您可以在这个 发布.它包括一些示例,说明如何使用回车 (\r) 字符.

You can find out, how to go back in the terminal in this post. It includes some examples, that show how to use the carriage return (\r) character.

此外还有一个例子,展示了如何使用 ansi 转义序列来获取红色文本.同样的方法,你可以使用ansi转义序列写到终端上的特定位置,看看此处.此链接中的强制光标位置"应该使您能够在要清除的每个位置写入空格.

Furthermore there is also an example, that shows how to use ansi escape sequences to get red text. In the same way, you can write to a specific position on the terminal using ansi escape sequences, take a look here. "Force Cursor Position" in this link should give you the ability to write blank spaces to every position, you want to clear.

但是您应该知道,并非所有终端都支持这些方法,并且如果您将输出流式传输到文件中,它将包含这些特殊字符.

However you should be aware, that not all terminals support these methods and that if you stream your output to a file, it will contain those special characters.

这篇关于在 C++ unix 中清除终端屏幕的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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