JDK-8265966 : JShell: No custom input (e.g. from GUI) possible with JavaShellToolBuilder
  • Type: CSR
  • Component: tools
  • Sub-Component: jshell
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 17
  • Submitted: 2021-04-26
  • Updated: 2021-05-26
  • Resolved: 2021-05-26
Related Reports
CSR :  
Description
Summary
-------

When using JavaShellToolBuilder API to create a JShell instance, allow the callers to specify whether a simpler ("legacy") format of the output should be used, or whether there is a full interactive terminal that can interpret escape codes is attached.

Problem
-------

There are clients of the JavaShellToolBuilder API that parse the outputs sent by JShell. With enhancements to JShell's ability to interact with the terminal, these clients have trouble parsing the outputs.

Solution
--------

JavaShellToolBuilder will be enhanced with a method that will allow to choose from two modes:
-a simpler mode, where JShell limits the formatting of the output text, similar to the formatting used on JDK 11. This will be the default
-a fully-featured mode, where JShell will assume the output is connected to a full terminal, and will produce output to convenient for the end user looking at the terminal. The exact escape sequences/codes sent won't be specified and will be a subject of change.

Specification
-------------

The proposed method is:
```
    /**
     * Set to true to specify the inputs and outputs are connected to an interactive terminal
     * that can interpret the ANSI escape codes. The characters sent to the output streams are
     * assumed to be interpreted by a terminal and shown to the user, and the exact order and nature
     * of characters sent to the outputs are unspecified.
     *
     * Set to false to specify a legacy simpler behavior whose output can be parsed by automatic
     * tools.
     *
     * When the input stream for this Java Shell is {@code System.in}, this value is ignored,
     * and the behavior is similar to specifying {@code true} in this method, but is more closely
     * following the specific terminal connected to {@code System.in}.
     *
     * @implSpec If this method is not called, the behavior should be
     * equivalent to calling {@code interactiveTerminal(false)}. The default implementation of
     * this method returns {@code this}.
     *
     * @param terminal if {@code true}, an terminal that can interpret the ANSI escape codes is
     *                 assumed to interpret the output. If {@code false}, a simpler output is selected.
     * @return the {@code JavaShellToolBuilder} instance
     * @since 17
     */
    default JavaShellToolBuilder interactiveTerminal(boolean terminal) {
        return this;
    }
```
Comments
Moving to Approved.
26-05-2021