summaryrefslogtreecommitdiffstats
path: root/linenoise
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-12 20:04:16 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-12 20:04:16 -0700
commitd367c9e2fb84ec6d4a13faf18375dacefaa6fdc9 (patch)
treeabc3e2770c22548c9a37fe4e7d87b5b127dd898b /linenoise
parentd499b2062a0f88be35a3ebb2e75c99c695f9f383 (diff)
downloadtxr-d367c9e2fb84ec6d4a13faf18375dacefaa6fdc9.tar.gz
txr-d367c9e2fb84ec6d4a13faf18375dacefaa6fdc9.tar.bz2
txr-d367c9e2fb84ec6d4a13faf18375dacefaa6fdc9.zip
linenoise: Ctrl-X Ctrl-P edits result of command.
* linenoise/linenoise.c (struct lino_state): New member, result. (edit): Ctrl-P or p in extended mode cause result string to be inserted into the buffer. (lino_copy): Ensure result string in copy is null. (lino_cleanup): Free result string and set to null. (lino_set_result): New function. * linenoise/linenoise.h (lino_set_result): Declared.
Diffstat (limited to 'linenoise')
-rw-r--r--linenoise/linenoise.c20
-rw-r--r--linenoise/linenoise.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 78949cc8..524324e4 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -96,6 +96,7 @@ struct lino_state {
int history_len;
char **history;
char *clip; /* Selection */
+ char *result; /* Previous command result. */
int ifd; /* Terminal stdin file descriptor. */
int ofd; /* Terminal stdout file descriptor. */
int save_hist_idx; /* Jump to history position on entry into edit */
@@ -1857,6 +1858,16 @@ static int edit(lino_t *l, const char *prompt)
}
}
break;
+ case CTL('P'): case 'p':
+ extended = 0;
+ if (l->result) {
+ int res = edit_insert_str(l, l->result, strlen(l->result));
+ if (res) {
+ l->error = lino_ioerr;
+ goto out;
+ }
+ }
+ break;
case CTL('Q'):
extended = 0;
{
@@ -2268,6 +2279,7 @@ lino_t *lino_copy(lino_t *le)
ls->history = 0;
ls->rawmode = 0;
ls->clip = 0;
+ ls->result = 0;
ls->undo_stack = 0;
link_into_list(&lino_list, ls);
@@ -2286,6 +2298,8 @@ static void lino_cleanup(lino_t *ls)
free_undo_stack(ls);
free(ls->clip);
ls->clip = 0;
+ free(ls->result);
+ ls->result = 0;
}
void lino_free(lino_t *ls)
@@ -2449,3 +2463,9 @@ int lino_hist_load(lino_t *ls, const char *filename) {
fclose(fp);
return 0;
}
+
+void lino_set_result(lino_t *ls, char *res)
+{
+ free(ls->result);
+ ls->result = res;
+}
diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h
index f6b692e5..454523a9 100644
--- a/linenoise/linenoise.h
+++ b/linenoise/linenoise.h
@@ -69,6 +69,7 @@ int lino_hist_add(lino_t *, const char *line);
int lino_hist_set_max_len(lino_t *, int len);
int lino_hist_save(lino_t *, const char *filename);
int lino_hist_load(lino_t *, const char *filename);
+void lino_set_result(lino_t *, char *);
int lino_clear_screen(lino_t *);
void lino_set_multiline(lino_t *, int ml);
int lino_get_multiline(lino_t *);