src/jdk.internal.le/share/classes/jdk/internal/org/jline/terminal/Terminal.java
author pliden
Fri, 13 Sep 2019 08:40:09 +0200
changeset 58125 9b4717ca9bd1
parent 52938 5ff7480c9e28
child 58903 eeb1c0da2126
permissions -rw-r--r--
8230878: ZGC: Use THREAD_LOCAL instead of __thread Reviewed-by: kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52938
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     1
/*
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2002-2018, the original author or authors.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     3
 *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     4
 * This software is distributable under the BSD license. See the terms of the
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     5
 * BSD license in the documentation provided with this software.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     6
 *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     7
 * http://www.opensource.org/licenses/bsd-license.php
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     8
 */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     9
package jdk.internal.org.jline.terminal;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    10
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    11
import java.io.Closeable;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    12
import java.io.Flushable;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    13
import java.io.InputStream;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    14
import java.io.OutputStream;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    15
import java.io.PrintWriter;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    16
import java.nio.charset.Charset;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    17
import java.util.function.IntConsumer;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    18
import java.util.function.IntSupplier;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    19
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    20
import jdk.internal.org.jline.terminal.impl.NativeSignalHandler;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    21
import jdk.internal.org.jline.utils.InfoCmp.Capability;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    22
import jdk.internal.org.jline.utils.NonBlockingReader;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    23
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    24
/**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    25
 * A terminal representing a virtual terminal on the computer.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    26
 *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    27
 * Terminals should be closed by calling the {@link #close()} method
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    28
 * in order to restore their original state.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    29
 */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    30
