Package org.jline.builtins
Class Nano.Box
java.lang.Object
org.jline.builtins.Nano.Box
- Enclosing class:
Nano
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate List<AttributedString> private intprivate intprivate AttributedStyleprivate List<AttributedString> private final intprivate final intprivate final intprivate final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateBox(int xi, int yi, int xl, int yl) Creates a new box with the specified coordinates. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddBoxBorders(List<AttributedString> newLines) protected voidaddBoxLines(List<AttributedString> screenLines) private voiddown()voiddraw(List<AttributedString> screenLines) Draws the box on the screen.intGets the index of the currently selected line.private intprivate AttributedStyleprivate booleanprotected voidsetLineInBox(List<AttributedString> newLines, int y, AttributedString line, boolean borders) private voidsetLines(List<AttributedString> lines) Sets the content lines to be displayed in the box.private voidsetSelectedStyle(AttributedStyle selectedStyle) Sets the style to use for the selected line.private voidup()
-
Field Details
-
xi
private final int xi -
xl
private final int xl -
yi
private final int yi -
yl
private final int yl -
lines
-
selected
private int selected -
selectedInView
private int selectedInView -
height
private final int height -
selectedStyle
-
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 corneryi- the y-coordinate of the upper-left cornerxl- the x-coordinate of the lower-right corneryl- the y-coordinate of the lower-right corner
-
-
Method Details
-
setLines
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
heightlines 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
Sets the style to use for the selected line.- Parameters:
selectedStyle- the style to apply to the selected line
-
getSelectedStyle
-
down
private void down() -
up
private void up() -
scrollable
private boolean scrollable() -
getSelectedInView
private int getSelectedInView() -
draw
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
-
setLineInBox
protected void setLineInBox(List<AttributedString> newLines, int y, AttributedString line, boolean borders) -
addBoxLines
-