Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333379

Add window size configuration option to JavaShellToolBuilder interface

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 24
    • tools
    • None
    • source
    • minimal
    • The default method means existing code will still be compatible.
    • Java API
    • SE

      Summary

      Add a new method windowSize() to the JavaShellToolBuilder interface that is part of JShell.

      Problem

      When launching JShell programmatically (i.e., from a Java program instead of the command line) for an interactive session, it's not currently possible to inform JShell what the terminal window's dimensions are. As a result, JShell defaults to 80x24 and line editing becomes almost impossible because of the scrambled screen contents (unless you happen to be using an 80x24 window, which these days is very unlikely).

      Solution

      Add a new method windowSize() to the JavaShellToolBuilder interface that is part of JShell. This method takes parameters for number of rows & number of columns and provides this information to the internal JShellTool class, which already knows what to do with it. The new method in JavaShellToolBuilder will have a default implementation which does nothing.

      Specification

      diff --git a/src/jdk.jshell/share/classes/jdk/jshell/tool/JavaShellToolBuilder.java b/src/jdk.jshell/share/classes/jdk/jshell/tool/JavaShellToolBuilder.java
      index c4b4bf66b33..74f4e1a91b3 100644
      --- a/src/jdk.jshell/share/classes/jdk/jshell/tool/JavaShellToolBuilder.java
      +++ b/src/jdk.jshell/share/classes/jdk/jshell/tool/JavaShellToolBuilder.java
      @@ -209,6 +209,24 @@ default JavaShellToolBuilder interactiveTerminal(boolean terminal) {
               return this;
           }
      
      +    /**
      +     * Provide a hint of the display window's dimensions when using an interactive terminal.
      +     *
      +     * <p>
      +     * When the input stream for this Java Shell is {@code System.in}, this setting is ignored.
      +     *
      +     * @implSpec Implementations may choose to ignore this method. The default implementation
      +     * of this method returns {@code this}.
      +     *
      +     * @param columns number of displayed columns
      +     * @param rows number of displayed rows
      +     * @return the {@code JavaShellToolBuilder} instance
      +     * @since 23
      +     */
      +    default JavaShellToolBuilder windowSize(int columns, int rows) {
      +        return this;
      +    }
      +
           /**
            * Run an instance of the Java shell tool as configured by the other methods
            * in this interface.  This call is not destructive, more than one call of

            acobbs Archie Cobbs
            acobbs Archie Cobbs
            Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: