summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2024-01-08 01:21:56 (GMT)
committerMichele Bini <michele.bini@gmail.com>2024-01-08 01:23:46 (GMT)
commitb08732f9c11abfdb630e6620c108c65f5301ee8b (patch)
treefc85ef9b4eac50a40baf98484a047088e8bd452f
parent84557ccf578ded16467fab36529ffa16333dfab5 (diff)
Ctrl-_ for seek to line by number, or random line
Improve support of pipe mode
-rw-r--r--nanobox.c45
1 files changed, 42 insertions, 3 deletions
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 <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 +608,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 +892,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 +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