Skip to content

Instantly share code, notes, and snippets.

@tbhaxor
Created March 5, 2019 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbhaxor/c99a8fba25efac5ab85ca0fc61d705f0 to your computer and use it in GitHub Desktop.
Save tbhaxor/c99a8fba25efac5ab85ca0fc61d705f0 to your computer and use it in GitHub Desktop.
Setting / Unsetting attributes
#include <ncurses.h>
using namespace std;
int main(int argc, char const *argv[])
{
initscr();
cbreak();
// checking is terminal supports color
if (!has_colors())
{
printf("no colors");
return 1;
}
// toggling on the attribute
attron(A_BLINK);
// printing the string
printw("blinking");
// toggling off the attribute
attroff(A_BLINK);
printw("\n");
// starting color
start_color();
// init new pair of attr with id = 1 and foreground color = COLOR_WHITE and background color = COLOR_RED
init_pair(1, COLOR_WHITE, COLOR_RED);
attron(COLOR_PAIR(1)); // color attribute with id = 1
printw("This is a colored text");
// attroff(COLOR_PAIR(1));
getch();
endwin();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment