Class Nano.Box

java.lang.Object
org.jline.builtins.Nano.Box
Enclosing class:
Nano

class Nano.Box extends Object
A class representing a box to be drawn on the screen.

The box is defined by its coordinates in the terminal:

 y axis (xi,yi)┌──────────────────────────────┐(xl,yi)
               │                              │
               │                              │
               │                              │
               │                              │
               │                              │
               │                              │
               │                              │
        (xi,yl)└──────────────────────────────┘(xl,yl)
                           x axis
 

The box can contain a list of lines to display, with support for scrolling if there are more lines than can fit in the box. It also supports highlighting a selected line with a different style.

  • Field Details

    • xi

      private final int xi
    • xl

      private final int xl
    • yi

      private final int yi
    • yl

      private final int yl
    • lines

      private List<AttributedString> lines
    • selected

      private int selected
    • selectedInView

      private int selectedInView
    • height

      private final int height
    • selectedStyle

      private AttributedStyle selectedStyle
    • visibleLines

      private List<AttributedString> visibleLines
  • Constructor Details

    • Box

      private Box(int xi, int yi, int xl, int yl)
      Creates a new box with the specified coordinates.
      Parameters:
      xi - the x-coordinate of the upper-left corner
      yi - the y-coordinate of the upper-left corner
      xl - the x-coordinate of the lower-right corner
      yl - the y-coordinate of the lower-right corner
  • Method Details

    • setLines

      private void setLines(List<AttributedString> lines)
      Sets the content lines to be displayed in the box.

      This method also initializes the visible lines based on the box height. If the number of lines exceeds the box height, only the first height lines will be visible initially.

      Parameters:
      lines - the lines to display in the box
    • getSelected

      public int getSelected()
      Gets the index of the currently selected line.
      Returns:
      the index of the selected line in the full list of lines
    • setSelectedStyle

      private void setSelectedStyle(AttributedStyle selectedStyle)
      Sets the style to use for the selected line.
      Parameters:
      selectedStyle - the style to apply to the selected line
    • getSelectedStyle

      private AttributedStyle getSelectedStyle()
    • down

      private void down()
    • up

      private void up()
    • scrollable

      private boolean scrollable()
    • getSelectedInView

      private int getSelectedInView()
    • draw

      public void draw(List<AttributedString> screenLines)
      Draws the box on the screen.

      This method draws the box borders and content on the provided screen lines. It modifies the screen lines in place to include the box.

      Parameters:
      screenLines - the screen lines to draw the box on
    • addBoxBorders

      protected void addBoxBorders(List<AttributedString> newLines)
    • setLineInBox

      protected void setLineInBox(List<AttributedString> newLines, int y, AttributedString line, boolean borders)
    • addBoxLines

      protected void addBoxLines(List<AttributedString> screenLines)