Package jexer.teditor
Class Line
- java.lang.Object
-
- jexer.teditor.Line
-
public class Line extends java.lang.ObjectA Line represents a single line of text on the screen, as a collection of words.
-
-
Constructor Summary
Constructors Constructor Description Line(java.lang.String str, CellAttributes defaultColor)Construct a new Line from an existing text string.Line(java.lang.String str, CellAttributes defaultColor, Highlighter highlighter)Construct a new Line from an existing text string, and highlight certain strings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChar(int ch)Insert a character at the cursor.voidbackspace(int tabSize, boolean backspaceUnindents)Delete the character immediately preceeding the cursor.voidbackTab(int tabSize)Handle the backtab (shift-tab) character.voiddel()Delete the character under the cursor.Linedup()Create a duplicate instance.booleanend()Go to the last column of this line.intgetChar()Get the character at the current cursor position in the text.intgetCursor()Get the current cursor position on screen.intgetDisplayLength()Get the on-screen display length.intgetRawCursor()Get the current cursor position in the text.java.lang.StringgetRawString()Get the raw string that matches this line.java.util.List<Word>getWords()Get a (shallow) copy of the words in this line.booleanhome()Go to the first column of this line.booleanleft()Decrement the cursor by one.intlength()Get the raw length of this line.voidreplaceChar(int ch)Replace a character at the cursor.booleanright()Increment the cursor by one.voidsetCursor(int cursor)Set the current cursor position.voidtab(int tabSize)Handle the tab character.voidtrimRight()Trim trailing whitespace from line, repositioning cursor if needed.
-
-
-
Constructor Detail
-
Line
public Line(java.lang.String str, CellAttributes defaultColor, Highlighter highlighter)Construct a new Line from an existing text string, and highlight certain strings.- Parameters:
str- the text stringdefaultColor- the color for unhighlighted texthighlighter- the highlighter to use
-
Line
public Line(java.lang.String str, CellAttributes defaultColor)Construct a new Line from an existing text string.- Parameters:
str- the text stringdefaultColor- the color for unhighlighted text
-
-
Method Detail
-
dup
public Line dup()
Create a duplicate instance.- Returns:
- duplicate intance
-
getWords
public java.util.List<Word> getWords()
Get a (shallow) copy of the words in this line.- Returns:
- a copy of the word list
-
getRawCursor
public int getRawCursor()
Get the current cursor position in the text.- Returns:
- the cursor position
-
getCursor
public int getCursor()
Get the current cursor position on screen.- Returns:
- the cursor position
-
setCursor
public void setCursor(int cursor)
Set the current cursor position.- Parameters:
cursor- the new cursor position
-
getChar
public int getChar()
Get the character at the current cursor position in the text.- Returns:
- the character, or -1 if the cursor is at the end of the line
-
getDisplayLength
public int getDisplayLength()
Get the on-screen display length.- Returns:
- the number of cells needed to display this line
-
getRawString
public java.lang.String getRawString()
Get the raw string that matches this line.- Returns:
- the string
-
length
public int length()
Get the raw length of this line.- Returns:
- the length of this line in characters, which may be different from the number of cells needed to display it
-
left
public boolean left()
Decrement the cursor by one. If at the first column, do nothing.- Returns:
- true if the cursor position changed
-
right
public boolean right()
Increment the cursor by one. If at the last column, do nothing.- Returns:
- true if the cursor position changed
-
home
public boolean home()
Go to the first column of this line.- Returns:
- true if the cursor position changed
-
end
public boolean end()
Go to the last column of this line.- Returns:
- true if the cursor position changed
-
del
public void del()
Delete the character under the cursor.
-
backspace
public void backspace(int tabSize, boolean backspaceUnindents)Delete the character immediately preceeding the cursor.- Parameters:
tabSize- the tab stop sizebackspaceUnindents- If true, backspace at an indent level goes back a full indent level. If false, backspace always goes back one column.
-
addChar
public void addChar(int ch)
Insert a character at the cursor.- Parameters:
ch- the character to insert
-
replaceChar
public void replaceChar(int ch)
Replace a character at the cursor.- Parameters:
ch- the character to replace
-
trimRight
public void trimRight()
Trim trailing whitespace from line, repositioning cursor if needed.
-
tab
public void tab(int tabSize)
Handle the tab character.- Parameters:
tabSize- the tab stop size
-
backTab
public void backTab(int tabSize)
Handle the backtab (shift-tab) character.- Parameters:
tabSize- the tab stop size
-
-