diff mbox

[powerdebug,08/22] Encapsulate the display (1)

Message ID 1308145856-6112-8-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 15, 2011, 1:50 p.m. UTC
Remove some corner cases for the footer display we have the same
display feature for all the pm blocks.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 display.c    |  104 +++++++++++++++++++++++----------------------------------
 display.h    |    2 +-
 powerdebug.c |    9 ++---
 powerdebug.h |   20 ++---------
 4 files changed, 49 insertions(+), 86 deletions(-)
diff mbox

Patch

diff --git a/display.c b/display.c
index c6a68a7..fa7d93a 100644
--- a/display.c
+++ b/display.c
@@ -18,7 +18,6 @@ 
 #include "display.h"
 
 #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
-#define NUM_FOOTER_ITEMS 5
 
 enum { PT_COLOR_DEFAULT = 1,
        PT_COLOR_HEADER_BAR,
@@ -38,7 +37,8 @@  int maxx, maxy;
 /* Number of lines in the virtual window */
 static const int maxrows = 1024;
 
-static char footer_items[NUM_FOOTER_ITEMS][64];
+#define footer_label " Q (Quit)  R (Refresh) Other Keys: 'Left', " \
+	"'Right' , 'Up', 'Down', 'enter', , 'Esc'"
 
 struct rowdata {
 	int attr;
@@ -66,7 +66,39 @@  static void display_fini(void)
 	endwin();
 }
 
-int display_init(void)
+static int show_header_footer(int win)
+{
+	int i;
+	int curr_pointer = 0;
+
+	wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
+	wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
+	werase(header_win);
+
+	print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
+	curr_pointer += 20;
+
+	for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
+		if (win == i)
+			wattron(header_win, A_REVERSE);
+		else
+			wattroff(header_win, A_REVERSE);
+
+		print(header_win, curr_pointer, 0, " %s ", windata[i].name);
+		curr_pointer += strlen(windata[i].name) + 2;
+	}
+	wrefresh(header_win);
+	werase(footer_win);
+
+	wattron(footer_win, A_REVERSE);
+	print(footer_win, 0, 0, "%s", footer_label);
+	wattroff(footer_win, A_REVERSE);
+	wrefresh(footer_win);
+
+	return 0;
+}
+
+int display_init(int wdefault)
 {
 	int i;
 	size_t array_size = sizeof(windata) / sizeof(windata[0]);
@@ -118,65 +150,7 @@  int display_init(void)
 	if (!footer_win)
 		return -1;
 
-	return 0;
-}
-
-void create_windows(int selectedwindow)
-{
-	strcpy(footer_items[0], " Q (Quit) ");
-	strcpy(footer_items[1], " R (Refresh) ");
-
-	if (selectedwindow == CLOCK)
-		strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
-			" '/', 'Esc' ");
-	else
-		strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
-
-	strcpy(footer_items[3], "");
-
-	werase(stdscr);
-	refresh();
-
-}
-
-void create_selectedwindow(int win)
-{
-	wrefresh(windata[win].win);
-}
-
-void show_header(int selectedwindow)
-{
-	int i, j = 0;
-	int curr_pointer = 0;
-
-	wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
-	wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
-	werase(header_win);
-
-	print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
-	curr_pointer += 20;
-
-	for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
-		if (selectedwindow == i)
-			wattron(header_win, A_REVERSE);
-		else
-			wattroff(header_win, A_REVERSE);
-
-		print(header_win, curr_pointer, 0, " %s ", windata[i].name);
-		curr_pointer += strlen(windata[i].name) + 2;
-	}
-	wrefresh(header_win);
-	werase(footer_win);
-
-	for (i = 0; i < NUM_FOOTER_ITEMS; i++) {
-		if (strlen(footer_items[i]) == 0)
-			continue;
-		wattron(footer_win, A_REVERSE);
-		print(footer_win, j, 0, "%s", footer_items[i]);
-		wattroff(footer_win, A_REVERSE);
-		j+= strlen(footer_items[i])+1;
-	}
-	wrefresh(footer_win);
+	return show_header_footer(wdefault);
 }
 
 void print_regulator_header(void)
