From b08732f9c11abfdb630e6620c108c65f5301ee8b Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Mon, 8 Jan 2024 02:21:56 +0100 Subject: Ctrl-_ for seek to line by number, or random line Improve support of pipe mode diff --git a/nanobox.c b/nanobox.c index fec354c..2242d04 100644 --- a/nanobox.c +++ b/nanobox.c @@ -179,6 +179,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 +235,7 @@ #include #include #include +#include 0) { #if ENABLE_FEATURE_NANO_CRASHME @@ -922,7 +936,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 +2481,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 +2549,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]" : ""), @@ -2974,6 +3005,14 @@ 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 case CTRL_CODE('W'): #define buf search__buf -- cgit v0.10.2