Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable text based console manipulator

Applications can manipulate text based consoles or terminals, and change their colors, set cursor position. The supported approaches are:

  • For Unix-like systems: There is ANSI escape code.
  • For Windows systems: There is APIs like SetConsoleTextAttribute.
  • ...

but, is there any lightweight and portable C/C++ library which handles differences between operating systems just for colors and cursor? and do nothing if it was technically impossible but best effort.

Note: I'm not searching for heavy external tools to emulate unix-like terminals (like Cygwin, Msys-rxvt, ...). I think a simple portability will be achieved with Windows APIs and ANSI escape codes. And not ncurses because it's heavy and has many functionality to full control console and I think it needs emulation.

like image 262
masoud Avatar asked Oct 24 '11 13:10

masoud


1 Answers

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.

like image 86
masoud Avatar answered Oct 21 '22 05:10

masoud