@@ -195,6 +169,8 @@  void print_regulator_header(void)
 	print(regulator_win, 84, 0, "Max u-volts");
 	wattroff(regulator_win, A_BOLD);
 	wrefresh(regulator_win);
+
+	show_header_footer(REGULATOR);
 }
 
 void print_clock_header(void)
@@ -210,6 +186,8 @@  void print_clock_header(void)
 	print(clock_win, 98, 0, "Children");
 	wattroff(clock_win, A_BOLD);
 	wrefresh(clock_win);
+
+	show_header_footer(CLOCK);
 }
 
 void print_sensor_header(void)
@@ -222,6 +200,8 @@  void print_sensor_header(void)
 	print(sensor_win, 36, 0, "Value");
 	wattroff(sensor_win, A_BOLD);
 	wrefresh(sensor_win);
+
+	show_header_footer(SENSOR);
 }
 
 int display_refresh_pad(int win)
diff --git a/display.h b/display.h
index 047d674..0b407fb 100644
--- a/display.h
+++ b/display.h
@@ -13,4 +13,4 @@ 
  *       - initial API and implementation
  *******************************************************************************/
 
-extern int display_init(void);
+extern int display_init(int wdefault);
diff --git a/powerdebug.c b/powerdebug.c
index 0eee7c5..4d94829 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -258,11 +258,8 @@  int mainloop(struct powerdebug_options *options)
 		struct timeval tval;
 		fd_set readfds;
 
-		if (options->selectedwindow != CLOCK || !cont) {
-			create_windows(options->selectedwindow);
-			show_header(options->selectedwindow);
-			create_selectedwindow(options->selectedwindow);
-		}
+		/* if (options->selectedwindow != CLOCK || !cont) */
+		/* 	show_header(options->selectedwindow); */
 
 		if (options->selectedwindow == REGULATOR)
 			regulator_display();
@@ -328,7 +325,7 @@  static int powerdebug_dump(struct powerdebug_options *options)
 
 static int powerdebug_display(struct powerdebug_options *options)
 {
-	if (display_init()) {
+	if (display_init(options->selectedwindow)) {
 		printf("failed to initialize display\n");
 		return -1;
 	}
diff --git a/powerdebug.h b/powerdebug.h
index 7175839..712acb2 100644
--- a/powerdebug.h
+++ b/powerdebug.h
@@ -28,13 +28,7 @@ 
 enum {CLOCK, REGULATOR, SENSOR};
 enum {CLOCK_SELECTED = 1, REFRESH_WINDOW};
 
-extern int read_and_dump_clock_info(char *clk);
 extern void find_parents_for_clock(char *clkname, int complete);
-extern int read_and_print_clock_info(void);
-extern int print_clock_info(int hrow, int selected);
-extern void print_string_val(char *name, char *val);
-extern void print_clock_header(void);
-
 extern int display_print_line(int window, int line, char *str,
 			      int bold, void *data);
 
@@ -45,16 +39,8 @@  extern int display_prev_line(int window);
 extern void *display_get_row_data(int window);
 
 extern int clock_toggle_expanded(void);
-extern int display_clock_select(int window, int line);
-extern int display_clock_unselect(int window, int line, bool bold);
-
-extern void get_sensor_info(char *path, char *name, char *sensor, int verbose);
-extern int  sensor_dump(void);
+extern int regulator_display(void);
 extern void print_sensor_header(void);
+extern void print_clock_header(void);
+extern void print_regulator_header(void);
 
-extern void killall_windows(int all);
-extern void show_header(int selectedwindow);
-extern void create_windows(int selectedwindow);
-extern void create_selectedwindow(int selectedwindow);
-
-extern int regulator_display(void);