Class PreserveStateAddon

java.lang.Object
com.flowingcode.vaadin.addons.xterm.PreserveStateAddon
All Implemented Interfaces:
ITerminal, ITerminalOptions, Serializable

public class PreserveStateAddon extends Object implements ITerminal, ITerminalOptions
Add-on which preserves the client-side state when the component is removed from the UI then reattached later on. The problem here is that when the XTerm server-side component is detached from the UI, the xterm.js client-side component is destroyed along with its state. When the XTerm component is later re-attached to the UI, a new unconfigured xterm.js is created on the client-side.

To use this addon, simply create the addon then make sure to call all ITerminal and ITerminalOptions methods via this addon:
 final XTerm xterm = new XTerm();
 final PreserveStateAddon addon = new PreserveStateAddon(xterm);
 addon.writeln("Hello!");
 addon.setPrompt("$ ");
 addon.writePrompt();
 
See Also:
  • Constructor Details

    • PreserveStateAddon

      public PreserveStateAddon(XTerm xterm)
  • Method Details

    • blur

      public void blur()
      Description copied from interface: ITerminal
      Unfocus the terminal.
      Specified by:
      blur in interface ITerminal
    • focus

      public void focus()
      Description copied from interface: ITerminal
      Focus the terminal.
      Specified by:
      focus in interface ITerminal
    • hasSelection

      public CompletableFuture<Boolean> hasSelection()
      Description copied from interface: ITerminal
      Gets whether the terminal has an active selection.
      Specified by:
      hasSelection in interface ITerminal
    • getSelection

      public CompletableFuture<String> getSelection()
      Description copied from interface: ITerminal
      Gets the terminal's current selection, this is useful for implementing copy behavior outside of xterm.js.
      Specified by:
      getSelection in interface ITerminal
    • clearSelection

      public void clearSelection()
      Description copied from interface: ITerminal
      Clears the current terminal selection.
      Specified by:
      clearSelection in interface ITerminal
    • select

      public void select(int column, int row, int length)
      Description copied from interface: ITerminal
      Selects text within the terminal.
      Specified by:
      select in interface ITerminal
      Parameters:
      column - The column the selection starts at.
      row - The row the selection starts at.
      length - The length of the selection.
    • selectAll

      public void selectAll()
      Description copied from interface: ITerminal
      Selects all text within the terminal.
      Specified by:
      selectAll in interface ITerminal
    • selectLines

      public void selectLines(int start, int end)
      Description copied from interface: ITerminal
      Selects text in the buffer between 2 lines.
      Specified by:
      selectLines in interface ITerminal
      Parameters:
      start - The 0-based line index to select from (inclusive).
      end - The 0-based line index to select to (inclusive).
    • scrollLines

      public void scrollLines(int amount)
      Description copied from interface: ITerminal
      Scroll the display of the terminal
      Specified by:
      scrollLines in interface ITerminal
      Parameters:
      amount - The number of lines to scroll down (negative scroll up).
    • scrollPages

      public void scrollPages(int pageCount)
      Description copied from interface: ITerminal
      Scroll the display of the terminal by a number of pages.
      Specified by:
      scrollPages in interface ITerminal
      Parameters:
      pageCount - The number of pages to scroll (negative scrolls up).
    • scrollToTop

      public void scrollToTop()
      Description copied from interface: ITerminal
      Scrolls the display of the terminal to the top.
      Specified by:
      scrollToTop in interface ITerminal
    • scrollToBottom

      public void scrollToBottom()
      Description copied from interface: ITerminal
      Scrolls the display of the terminal to the bottom.
      Specified by:
      scrollToBottom in interface ITerminal
    • scrollToLine

      public void scrollToLine(int line)
      Description copied from interface: ITerminal
      Scrolls to a line within the buffer.
      Specified by:
      scrollToLine in interface ITerminal
      Parameters:
      line - The 0-based line index to scroll to.
    • clear

      public void clear()
      Description copied from interface: ITerminal
      Clear the entire buffer, making the prompt line the new first line.
      Specified by:
      clear in interface ITerminal
    • write

      public void write(String data)
      Description copied from interface: ITerminal
      Write data to the terminal.
      Specified by:
      write in interface ITerminal
      Parameters:
      data - The data to write to the terminal.
    • writeln

      public void writeln(String data)
      Description copied from interface: ITerminal
      Writes data to the terminal, followed by a break line character (\n).
      Specified by:
      writeln in interface ITerminal
      Parameters:
      data - The data to write to the terminal. This can either be raw bytes given as Uint8Array from the pty or a string. Raw bytes will always be treated as UTF-8 encoded, string data as UTF-16.
    • paste

      public void paste(String data)
      Description copied from interface: ITerminal
      Writes text to the terminal, performing the necessary transformations for pasted text.
      Specified by:
      paste in interface ITerminal
      Parameters:
      data - The text to write to the terminal.
    • refresh

      public void refresh(int start, int end)
      Description copied from interface: ITerminal
      Tells the renderer to refresh terminal content between two rows (inclusive) at the next opportunity.
      Specified by:
      refresh in interface ITerminal
      Parameters:
      start - The row to start from (between 0 and this.rows - 1).
      end - The row to end at (between start and this.rows - 1).
    • reset

      public void reset()
      Description copied from interface: ITerminal
      Perform a full reset (RIS, aka '\x1bc').
      Specified by:
      reset in interface ITerminal
    • resize

      public void resize(int columns, int rows)
      Description copied from interface: ITerminal
      Resizes the terminal. Set the number of columns and rows in the terminal.
      Specified by:
      resize in interface ITerminal
    • setPrompt

      public void setPrompt(String prompt)
    • getPrompt

      public String getPrompt()
    • writePrompt

      public void writePrompt()
    • getScrollbackBuffer

      public String getScrollbackBuffer()
    • getXTerm

      public XTerm getXTerm()