@@ -134,22 +134,38 @@ public void loop(final InputStream in) throws IOException {
134134 }
135135 }
136136
137- /** Outputs a greeting, and sets up the initial language of the REPL. */
137+ /**
138+ * Outputs a greeting, and sets up the initial language and variables of the
139+ * REPL.
140+ */
138141 public void initialize () {
139- out .println ("Welcome to the SciJava REPL!" );
140- out .println ();
141- help ();
142+ initialize (true );
143+ }
144+
145+ /**
146+ * Sets up the initial language and variables of the REPL.
147+ *
148+ * @param verbose Whether to output an initial greeting.
149+ */
150+ public void initialize (final boolean verbose ) {
151+ if (verbose ) {
152+ out .println ("Welcome to the SciJava REPL!" );
153+ out .println ();
154+ help ();
155+ }
142156 final List <ScriptLanguage > langs = getInterpretedLanguages ();
143- if (langs .isEmpty ()) {
144- out .println ("--------------------------------------------------------------" );
145- out .println ("Uh oh! There are no SciJava script languages available!" );
146- out .println ("Are any on your classpath? E.g.: org.scijava:scripting-groovy?" );
147- out .println ("--------------------------------------------------------------" );
157+ if (verbose ) {
158+ if (langs .isEmpty ()) {
159+ out .println ("--------------------------------------------------------------" );
160+ out .println ("Uh oh! There are no SciJava script languages available!" );
161+ out .println ("Are any on your classpath? E.g.: org.scijava:scripting-groovy?" );
162+ out .println ("--------------------------------------------------------------" );
163+ out .println ();
164+ return ;
165+ }
166+ out .println ("Have fun!" );
148167 out .println ();
149- return ;
150168 }
151- out .println ("Have fun!" );
152- out .println ();
153169 lang (langs .get (0 ).getLanguageName ());
154170 populateBindings (interpreter .getBindings ());
155171 }
@@ -249,6 +265,17 @@ public void lang(final String langName) {
249265 out .println ("No such language: " + langName );
250266 return ;
251267 }
268+ lang (language );
269+ out .println ("language -> " + interpreter .getLanguage ().getLanguageName ());
270+ }
271+
272+ /**
273+ * Creates a new {@link ScriptInterpreter} to interpret statements, preserving
274+ * existing variables from the previous interpreter.
275+ *
276+ * @param language The script language of the new interpreter.
277+ */
278+ public void lang (final ScriptLanguage language ) {
252279 final ScriptInterpreter newInterpreter =
253280 new DefaultScriptInterpreter (language );
254281
@@ -259,8 +286,6 @@ public void lang(final String langName) {
259286 catch (final Throwable t ) {
260287 t .printStackTrace (out );
261288 }
262- out .println ("language -> " +
263- newInterpreter .getLanguage ().getLanguageName ());
264289 interpreter = newInterpreter ;
265290 }
266291
0 commit comments