diff options
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 36 | ||||
-rw-r--r-- | linenoise/linenoise.h | 3 |
2 files changed, 38 insertions, 1 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 0bdd14c1..d84068bd 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -74,7 +74,9 @@ struct lino_state { /* Lifetime enduring state */ lino_compl_cb_t *completion_callback; - void *cb_ctx; /* User context for callback */ + void *cb_ctx; /* User context for completion callback */ + lino_atom_cb_t *atom_callback; + void *ca_ctx; /* User context for atom callback */ struct termios orig_termios; /* In order to restore at exit.*/ int rawmode; /* For atexit() function to check if restore is needed*/ int mlmode; /* Multi line mode. Default is single line. */ @@ -133,6 +135,12 @@ int lino_get_multiline(lino_t *ls) { return ls->mlmode; } +void lino_set_atom_cb(lino_t *l, lino_atom_cb_t *cb, void *ctx) +{ + l->atom_callback = cb; + l->ca_ctx = ctx; +} + static void atexit_handler(void); /* Raw mode: 1960 magic shit. */ @@ -1181,6 +1189,32 @@ static int edit(lino_t *l, const char *prompt) } break; + case CTL('A'): case 'a': + extended = 0; + if (extend_num < 0) + extend_num = 1; + if (l->history_len > 1 && l->atom_callback) + { + char *prev_line = l->history[l->history_len - 2]; + char *word = l->atom_callback(l, prev_line, + extend_num, l->ca_ctx); + const char *p = word; + int res = 0; + + if (word != 0) { + while (*p) + if ((res = edit_insert(l, *p++)) != 0) + break; + + free(word); + } + + if (res) { + l->error = lino_ioerr; + return -1; + } + } + break; default: if (isdigit((unsigned char) c)) { if (extend_num < 0) diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h index 6471993f..94cf3913 100644 --- a/linenoise/linenoise.h +++ b/linenoise/linenoise.h @@ -71,3 +71,6 @@ int lino_hist_load(lino_t *, const char *filename); int lino_clear_screen(lino_t *); void lino_set_multiline(lino_t *, int ml); int lino_get_multiline(lino_t *); + +typedef char *lino_atom_cb_t(lino_t *, const char *line, int n, void *ctx); +void lino_set_atom_cb(lino_t *, lino_atom_cb_t *, void *ctx); |