diff options
| author | Tesori Delle Api <pi@rasbperry> | 2025-05-13 19:40:33 (GMT) |
|---|---|---|
| committer | Tesori Delle Api <pi@rasbperry> | 2025-05-13 19:40:33 (GMT) |
| commit | 78732167010d29f35ccf4dccf566392ddf03a729 (patch) | |
| tree | 4d93f7659a677f4705d614c80a6fa4e9640a503d | |
| parent | 689270ed61c0e3964144ece380c62d3784fde9c1 (diff) | |
| parent | fb13647e6aef47c175412be7a08f655e016bf587 (diff) | |
Merge branch 'from-alienbuntu' of tidal.blue:srv/cgit/nanoboxfrom-tda
| -rw-r--r-- | nanobox.c | 131 |
1 files changed, 126 insertions, 5 deletions
@@ -78,6 +78,9 @@ //config: help //config: Select this if you wish to be able to do search and replace. //config: +#define ENABLE_FEATURE_NANO_CORRECT_SEARCH 1 +//config: bool "Better support 0-chars in text, and perhaps (slightly) more efficent search" +#define ENABLE_FEATURE_NANO_REVERSE_SEARCH 1 #define ENABLE_FEATURE_NANO_REGEX_SEARCH 0 //config:config FEATURE_NANO_REGEX_SEARCH //config: bool "Enable regex in search and replace" @@ -179,6 +182,7 @@ //config: This option makes the HOME and RETURN key behave differently //config: depending on the current indentation level. //config: +#define ENABLE_FEATURE_NANO_GOTO_LINE 1 #define ENABLE_FEATURE_NANO_DEVTTY 1 #define ENABLE_FEATURE_NANO_STDIO 1 //config:config FEATURE_NANO_STDIO_C @@ -234,6 +238,7 @@ #include <sys/stat.h> #include <sys/poll.h> #include <sys/ioctl.h> +#include <sys/time.h #if 1 #include "platform.h" #define FALSE 0 @@ -606,6 +611,7 @@ static void screen_erase(void); static void clear_to_eol(void); static void clear_to_eos(void); static void go_bottom_and_clear_to_eol(void); +static void go_to_line(char*); static void standout_start(void); // send "start reverse video" sequence static void standout_end(void); // send "end reverse video" sequence static void show_status_line(void); // put a message on the bottom line @@ -889,7 +895,18 @@ static void edit_file(char *fn) offset = 0; // no horizontal offset c = '\0'; - redraw(FALSE); // dont force every col re-draw + if (nano_stdio_mode) { + dot = end; + redraw(FALSE); // dont force every col re-draw + dot_left(); + // dot_left(); + // dot_left(); + refresh(FALSE); + // fprintf(stderr, "%s\n", "XXXXXXXXXXXXXXXXXXXXX"); + // show_status_line(); + } else { + redraw(FALSE); // dont force every col re-draw + } //------This is the main Nano cmd handling loop ----------------------- while (editing > 0) { #if ENABLE_FEATURE_NANO_CRASHME @@ -922,7 +939,9 @@ static void edit_file(char *fn) } //------------------------------------------------------------------- - go_bottom_and_clear_to_eol(); + if (!nano_stdio_mode) { + go_bottom_and_clear_to_eol(); + } cookmode(); #undef cur_line } @@ -2465,6 +2484,21 @@ static void not_implemented(const char *s) static char last_key_code = 0; #endif +static void go_to_line(char*line) +{ + int lineno; + if (strcmp(line, "!") == 0) { + srand(time(NULL)); + lineno = rand() % count_lines(text, end - 1); + } else { + lineno = atoi(line); + if (!(lineno > 1)) return; + lineno--; + } + for (dot = text; lineno > 0 && dot < end; lineno--) dot = next_line(dot); +} + + // show file status on status line static int format_edit_status(void) { @@ -2518,7 +2552,7 @@ static int format_edit_status(void) #if 0 " %ld" #endif - " ^X=Exit ^O=Save ^W=Search ^K=Cut ^U=Paste M-u=Undo", + " ^X=Exit ^O=Save ^W=Search ^K=Cut ^U=Paste ^_=GoTo M-u=Undo", (current_filename != NULL ? current_filename : ""), #if ENABLE_FEATURE_NANO_READONLY (readonly_mode ? " [Readonly]" : ""), @@ -2798,6 +2832,50 @@ static void fold_cmd(void) // 78 x 79 y 7a z 7b { 7c | 7d } 7e ~ 7f del //--------------------------------------------------------------------- + +#if ENABLE_FEATURE_NANO_REVERSE_SEARCH +static char *rstrstr(const char * haystack, const char * needle, const char * start) { + const char *h, *n; + if (start == NULL) { + for (start = haystack; *start != 0; start++); + } + while (--start >= haystack) { + for (h = start, n = needle; *h == *n; h++, n++) { + if (*n == 0) return (char*)start; + } + if (*n == 0) return (char*)start; + } +} +#endif + +#if ENABLE_FEATURE_NANO_CORRECT_SEARCH +#if 0 +static char *strstr(const char * haystack, const char * needle) { + const char *h, *n; + while (*haystack != 0) { + for (h = haystack, n = needle; *h == *n; h++, n++) { + if (*n == 0) return (char*)haystack; + } + if (*n == 0) return (char*)haystack; + haystack++; + } + return NULL; +} +#endif +static char *strstrx(const char * haystack, const char * needle, const char * before) { + const char *h, *n; + // before shouldn't be NULL! + while (haystack < before) { + for (h = haystack, n = needle; *h == *n; h++, n++) { + if (*n == 0) return (char*)haystack; + } + if (*n == 0) return (char*)haystack; + haystack++; + } + return NULL; +} +#endif + //----- Execute a Nano Command ----------------------------------- static void do_cmd(int c) { @@ -2974,17 +3052,58 @@ static void do_cmd(int c) editing = 0; continue_editing: break; +#if ENABLE_FEATURE_NANO_GOTO_LINE + case CTRL_CODE('_'): + // p = get_input_line("Jump to line [!=random]: ", buf); + p = get_input_line("Go to line [!=random]: ", buf); + strcpy(buf, p); + go_to_line(p); + break; +#endif #if ENABLE_FEATURE_NANO_SEARCH +#if ENABLE_FEATURE_NANO_REVERSE_SEARCH + case CTRL_CODE('Y'): +#define buf search__buf + if (dot == NULL) dot = end; // not sure if this is really needed, segfaults observed during search + p = get_input_line("Search: ", buf); + strcpy(buf, p); + q = dot > text ? rstrstr(text, p, dot) : NULL; + char *info_dot = dot; + if (q != NULL) { + dot = q; + } else { + q = rstrstr(dot, p, end); + if (q != NULL) { + status_line_bold("Search wrapped!"); + dot = q; + } else { + status_line_bold("String not found: %s", p); + } + } +#undef buf + break; +#endif case CTRL_CODE('W'): #define buf search__buf + if (dot == NULL) dot = end; // not sure if this is really needed, segfaults observed during search! p = get_input_line("Search: ", buf); strcpy(buf, p); - q = dot + 1 < end ? strstr(dot+1, p) : NULL; + q = dot + 1 < end ? +#if ENABLE_FEATURE_NANO_CORRECT_SEARCH + strstrx(dot+1, p, end) +#else + strstr(dot+1, p) +#endif + : NULL; if (q != NULL) { dot = q; } else { - // This may scan parts of the buffer twice but is still correct and much simpler to implement. +#if ENABLE_FEATURE_NANO_CORRECT_SEARCH + q = strstrx(text, p, dot); +#else + // This may scan parts of the buffer twice but is still correct and much simpler to code q = strstr(text, p); +#endif if (q != NULL) { status_line_bold("Search wrapped!", p); dot = q; @@ -2995,9 +3114,11 @@ static void do_cmd(int c) #undef buf break; #endif +#if !(ENABLE_FEATURE_NANO_SEARCH && ENABLE_FEATURE_NANO_REVERSE_SEARCH) case 25: // ctrl-Y scroll up one line dot_scroll(1, -1); break; +#endif case KEYCODE_RIGHT: // Cursor Key Right dot_right(); break; |
