[powerdebug,08/17] Add the find callback

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

Commit Message

Daniel Lezcano June 20, 2011, 10:58 p.m.
Switch the keyboard callback when we switch to the find mode.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 display.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

Patch

diff --git a/display.c b/display.c
index d32783f..758d17e 100644
--- a/display.c
+++ b/display.c
@@ -17,6 +17,7 @@ 
 #include <string.h>
 #include <stdlib.h>
 #include <ncurses.h>
+#include <form.h>
 #include "powerdebug.h"
 #include "mainloop.h"
 #include "regulator.h"
@@ -266,6 +267,19 @@  int display_print_line(int win, int line, char *str, int bold, void *data)
 	return 0;
 }
 
+static int display_find_keystroke(int fd, void *data);
+
+static int display_switch_to_find(int fd)
+{
+	if (mainloop_del(fd))
+		return -1;
+
+	if (mainloop_add(fd, display_find_keystroke, NULL))
+		return -1;
+
+	return 0;
+}
+
 static int display_keystroke(int fd, void *data)
 {
 	int keystroke = getch();
@@ -299,6 +313,9 @@  static int display_keystroke(int fd, void *data)
 	case 'Q':
 		return 1;
 
+	case '/':
+		return display_switch_to_find(fd);
+
 	case 'r':
 	case 'R':
 		/* refresh will be done after */
@@ -312,6 +329,35 @@  static int display_keystroke(int fd, void *data)
 	return 0;
 }
 
+static int display_switch_to_main(int fd)
+{
+	if (mainloop_del(fd))
+		return -1;
+
+	if (mainloop_add(fd, display_keystroke, NULL))
+		return -1;
+
+	display_refresh(current_win);
+
+	return 0;
+}
+
+
+static int display_find_keystroke(int fd, void *data)
+{
+	int keystroke = getch();
+
+	switch (keystroke) {
+
+	case '\e':
+		return display_switch_to_main(fd);
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 int display_init(int wdefault)
 {
 	int i, maxx, maxy;