public interface Terminal extends Closeable, Flushable {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    31
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    32
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    33
     * Type used for dumb terminals.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    34
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    35
    String TYPE_DUMB = "dumb";
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    36
    String TYPE_DUMB_COLOR = "dumb-color";
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    37
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    38
    String getName();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    39
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    40
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    41
    // Signal support
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    42
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    43
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    44
    enum Signal {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    45
        INT,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    46
        QUIT,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    47
        TSTP,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    48
        CONT,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    49
        INFO,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    50
        WINCH
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    51
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    52
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    53
    interface SignalHandler {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    54
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    55
        SignalHandler SIG_DFL = NativeSignalHandler.SIG_DFL;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    56
        SignalHandler SIG_IGN = NativeSignalHandler.SIG_IGN;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    57
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    58
        void handle(Signal signal);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    59
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    60
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    61
    SignalHandler handle(Signal signal, SignalHandler handler);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    62
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    63
    void raise(Signal signal);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    64
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    65
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    66
    // Input / output
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    67
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    68
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    69
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    70
     * Retrieve the <code>Reader</code> for this terminal.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    71
     * This is the standard way to read input from this terminal.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    72
     * The reader is non blocking.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    73
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    74
     * @return The non blocking reader
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    75
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    76
    NonBlockingReader reader();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    77
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    78
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    79
     * Retrieve the <code>Writer</code> for this terminal.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    80
     * This is the standard way to write to this terminal.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    81
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    82
     * @return The writer
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    83
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    84
    PrintWriter writer();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    85
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    86
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    87
     * Returns the {@link Charset} that should be used to encode characters
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    88
     * for {@link #input()} and {@link #output()}.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    89
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    90
     * @return The terminal encoding
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    91
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    92
    Charset encoding();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    93
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    94
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    95
     * Retrieve the input stream for this terminal.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    96
     * In some rare cases, there may be a need to access the
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    97
     * terminal input stream directly. In the usual cases,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    98
     * use the {@link #reader()} instead.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    99
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   100
     * @return The input stream
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   101
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   102
     * @see #reader()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   103
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   104
    InputStream input();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   105
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   106
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   107
     * Retrieve the output stream for this terminal.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   108
     * In some rare cases, there may be a need to access the
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   109
     * terminal output stream directly. In the usual cases,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   110
     * use the {@link #writer()} instead.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   111
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   112
     * @return The output stream
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   113
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   114
     * @see #writer();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   115
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   116
    OutputStream output();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   117
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   118
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   119
    // Input control
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   120
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   121
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   122
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   123
     * Whether this terminal supports {@link #pause()} and {@link #resume()} calls.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   124
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   125
     * @return whether this terminal supports {@link #pause()} and {@link #resume()} calls.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   126
     * @see #paused()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   127
     * @see #pause()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   128
     * @see #resume()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   129
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   130
    boolean canPauseResume();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   131
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   132
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   133
     * Stop reading the input stream.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   134
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   135
     * @see #resume()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   136
     * @see #paused()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   137
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   138
    void pause();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   139
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   140
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   141
     * Stop reading the input stream and optionally wait for the underlying threads to finish.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   142
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   143
     * @param wait <code>true</code> to wait until the terminal is actually paused
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   144
     * @throws InterruptedException if the call has been interrupted
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   145
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   146
    void pause(boolean wait) throws InterruptedException;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   147
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   148
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   149
     * Resume reading the input stream.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   150
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   151
     * @see #pause()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   152
     * @see #paused()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   153
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   154
    void resume();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   155
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   156
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   157
     * Check whether the terminal is currently reading the input stream or not.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   158
     * In order to process signal as quickly as possible, the terminal need to read
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   159
     * the input stream and buffer it internally so that it can detect specific
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   160
     * characters in the input stream (Ctrl+C, Ctrl+D, etc...) and raise the
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   161
     * appropriate signals.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   162
     * However, there are some cases where this processing should be disabled, for
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   163
     * example when handing the terminal control to a subprocess.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   164
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   165
     * @return whether the terminal is currently reading the input stream or not
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   166
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   167
     * @see #pause()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   168
     * @see #resume()
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   169
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   170
    boolean paused();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   171
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   172
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   173
    // Pty settings
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   174
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   175
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   176
    Attributes enterRawMode();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   177
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   178
    boolean echo();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   179
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   180
    boolean echo(boolean echo);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   181
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   182
    Attributes getAttributes();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   183
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   184
    void setAttributes(Attributes attr);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   185
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   186
    Size getSize();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   187
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   188
    void setSize(Size size);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   189
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   190
    default int getWidth() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   191
        return getSize().getColumns();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   192
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   193
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   194
    default int getHeight() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   195
        return getSize().getRows();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   196
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   197
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   198
    void flush();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   199
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   200
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   201
    // Infocmp capabilities
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   202
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   203
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   204
    String getType();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   205
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   206
    boolean puts(Capability capability, Object... params);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   207
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   208
    boolean getBooleanCapability(Capability capability);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   209
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   210
    Integer getNumericCapability(Capability capability);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   211
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   212
    String getStringCapability(Capability capability);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   213
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   214
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   215
    // Cursor support
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   216
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   217
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   218
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   219
     * Query the terminal to report the cursor position.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   220
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   221
     * As the response is read from the input stream, some
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   222
     * characters may be read before the cursor position is actually
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   223
     * read. Those characters can be given back using
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   224
     * <code>org.jline.keymap.BindingReader#runMacro(String)</code>
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   225
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   226
     * @param discarded a consumer receiving discarded characters
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   227
     * @return <code>null</code> if cursor position reporting
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   228
     *                  is not supported or a valid cursor position
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   229
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   230
    Cursor getCursorPosition(IntConsumer discarded);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   231
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   232
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   233
    // Mouse support
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   234
    //
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   235
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   236
    enum MouseTracking {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   237
        /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   238
         * Disable mouse tracking
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   239
         */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   240
        Off,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   241
        /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   242
         * Track button press and release.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   243
         */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   244
        Normal,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   245
        /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   246
         * Also report button-motion events.  Mouse movements are reported if the mouse pointer
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   247
         * has moved to a different character cell.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   248
         */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   249
        Button,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   250
        /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   251
         * Report all motions events, even if no mouse button is down.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   252
         */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   253
        Any
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   254
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   255
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   256
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   257
     * Returns <code>true</code> if the terminal has support for mouse.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   258
     * @return whether mouse is supported by the terminal
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   259
     * @see #trackMouse(MouseTracking)
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   260
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   261
    boolean hasMouseSupport();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   262
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   263
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   264
     * Change the mouse tracking mouse.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   265
     * To start mouse tracking, this method must be called with a valid mouse tracking mode.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   266
     * Mouse events will be reported by writing the {@link Capability#key_mouse} to the input stream.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   267
     * When this character sequence is detected, the {@link #readMouseEvent()} method can be
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   268
     * called to actually read the corresponding mouse event.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   269
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   270
     * @param tracking the mouse tracking mode
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   271
     * @return <code>true</code> if mouse tracking is supported
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   272
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   273
    boolean trackMouse(MouseTracking tracking);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   274
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   275
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   276
     * Read a MouseEvent from the terminal input stream.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   277
     * Such an event must have been detected by scanning the terminal's {@link Capability#key_mouse}
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   278
     * in the stream immediately before reading the event.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   279
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   280
     * @return the decoded mouse event.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   281
     * @see #trackMouse(MouseTracking)
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   282
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   283
    MouseEvent readMouseEvent();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   284
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   285
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   286
     * Read a MouseEvent from the given input stream.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   287
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   288
     * @param reader the input supplier
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   289
     * @return the decoded mouse event
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   290
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   291
    MouseEvent readMouseEvent(IntSupplier reader);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   292
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   293
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   294
     * Returns <code>true</code> if the terminal has support for focus tracking.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   295
     * @return whether focus tracking is supported by the terminal
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   296
     * @see #trackFocus(boolean)
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   297
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   298
    boolean hasFocusSupport();
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   299
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   300
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   301
     * Enable or disable focus tracking mode.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   302
     * When focus tracking has been activated, each time the terminal grabs the focus,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   303
     * the string "\33[I" will be sent to the input stream and each time the focus is lost,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   304
     * the string "\33[O" will be sent to the input stream.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   305
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   306
     * @param tracking whether the focus tracking mode should be enabled or not
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   307
     * @return <code>true</code> if focus tracking is supported
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   308
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   309
    boolean trackFocus(boolean tracking);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   310
}