Class Size

java.lang.Object
org.jline.terminal.Size
All Implemented Interfaces:
Sized

public class Size extends Object implements Sized
Represents the dimensions of a terminal in terms of rows and columns.

The Size class encapsulates the dimensions of a terminal screen, providing methods to get the number of rows and columns. Terminal dimensions are used for various operations such as cursor positioning, screen clearing, and text layout calculations.

Prefer the of(int, int) or of(Sized) factory methods to create new instances. The mutating methods (setColumns(int), setRows(int), copy(org.jline.terminal.Size)) are deprecated and will be removed in a future major version.

Terminal dimensions are typically measured in character cells, where:

  • Columns - The number of character cells in each row (width)
  • Rows - The number of character cells in each column (height)

Size objects are typically obtained from a Terminal using Terminal.getSize(), and can be used to adjust display formatting or to set the terminal size using Terminal.setSize(Sized).

Example usage:

 Terminal terminal = TerminalBuilder.terminal();

 // Get current terminal size
 Size size = terminal.getSize();
 System.out.println("Terminal dimensions: " + size.getColumns() + "x" + size.getRows());

 // Create a new size and set it
 Size newSize = Size.of(80, 24);
 terminal.setSize(newSize);
 
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Use of(int, int) instead.
    Size(int columns, int rows)
    Deprecated.
    Use of(int, int) instead.
    Size(Sized sized)
    Deprecated.
    Use of(Sized) instead.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    copy(Size size)
    Deprecated.
    Use of(Sized) to create a new instance instead.
    void
    copy(Sized size)
    Deprecated.
    Use of(Sized) to create a new instance instead.
    int
    cursorPos(int row, int col)
    A cursor position combines a row number with a column position.
    boolean
    Compares this Size object with another object for equality.
    int
    Returns the number of columns (width) in this terminal size.
    int
    Returns the number of rows (height) in this terminal size.
    int
    Returns a hash code for this Size object.
    static Size
    of(int columns, int rows)
    Creates a new Size with the specified number of columns and rows.
    static Size
    of(Sized sized)
    Creates a new Size with the same columns and rows as the given source.
    void
    setColumns(int columns)
    Deprecated.
    Use of(int, int) to create a new instance instead.
    void
    setRows(int rows)
    Deprecated.
    Use of(int, int) to create a new instance instead.
    Returns a string representation of this Size object.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Size

      @Deprecated public Size()
      Deprecated.
      Use of(int, int) instead.
      Creates a new Size instance with default dimensions (0 rows and 0 columns).
    • Size

      @Deprecated public Size(int columns, int rows)
      Deprecated.
      Use of(int, int) instead.
      Constructs a Size with the specified number of columns and rows.
      Parameters:
      columns - the number of columns (width)
      rows - the number of rows (height)
    • Size

      @Deprecated public Size(Sized sized)
      Deprecated.
      Use of(Sized) instead.
      Constructs a new Size with the same columns and rows as the given size.
      Parameters:
      sized - the source Size from which to copy columns and rows
  • Method Details

    • of

      public static Size of(int columns, int rows)
      Creates a new Size with the specified number of columns and rows.
      Parameters:
      columns - the number of columns (width)
      rows - the number of rows (height)
      Returns:
      a new Size instance
    • of

      public static Size of(Sized sized)
      Creates a new Size with the same columns and rows as the given source.
      Parameters:
      sized - the source from which to copy columns and rows
      Returns:
      a new Size instance
    • getColumns

      public int getColumns()
      Returns the number of columns (width) in this terminal size.
      Specified by:
      getColumns in interface Sized
      Returns:
      the number of columns
    • setColumns

      @Deprecated public void setColumns(int columns)
      Deprecated.
      Use of(int, int) to create a new instance instead.
      Sets the number of columns (width) for this terminal size.
      Parameters:
      columns - the number of columns to set
    • getRows

      public int getRows()
      Returns the number of rows (height) in this terminal size.
      Specified by:
      getRows in interface Sized
      Returns:
      the number of rows
    • setRows

      @Deprecated public void setRows(int rows)
      Deprecated.
      Use of(int, int) to create a new instance instead.
      Sets the number of rows (height) for this terminal size.
      Parameters:
      rows - the number of rows to set
    • cursorPos

      public int cursorPos(int row, int col)
      A cursor position combines a row number with a column position.

      Note each row has col+1 different column positions, including the right margin.

      Parameters:
      row - the new row
      col - the new column
      Returns:
      the cursor position
    • copy

      @Deprecated public void copy(Size size)
      Deprecated.
      Use of(Sized) to create a new instance instead.
      Copies the dimensions from another Size object to this one.
      Parameters:
      size - the Size object to copy dimensions from
    • copy

      @Deprecated public void copy(Sized size)
      Deprecated.
      Use of(Sized) to create a new instance instead.
      Copies the dimensions from another Sized object to this one.
      Parameters:
      size - the Sized object to copy dimensions from
    • equals

      public boolean equals(Object o)
      Compares this Size object with another object for equality.

      Two Size objects are considered equal if they have the same number of rows and columns.

      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare with
      Returns:
      true if the objects are equal, false otherwise
    • hashCode

      public int hashCode()
      Returns a hash code for this Size object.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this Size object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object