Class DumbTerminal

java.lang.Object
org.jline.terminal.impl.AbstractTerminal
org.jline.terminal.impl.DumbTerminal
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, TerminalExt, Terminal

public class DumbTerminal extends AbstractTerminal
A minimal terminal implementation with limited capabilities.

The DumbTerminal class provides a basic terminal implementation that works in environments where a full-featured terminal is not available or not supported. It has minimal capabilities and does not support features like cursor movement, color output, or advanced input processing.

This terminal type is often used as a fallback when more capable terminal implementations cannot be created, such as in non-interactive environments, redirected I/O scenarios, or when running inside IDEs or other tools that don't provide full terminal emulation.

The DumbTerminal supports two variants:

While limited in capabilities, the DumbTerminal still provides the core terminal functionality such as reading input and writing output, making it suitable for basic console applications that don't require advanced terminal features.

See Also:
  • Constructor Details

  • Method Details

    • reader

      public NonBlockingReader reader()
      Description copied from interface: Terminal
      Retrieve the Reader for this terminal. This is the standard way to read input from this terminal. The reader is non blocking.
      Returns:
      The non blocking reader
    • writer

      public PrintWriter writer()
      Description copied from interface: Terminal
      Retrieve the Writer for this terminal. This is the standard way to write to this terminal.
      Returns:
      The writer
    • input

      public InputStream input()
      Description copied from interface: Terminal
      Retrieve the input stream for this terminal. In some rare cases, there may be a need to access the terminal input stream directly. In the usual cases, use the Terminal.reader() instead.
      Returns:
      The input stream
      See Also:
    • output

      public OutputStream output()
      Description copied from interface: Terminal
      Retrieve the output stream for this terminal. In some rare cases, there may be a need to access the terminal output stream directly. In the usual cases, use the Terminal.writer() instead.
      Returns:
      The output stream
      See Also:
    • getAttributes

      public Attributes getAttributes()
      Description copied from interface: Terminal
      Returns the current terminal attributes.

      Terminal attributes control various aspects of terminal behavior, including:

      • Input processing - How input characters are processed (e.g., character mapping, parity checking)
      • Output processing - How output characters are processed (e.g., newline translation)
      • Control settings - Hardware settings like baud rate and character size
      • Local settings - Terminal behavior settings like echo, canonical mode, and signal generation
      • Control characters - Special characters like EOF, interrupt, and erase

      The returned Attributes object is a copy of the terminal's current attributes and can be safely modified without affecting the terminal until it is applied using Terminal.setAttributes(Attributes). This allows for making multiple changes to the attributes before applying them all at once.

      Example usage:

       Terminal terminal = TerminalBuilder.terminal();
      
       // Get current attributes
       Attributes attrs = terminal.getAttributes();
      
       // Modify attributes
       attrs.setLocalFlag(LocalFlag.ECHO, false);      // Disable echo
       attrs.setInputFlag(InputFlag.ICRNL, false);     // Disable CR to NL mapping
       attrs.setControlChar(ControlChar.VMIN, 1);      // Set minimum input to 1 character
       attrs.setControlChar(ControlChar.VTIME, 0);     // Set timeout to 0 deciseconds
      
       // Apply modified attributes
       terminal.setAttributes(attrs);
       
      Returns:
      a copy of the terminal's current attributes
      See Also:
    • setAttributes

      public void setAttributes(Attributes attr)
      Description copied from interface: Terminal
      Sets the terminal attributes to the specified values.

      This method applies the specified attributes to the terminal, changing its behavior according to the settings in the Attributes object. The terminal makes a copy of the provided attributes, so further modifications to the attr object will not affect the terminal until this method is called again.

      Terminal attributes control various aspects of terminal behavior, including input and output processing, control settings, local settings, and special control characters. Changing these attributes allows for fine-grained control over how the terminal processes input and output.

      Common attribute modifications include:

      • Disabling echo for password input
      • Enabling/disabling canonical mode for line-by-line or character-by-character input
      • Disabling signal generation for custom handling of Ctrl+C and other control sequences
      • Changing control characters like the interrupt character or end-of-file character

      For convenience, the Terminal.enterRawMode() method provides a pre-configured set of attributes suitable for full-screen interactive applications.

      Example usage:

       Terminal terminal = TerminalBuilder.terminal();
      
       // Save original attributes for later restoration
       Attributes originalAttrs = terminal.getAttributes();
      
       try {
           // Create and configure new attributes
           Attributes attrs = new Attributes(originalAttrs);
           attrs.setLocalFlag(LocalFlag.ECHO, false);      // Disable echo for password input
           attrs.setLocalFlag(LocalFlag.ICANON, false);    // Disable canonical mode
      
           // Apply the new attributes
           terminal.setAttributes(attrs);
      
           // Use terminal with modified attributes...
       } finally {
           // Restore original attributes
           terminal.setAttributes(originalAttrs);
       }
       
      Parameters:
      attr - the attributes to apply to the terminal
      See Also:
    • getSize

      public Size getSize()
      Description copied from interface: Terminal
      Retrieve the size of the visible window
      Returns:
      the visible terminal size
      See Also:
    • setSize

      public void setSize(Size sz)
      Description copied from interface: Terminal
      Sets the size of the terminal.

      This method attempts to resize the terminal to the specified dimensions. Note that not all terminals support resizing, and the actual size after this operation may differ from the requested size depending on terminal capabilities and constraints.

      For virtual terminals or terminal emulators, this may update the internal size representation. For physical terminals, this may send appropriate escape sequences to adjust the viewable area.

      Parameters:
      sz - the new terminal size (columns and rows)
      See Also:
    • getProvider

      public TerminalProvider getProvider()
      Description copied from interface: TerminalExt
      Returns the terminal provider that created this terminal.

      The terminal provider is responsible for creating and managing terminal instances on a specific platform. This method allows access to the provider that created this terminal, which can be useful for accessing provider-specific functionality or for creating additional terminals with the same provider.

      Returns:
      the TerminalProvider that created this terminal, or null if the terminal was created with no provider
      See Also:
    • getSystemStream

      public SystemStream getSystemStream()
      Description copied from interface: TerminalExt
      Returns the system stream associated with this terminal, if any.

      This method indicates whether the terminal is bound to a standard system stream (standard input, standard output, or standard error). Terminals that are connected to system streams typically represent the actual terminal window or console that the application is running in.

      Returns:
      the underlying system stream, which may be SystemStream.Input, SystemStream.Output, SystemStream.Error, or null if this terminal is not bound to a system stream
      See Also: