aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThara Gopinath <thara.gopinath@linaro.org>2017-07-14 13:15:46 -0400
committerLisa Nguyen <lisa.nguyen@linaro.org>2017-09-19 12:56:31 -0700
commit569054ea21aee41d84e9b864c0c381ab9b988541 (patch)
tree697c01b4fd55f2f41f2f1261ea2192fd9385bb46
parentd78818c4670e4ebc59ed98a5322fcee286e3b4fc (diff)
Check if terminal supports changing color definitions.
This patch adds the check whether the terminal supports colors and allows changing color definitions before actually attempting to redifine the color definitions. Without this check, attempting to change color definitions in a color not supported terminal causes a hang. Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
-rw-r--r--display.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/display.c b/display.c
index e34d083..6b2404e 100644
--- a/display.c
+++ b/display.c
@@ -576,15 +576,17 @@ int display_init(struct powerdebug_options *options)
curs_set(0);
nonl();
- if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) ||
- init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) ||
- init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) ||
- init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) ||
- init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) ||
- init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) ||
- init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) ||
- init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED))
- return -1;
+ if (can_change_color()) {
+ if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) ||
+ init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) ||
+ init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) ||
+ init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) ||
+ init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) ||
+ init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) ||
+ init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) ||
+ init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED))
+ return -1;
+ }
if (atexit(display_fini))
return -1;