Created
March 5, 2019 19:09
-
-
Save tbhaxor/c99a8fba25efac5ab85ca0fc61d705f0 to your computer and use it in GitHub Desktop.
Setting / Unsetting attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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