turning off contiuation mode Re: JShellTool and future directions

Michel Trudeau michel.trudeau at oracle.com
Thu Jul 22 22:38:19 UTC 2021


[cc’ing kulla-dev]

From: Korbi Schmid <korbi.schmid at oracle.com>
Date: Thursday, July 22, 2021 at 7:49 AM
To: Robert Field <robert.field at oracle.com>
Cc: Michel Trudeau <michel.trudeau at oracle.com>, Miguel Delgadillo <miguel.d.delgadillo at oracle.com>, Francisco Riestra <francisco.riestra at oracle.com>, Melliyal Annamalai <melliyal.annamalai at oracle.com>, Steve Serra <steven.serra at oracle.com>
Subject: turning off contiuation mode Re: JShellTool and future directions


Hi Robert

I'm "hijacking" this older thread because we just ran into another problem with JShellTool and wonder if there's a simple trick here as well. Is there any way to "turn off" continuation prompt? I mean this behavior where the shell waits for more input instead of giving an error:

jshell> System.out.println("I forgot to close the brace"
   ...>
   ...>
   ...>

When used programmatically, this causes confusion because in our app there is no visual indicator like "...>" suggesting more input is required. For us it would be better if the tool directly prints out the syntax error instead of waiting for more input.

Thanks
Korbi
On 6/5/19 5:51 PM, Robert Field wrote:

Hi Martijn,

The JShell API was designed as an API, the tool was not.  However, I understand the desire to reuse the functionality of the tool.

Your 1 and 2 can be achieved with modes, for example --

% cat > /tmp/jsmode
/set mode jsmode -quiet
/set prompt jsmode "pgx> " "...> "
/set mode -retain jsmode
% jshell --startup /tmp/jsmode --feedback jsmode
pgx>

For 3, I don't know how you plan to hook into the jshell tool, but if you are capturing command output, the value is in an easily parsed form --

jshell> 45
$1 ==> 45

Basically look for "$<n> ==>".  Of course, that requires you to be in a -command mode not a -quiet mode ;-)
If you are capturing command output you can just filter out the welcome message and avoid the -quiet mode.

Alternatively, you could hook in through the SPI, and nab the value of ExecutionControl.invoke(...) by overriding it.

There are no plans to make an API for the tool.  I don't know what your needs are, hopefully simple tricks like the above will fit your needs.  Let me know if you have more problems.

Otherwise, you can use the JShell API, cloning as much or all of the tool as needed -- with the ensuing maintenance issues.

Hope that helps,
Robert




On 6/5/19 8:33 AM, Martijn Dwars wrote:
Hello Robert,

I am part of the PGX team (Oracle Labs) where we develop PGX, a Parallel Graph AnalytiX engine. PGX currently comes with a Groovy shell, but we are in the process of replacing this Groovy-based shell by a JShell-based shell. We were considering using the JShellTool, since it adds a lot of useful functionality to the bare JShell. However, the public API of the JShellTool is very restricted. Some problems that we ran into:


  1.  It is not possible to change the prompt from "jshell>" into "pgx>". We tried to do this by creating a feedback mode in a startup script, but the startup script is loaded before the pre-defined feedback modes are loaded.
  2.  It is not possible to suppress the jshell welcome message ("Welcome to JShell -- Version 11.0.2”).
  3.  It is not possible to access the values of the expressions (in particular, we would like to capture the value of the last expression after evaluating a piece of code).

Could you tell me if we are correct in that the above is not possible with the JShellTool? Are there plans to open up the JShellTool API in the future, or are we better off building our own solution on top of JShell (and reimplementing most of the functionality found in JShellTool)?

Kind regards,

Martijn Dwars


More information about the kulla-dev mailing list