基本终端输出使用C ++ - 问题 [英] Basic terminal output using C++ - Questions

查看:202
本文介绍了基本终端输出使用C ++ - 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,这个问题可能听起来有点太含糊了,但这里有两个我需要做的事情,我肯定需要一些输入:

Well, the question may sound a bit too vague but here's 2 things I need to do and I'd definitely need some input on this :


  • 使用颜色输出某些内容(例如使用 cout )(注意:My TERM 环境变量设置为 xterm-color 如果这有什么区别;还有,是否有任何统一的方式输出彩色文本, mac和* nix终端,以便代码可移植)

  • Output something (e.g. using cout) with color (note: My TERM environment variable is set to xterm-color if that makes any difference; also, is there any uniform way to output colored text that's compatible with both pure mac and *nix terminals in general, so that the code is portable)

在终端屏幕上输出相同位置。确定,这可能听起来很混乱。让我们来看一个终端应用程序,它只是输出一个进度百分比。它通常不会为此开始一个新行。新值显示在同一位置。这是怎么回事?

Output something at the same position on the terminal screen. OK, this may sound confusing too. Let's take a terminal app which simply outputs a progress percentage. It normally won't start a new line for that. The new value is shown at the very same spot. How is this doable? (Being a once Borland Pascal guy from the good old DOS days, the only thing I could think of is something to do with accessing video memory directly... or not?)

那么...任何想法?

推荐答案

您可能想要使用 ncurses 库。和 ANSI转义代码也可用于着色。

You probably want to use ncurses library. And ANSI escape codes can also be used for coloring.

这篇关于基本终端输出使用C ++ - 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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