Portable text based console manipulator
Alright, i finally found a portable and easy to use library: rlutil.h
Usage:
#include <iostream>
#include "rlutil.h"
int main()
{
for (int i = 0; i < 16; i++)
{
rlutil::setColor(i);
std::cout << i << " ";
}
std::cout << std::endl;
return 0;
}
but, i will be glad for other suggestions.
Any way to make terminal control sequences portable?
tput(1)
uses the terminfo(5)
(or older termcap(5)
) database, which provides the mapping from abstract commands such as move cursor to x,y to escape sequences for different terminals. When you run a command such as
$ tput cup 10 3 # move cursor to row/column 10/3
, the terminfo database is queried to find the correct string for your terminal, which is then simply written to stdout. To find the available commands (e.g., cup
), look at the cap-name column in terminfo(5)
. tput
determines what terminal you are using by looking at the TERM
environment variable.
(This means that you can check what escape characters are being generated by simply doing $ tput [command] > [file]
and opening [file]
in some editor that can show control characters, which can be handy for exploration. The infocmp(1)
command can also be used for this.)
If you use tput
(or the underlying tputs(3)
), your program is hence automatically portable to different terminals. This is what Vim uses by the way.
However -- in the modern world, pretty much all terminals (or terminal emulators rather) use ANSI escape codes, along with some extensions (see XTerm Control Sequences). I believe the escapes supported by xterm and their behavior have become something of a de facto standard at this point, with other terminal emulators simply copying xterm's behavior. Some text-based UI libraries like termbox seem to do away with support for non-ANSI terminals altogether, and output ANSI escapes directly.
Besides the already-mentioned termbox, there's also S-Lang, which includes a terminal handling component. I believe those are the two most popular "ncurses replacements". I'd give ncurses some time first though.
Is it possible to display text in a console with a strike-through effect?
According to the ECMA-48 standard for terminals, SGR (Select Graphic Rendition) code number 9 is supposed to enable crossed-out text. However, the ANSI escape code wikipedia page says that it's not widely supported, and I'm not aware of any that do. I'd suspect that's because DEC's VTxxx series didn't support it.
Simple graphics library for tick-based simulation
I would use SDL since it is cross compatible with most OS and mature.
Also check these examples for 2D animations in order to perform the screen updates you need.
Where can I read the ANSI terminal standard?
I think I found what I'm looking for.
According to WikiPedia's ANSI escape code, the standard adopted was ECMA-48, the document is available at www.ecma-international.org Ecma-048.pdf
Related Topics
"Roll-Back" or Undo Any Manipulators Applied to a Stream Without Knowing What the Manipulators Were
Why Do Linked Lists Use Pointers Instead of Storing Nodes Inside of Nodes
Why Does Int Main() {} Compile
How to Forward Declare a Template Class in Namespace Std
Under What Circumstances Are C++ Destructors Not Going to Be Called
How to Use C++ Std::Ostream with Printf-Like Formatting
Calling Constructor of a Class Member in Constructor
Should C++ Eliminate Header Files
Missing C++ Header <_Debug> After Updating Osx Command Line Tools 6.3
What's the Usual Way of Controlling Frame Rate
Memory-Efficient C++ Strings (Interning, Ropes, Copy-On-Write, etc)
"Proper" Way to Store Binary Data with C++/Stl
How to Use the _Attribute_((Visibility("Default")))
C++ Why the Assignment Operator Should Return a Const Ref in Order to Avoid (A=B)=C