Class Display

java.lang.Object
org.jline.utils.Display
All Implemented Interfaces:
Sized

public class Display extends Object implements Sized
Manages terminal display and efficient screen updates with cursor positioning.

The Display class provides functionality for managing the display of content on the terminal screen. It handles the complexities of cursor positioning, line wrapping, and efficient screen updates to minimize the amount of data sent to the terminal.

This class supports two main modes of operation:

  • Full-screen mode - Takes over the entire terminal screen
  • Partial-screen mode - Updates only a portion of the screen, preserving content above

Key features include:

  • Efficient screen updates using cursor positioning
  • Support for multi-line content with proper wrapping
  • Handling of ANSI-styled text (colors, attributes)
  • Size-aware rendering that adapts to terminal dimensions
  • Cursor positioning relative to the display area

This class is used by various JLine components, such as LineReader, to provide efficient terminal display management for features like command-line editing, completion menus, and status messages.

Thread Safety

This class is NOT thread-safe and must be accessed from a single thread or with external synchronization. The Display class maintains mutable state including cursor position, screen content, and terminal dimensions that can be corrupted by concurrent access.

Components that use Display in multi-threaded environments (such as signal handlers for window resize events) must provide their own synchronization. For example, the LineReader uses a ReentrantLock to coordinate access between the main thread and signal handlers.

Warning: Concurrent access to Display methods may result in:

  • ConcurrentModificationException
  • Corrupted terminal output
  • Inconsistent cursor positioning
  • Race conditions in screen updates