Class LiveRegion

java.lang.Object
com.codename1.cli.LiveRegion
All Implemented Interfaces:
AutoCloseable

public final class LiveRegion extends Object implements AutoCloseable

The last few lines of the terminal, redrawn in place: what progress bars, spinners and prompts are drawn on.

update(String...) replaces the lines; println(String) prints a line above them, so log output and a live display can be mixed without tearing. Each frame goes out in one write. Lines are cut to the terminal's width, because a line that wrapped would throw off the count of lines to move back over.

When standard output is not a terminal nothing is redrawn: println(String) prints its line and close() prints the final lines once, so a log gets the outcome without a frame per update.

  • Constructor Summary

    Constructors
    Constructor
    Description
    A region on standard output, live when it is a terminal.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Erases the region from the screen, leaving the cursor where it began.
    void
    Leaves the last lines on screen, moves below them and shows the cursor.
    boolean
    Whether this region redraws in place.
    void
    Prints text above the region and redraws the region under it.
    void
    update(String... newLines)
    Replaces the lines and redraws them, with the cursor hidden.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LiveRegion

      public LiveRegion()
      A region on standard output, live when it is a terminal.
  • Method Details

    • isLive

      public boolean isLive()
      Whether this region redraws in place.
    • update

      public void update(String... newLines)
      Replaces the lines and redraws them, with the cursor hidden.
    • println

      public void println(String text)
      Prints text above the region and redraws the region under it.
    • clear

      public void clear()
      Erases the region from the screen, leaving the cursor where it began.
    • close

      public void close()
      Leaves the last lines on screen, moves below them and shows the cursor. Off a terminal, prints the last lines.
      Specified by:
      close in interface AutoCloseable