C++ Smudges - Minor errors or inconsistencies: small, almost unnoticeable mistakes, like formatting issues or slightly misaligned code, that don't necessarily break the program but make it less clean or readable. Incomplete or messy code: sections of code that are not fully developed, have placeholder values, or are generally disorganized. Code that needs refinement: functions but could be optimized for performance, readability, or maintainability.
Friday, January 16, 2026
Sunday, January 4, 2026
Terminal Colors
Changing terminal output colors with an easy function.
I had a hard time adjusting to using ncursers and conio in Linux, so I just wrote my own color map. It resembles the Borland VCL color consts that I'm so used to.
Sample program and color.h shown below:
main.cpp
#include <iostream>#include <stdio.h>#include <cstring>#include "color.h"using namespace std;int main(){string s = "Demo colors on terminal output.";cout << SendColoredText(clMAROON, clWHITE, s) << "\n";cout << SendColoredText(clBLACK, clOLIVE, s) << "\n";cout << s << " (default)\n";// default terminal colorscout << "\e[3m\e[4m" + SendColoredText(13, 9, s) << "\n\n";//italics + underlinedreturn 0;}
colors.h
#define clBLACK 0
#define clMAROON 1
#define clGREEN 2
#define clOLIVE 3
#define clNAVY 4
#define clBLUE 5
#define clPURPLE 6
#define clSILVER 7
#define clGRAY 8
#define clRED 9
#define clLIME 10
#define clYELLOW 11
#define clMAGENTA 12
#define clCYAN 13
#define clWHITE 14
#define clDEFAULT 15
std::string SendColoredText(int BG, int FG, std::string TEXT){
std::string _FG, _BG, _ATTRIB, RETURN_STRING;
std::string RESET_STRING = "\e[0m";
switch(FG)
{
case 0:{_FG = "\e[30m"; break;}
case 1:{_FG = "\e[31m"; break;}
case 2:{_FG = "\e[32m"; break;}
case 3:{_FG = "\e[33m"; break;}
case 4:{_FG = "\e[34m"; break;}
case 5:{_FG = "\e[35m"; break;}
case 6:{_FG = "\e[36m"; break;}
case 7:{_FG = "\e[37m"; break;}
case 8:{_FG = "\e[90m"; break;}
case 9:{_FG = "\e[91m"; break;}
case 10:{_FG = "\e[92m"; break;}
case 11:{_FG = "\e[93m"; break;}
case 12:{_FG = "\e[95m"; break;}
case 13:{_FG = "\e[96m"; break;}
case 14:{_FG = "\e[97m"; break;}
case 15:{_FG = "\e[0m"; break;}
}
switch (BG)
{
case clBLACK:{_BG = "\e[40m";break;}
case clMAROON:{_BG = "\e[41m";break;}
case clGREEN:{_BG = "\e[42m";break;}
case clOLIVE:{_BG = "\e[43m";break;}
case clNAVY:{_BG = "\e[44m";break;}
case clPURPLE:{_BG = "\e[45m";break;}
case clBLUE:{_BG = "\e[46m";break;}
case clSILVER:{_BG = "\e[47m";break;}
case clGRAY:{_BG = "\e[100m";break;}
case clRED:{_BG = "\e[101m";break;}
case clLIME:{_BG = "\e[102m";break;}
case clYELLOW:{_BG = "\e[103m";break;}
case clMAGENTA:{_BG = "\e[105m";break;}
case clCYAN:{_BG = "\e[106m";break;}
case clWHITE:{_BG = "\e[197m";break;}
}
RETURN_STRING = _BG + _FG + TEXT + RESET_STRING;
return RETURN_STRING;
}
Subscribe to:
Comments (Atom)
-
Today's smudge There's gotta be an easier way..... I still have the "Setter "to write: int TCharGenerator::GetCharLine(b...
-
Smudge for today Written using C++ Builder 6 A simple program that writes a short batch file, runs it and deletes the .bat.U...
-
Snip of the week Written using C++ Builder 6 ENT ShellExecuteEx( ) - When you want to launch another program from your pro...

