Add the find callback

Switch the keyboard callback when we switch to the find mode.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
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 @@
 	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 @@
 	case 'Q':
 		return 1;
 
+	case '/':
+		return display_switch_to_find(fd);
+
 	case 'r':
 	case 'R':
 		/* refresh will be done after */
@@ -312,6 +329,35 @@
 	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;