diff options
author | Joshua Judson Rosen | 2017-03-19 15:31:10 -0400 |
---|---|---|
committer | Joshua Judson Rosen | 2017-03-28 22:07:50 -0400 |
commit | 7bc9c9a84b1cf58a2a35be7f0bcd1c39214cf63f (patch) | |
tree | 3fdee9a848ae2e79321f121d635ce2800e7a4829 | |
parent | catch_handler: restore/fix reporting of actual error-messages (diff) | |
download | gnurobots-7bc9c9a84b1cf58a2a35be7f0bcd1c39214cf63f.tar.gz |
REPL: just use guile's normal REPL
This gives _much_ more useful readline behavior,
since (ice-9 readline) actually knows how to autocomplete
based on the scheme environment, handle multi-line input, etc.;
and properly displays return values and error-messages,
and supports switching to different front-end programming languages
like ecmascript.
Note that we're keeping catch_handler so that we have a chance
of diagnosing problems that could _conceivably_ occur
when interacting with guile during bootstrap
(e.g.: missing readline support, changed REPL API...).
-rw-r--r-- | include/ui-cmdwin.h | 2 | ||||
-rw-r--r-- | src/main.c | 29 | ||||
-rw-r--r-- | src/ui-cmdwin.c | 16 |
3 files changed, 16 insertions, 31 deletions
diff --git a/include/ui-cmdwin.h b/include/ui-cmdwin.h index 1c6196d..c3bcf8a 100644 --- a/include/ui-cmdwin.h +++ b/include/ui-cmdwin.h @@ -52,8 +52,6 @@ struct _UICmdWinClass GType ui_cmdwin_get_type(void) G_GNUC_CONST; GtkWidget *ui_cmdwin_new(void); -void ui_cmdwin_get_string(UICmdWin *cmdwin, gchar *prompt, gchar *buf, - gint len); G_END_DECLS @@ -325,22 +325,25 @@ void main_prog(void *closure, gint argc, gchar *argv[]) } else { - gchar buf[BUFF_LEN]; - g_printf ("Robot program not specified. Entering interactive mode..\n"); - while (1) - { - memset(&buf, 0, BUFF_LEN); - - ui_cmdwin_get_string(UI_CMDWIN(ui->priv->cmdwin), "guile> ", - buf, BUFF_LEN); - - scm_internal_catch(SCM_BOOL_T, - (scm_t_catch_body) scm_c_eval_string, buf, - catch_handler, NULL); - } + scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) scm_c_use_module, + "ice-9 readline", + catch_handler, NULL); + scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) scm_c_eval_string, + "(activate-readline)", + catch_handler, NULL); + scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) scm_c_use_module, + "system repl repl", + catch_handler, NULL); + scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) scm_c_eval_string, + "(start-repl)", + catch_handler, NULL); } /* done */ diff --git a/src/ui-cmdwin.c b/src/ui-cmdwin.c index ce2c9ee..003b845 100644 --- a/src/ui-cmdwin.c +++ b/src/ui-cmdwin.c @@ -68,19 +68,3 @@ static void ui_cmdwin_class_init(UICmdWinClass *klass) g_type_class_add_private(G_OBJECT_CLASS(klass), sizeof(UICmdWinPrivate)); } - -void ui_cmdwin_get_string(UICmdWin *cmdwin, gchar *prompt, gchar *buf, - gint len) -{ - char *line = (char *)NULL; - - line = readline(prompt); - - if (line && *line) - { - add_history(line); - g_strlcpy(buf, line, len); - } - - free(line); -} |