aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--display.c30
-rw-r--r--display.h2
-rw-r--r--powerdebug.c10
3 files changed, 26 insertions, 16 deletions
diff --git a/display.c b/display.c
index cf1d5d7..aee5503 100644
--- a/display.c
+++ b/display.c
@@ -66,27 +66,31 @@ static void display_fini(void)
endwin();
}
-void display_init(void)
+int display_init(void)
{
- initscr();
+ if (!initscr())
+ return -1;
+
start_color();
+ use_default_colors();
+
keypad(stdscr, TRUE);
noecho();
cbreak();
curs_set(0);
nonl();
- use_default_colors();
-
- 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);
- atexit(display_fini);
+ 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;
+
+ return atexit(display_fini);
}
void create_windows(int selectedwindow)
diff --git a/display.h b/display.h
index d3c875a..044af6c 100644
--- a/display.h
+++ b/display.h
@@ -22,4 +22,4 @@
#define PT_COLOR_BRIGHT 7
#define PT_COLOR_BLUE 8
-extern void display_init(void);
+extern int display_init(void);
diff --git a/powerdebug.c b/powerdebug.c
index 8244df2..215b0fe 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -261,8 +261,9 @@ int mainloop(struct powerdebug_options *options,
struct timeval tval;
fd_set readfds;
- if (firsttime[0])
- display_init();
+ if (firsttime[0] && display_init())
+ return -1;
+
create_windows(options->selectedwindow);
show_header(options->selectedwindow);
@@ -395,6 +396,11 @@ int main(int argc, char **argv)
return 0;
}
+ if (display_init()) {
+ printf("failed to initialize display\n");
+ return 1;
+ }
+
if (mainloop(options, regulators_info, numregulators))
return 1;