Skip to content

Commit

Permalink
Add quick-and-dirty rline for use in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed Dec 17, 2016
1 parent 0bfe9d0 commit b4abf03
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions userspace/lib/rline.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,34 @@ int rline(char * buffer, int buf_size, rline_callbacks_t * callbacks) {
set_buffered();
return context.collected;
}


static char * last_prompt = NULL;
static void redraw_prompt(rline_context_t * c) {
(void)c;
printf("%s", last_prompt);
fflush(stdout);
return;
}
static void insert_tab(rline_context_t * c) {
rline_insert(c, "\t");
rline_redraw_clean(c);
}

void * rline_for_python(void * _stdin, void * _stdout, char * prompt) {
last_prompt = prompt;

rline_callbacks_t callbacks = {
insert_tab, redraw_prompt, NULL,
NULL, NULL, NULL, NULL, NULL
};


redraw_prompt(NULL);
char * buf = malloc(1024);
memset(buf, 0, 1024);
rline(buf, 1024, &callbacks);
rline_history_insert(strdup(buf));

return buf;
}

0 comments on commit b4abf03

Please sign in to comment.