From 7768f03eebca838b8c8cde4d31afb09c1a1f66ec Mon Sep 17 00:00:00 2001
From: Rishabh Dave <rishabhddave@gmail.com>
Date: Tue, 18 Oct 2016 19:56:28 +0530
Subject: [PATCH] feature: add search facility to help

Write the help string in a file and display it using a sub-instance of
nano.

Signed-off-by: Rishabh Dave <rishabhddave@gmail.com>
---
 src/help.c | 131 +++----------------------------------------------------------
 1 file changed, 5 insertions(+), 126 deletions(-)

diff --git a/src/help.c b/src/help.c
index b694192..dcea77f 100644
--- a/src/help.c
+++ b/src/help.c
@@ -38,23 +38,6 @@ static char *end_of_intro = NULL;
 /* Our main help-viewer function. */
 void do_help(void)
 {
-    int kbinput = ERR;
-    bool old_no_help = ISSET(NO_HELP);
-    size_t line = 0;
-	/* The line number in help_text of the first displayed help
-	 * line.  This variable is zero-based. */
-    size_t last_line = 0;
-	/* The line number in help_text of the last help line.  This
-	 * variable is zero-based. */
-    int oldmenu = currmenu;
-	/* The menu we were called from. */
-    const char *ptr;
-	/* The current line of the help text. */
-    size_t old_line = (size_t)-1;
-	/* The line we were on before the current line. */
-    functionptrtype func;
-	/* The function of the key the user typed in. */
-
     /* Don't show a cursor in the help screen. */
     curs_set(0);
     blank_edit();
@@ -72,116 +55,12 @@ void do_help(void)
 	window_init();
     }
 
-    bottombars(MHELP);
-    wnoutrefresh(bottomwin);
-
-    while (TRUE) {
-	size_t i;
-
-	ptr = help_text;
-
-	/* Find the line number of the last line of the help text. */
-	for (last_line = 0; *ptr != '\0'; last_line++) {
-	    ptr += help_line_len(ptr);
-	    if (*ptr == '\n')
-		ptr++;
-	}
-
-	if (last_line > 0)
-	    last_line--;
-
-	/* Redisplay if the text was scrolled or an invalid key was pressed. */
-	if (line != old_line || kbinput == ERR) {
-	    blank_edit();
-
-	    ptr = help_text;
-
-	    /* Advance in the text to the first line to be displayed. */
-	    for (i = 0; i < line; i++) {
-		ptr += help_line_len(ptr);
-		if (*ptr == '\n')
-		    ptr++;
-	    }
-
-	    /* Now display as many lines as the window will hold. */
-	    for (i = 0; i < editwinrows && *ptr != '\0'; i++) {
-		size_t j = help_line_len(ptr);
-
-		mvwaddnstr(edit, i, 0, ptr, j);
-		ptr += j;
-		if (*ptr == '\n')
-		    ptr++;
-	    }
-	}
-
-	wnoutrefresh(edit);
-
-	old_line = line;
-
-	lastmessage = HUSH;
-
-	kbinput = get_kbinput(edit);
-
-#ifndef NANO_TINY
-	if (kbinput == KEY_WINCH) {
-	    kbinput = ERR;
-	    continue;    /* Redraw the screen. */
-	}
-#endif
-
-#ifndef DISABLE_MOUSE
-	if (kbinput == KEY_MOUSE) {
-	    int mouse_x, mouse_y;
-	    get_mouseinput(&mouse_x, &mouse_y, TRUE);
-	    continue;    /* Redraw the screen. */
-	}
-#endif
-
-	func = parse_help_input(&kbinput);
-
-	if (func == total_refresh) {
-	    total_redraw();
-	} else if (func == do_up_void) {
-	    if (line > 0)
-		line--;
-	} else if (func == do_down_void) {
-	    if (line + (editwinrows - 1) < last_line)
-		line++;
-	} else if (func == do_page_up) {
-	    if (line > editwinrows - 2)
-		line -= editwinrows - 2;
-	    else
-		line = 0;
-	} else if (func == do_page_down) {
-	    if (line + (editwinrows - 1) < last_line)
-		line += editwinrows - 2;
-	} else if (func == do_first_line) {
-	    line = 0;
-	} else if (func == do_last_line) {
-	    if (line + (editwinrows - 1) < last_line)
-		line = last_line - (editwinrows - 1);
-	} else if (func == do_exit) {
-	    /* Exit from the help viewer. */
-	    break;
-	} else
-	    unbound_key(kbinput);
-    }
-
-    if (old_no_help) {
-	blank_bottombars();
-	wnoutrefresh(bottomwin);
-	currmenu = oldmenu;
-	SET(NO_HELP);
-	window_init();
-    } else
-	bottombars(oldmenu);
+    FILE *fp = fopen("help.txt", "w");
+    fprintf(fp, "%s", help_text);
+    fclose(fp);
 
-#ifndef DISABLE_BROWSER
-    if (oldmenu == MBROWSER || oldmenu == MWHEREISFILE || oldmenu == MGOTODIR)
-	browser_refresh();
-    else
-#endif
-	edit_refresh();
+    system("nano --view --softwrap ./help.txt");
+    total_refresh();
 
     /* We're exiting from the help screen. */
     free(help_text);
-- 
2.7.4

