Class Size

java.lang.Object
org.jline.terminal.Size

public class Size extends Object
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 and set the number of rows and columns. Terminal dimensions are used for various operations such as cursor positioning, screen clearing, and text layout calculations.

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(Size).

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 = new Size(80, 24);
 terminal.setSize(newSize);
 
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Size instance with default dimensions (0 rows and 0 columns).
    Size(int columns, int rows)
    Creates a new Size instance with the specified dimensions.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    copy(Size size)
    Copies the dimensions from another Size object to this one.
    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.
    void
    setColumns(int columns)
    Sets the number of columns (width) for this terminal size.
    void
    setRows(int rows)
    Sets the number of rows (height) for this terminal size.
    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

      public Size()
      Creates a new Size instance with default dimensions (0 rows and 0 columns).

      This constructor creates a Size object with zero dimensions. The dimensions can be set later using setRows(int) and setColumns(int).

    • Size

      public Size(int columns, int rows)
      Creates a new Size instance with the specified dimensions.

      This constructor creates a Size object with the specified number of columns and rows.

      Parameters:
      columns - the number of columns (width)
      rows - the number of rows (height)
  • Method Details

    • getColumns

      public int getColumns()
      Returns the number of columns (width) in this terminal size.

      The number of columns represents the width of the terminal in character cells.

      Returns:
      the number of columns
      See Also:
    • setColumns

      public void setColumns(int columns)
      Sets the number of columns (width) for this terminal size.

      The number of columns represents the width of the terminal in character cells.

      Parameters:
      columns - the number of columns to set
      See Also:
    • getRows

      public int getRows()
      Returns the number of rows (height) in this terminal size.

      The number of rows represents the height of the terminal in character cells.

      Returns:
      the number of rows
      See Also:
    • setRows

      public void setRows(int rows)
      Sets the number of rows (height) for this terminal size.

      The number of rows represents the height of the terminal in character cells.

      Parameters:
      rows - the number of rows to set
      See Also:
    • 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

      public void copy(Size size)
      Copies the dimensions from another Size object to this one.

      This method updates this Size object to have the same dimensions (rows and columns) as the specified Size object.

      Parameters:
      size - the Size 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.

      The hash code is computed based on the rows and columns values.

      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.

      The string representation includes the number of columns and rows.

      Overrides:
      toString in class Object
      Returns:
      a string representation of this object