Package jexer.teditor

Class Line


  • public class Line
    extends java.lang.Object
    A 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
      void addChar​(int ch)
      Insert a character at the cursor.
      void backspace​(int tabSize, boolean backspaceUnindents)
      Delete the character immediately preceeding the cursor.
      void backTab​(int tabSize)
      Handle the backtab (shift-tab) character.
      void del()
      Delete the character under the cursor.
      Line dup()
      Create a duplicate instance.
      boolean end()
      Go to the last column of this line.
      int getChar()
      Get the character at the current cursor position in the text.
      int getCursor()
      Get the current cursor position on screen.
      int getDisplayLength()
      Get the on-screen display length.
      int getRawCursor()
      Get the current cursor position in the text.
      java.lang.String getRawString()
      Get the raw string that matches this line.
      java.util.List<Word> getWords()
      Get a (shallow) copy of the words in this line.
      boolean home()
      Go to the first column of this line.
      boolean left()
      Decrement the cursor by one.
      int length()
      Get the raw length of this line.
      void replaceChar​(int ch)
      Replace a character at the cursor.
      boolean right()
      Increment the cursor by one.
      void setCursor​(int cursor)
      Set the current cursor position.
      void tab​(int tabSize)
      Handle the tab character.
      void trimRight()
      Trim trailing whitespace from line, repositioning cursor if needed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 string
        defaultColor - the color for unhighlighted text
        highlighter - 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 string
        defaultColor - 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 size
        backspaceUnindents - 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