From 7bc9c9a84b1cf58a2a35be7f0bcd1c39214cf63f Mon Sep 17 00:00:00 2001 From: Joshua Judson Rosen Date: Sun, 19 Mar 2017 15:31:10 -0400 Subject: 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...). --- include/ui-cmdwin.h | 2 -- src/main.c | 29 ++++++++++++++++------------- 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 diff --git a/src/main.c b/src/main.c index 62a9210..fcc55f5 100644 --- a/src/main.c +++ b/src/main.c @@ -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); -} -- cgit v1.1