Class App


  • public final class App
    extends java.lang.Object
    The application engine: owns the terminal, the single UI thread and event loop, layout, repaint, focus, and resize. Background threads interact with the UI only through post(Runnable).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  App.Builder
      Fluent builder for an App.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static App.Builder builder()  
      static App current()  
      OverlayHandle openOverlay​(Section content, Placement placement, Section... focusTargets)
      Opens a modal overlay rendered on top of the UI and routes keys to it.
      void post​(java.lang.Runnable task)
      Marshals a runnable onto the UI thread.
      void quit()
      Stops the event loop; run() then restores the terminal.
      void run()
      Installs the terminal, runs the event loop until quit, and restores the terminal on exit, even if an exception propagates.
      Cancellable schedule​(java.time.Duration delay, java.lang.Runnable task)
      Schedules a one-shot task on the UI thread.
      Cancellable scheduleAtFixedRate​(java.time.Duration initialDelay, java.time.Duration period, java.lang.Runnable task)
      Schedules a repeating task on the UI thread.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • builder

        public static App.Builder builder()
        Returns:
        a new app builder
      • current

        public static App current()
        Returns:
        the running app, or null when no app is running
      • run

        public void run()
        Installs the terminal, runs the event loop until quit, and restores the terminal on exit, even if an exception propagates.
      • quit

        public void quit()
        Stops the event loop; run() then restores the terminal.
      • post

        public void post​(java.lang.Runnable task)
        Marshals a runnable onto the UI thread. Safe to call from any thread.
        Parameters:
        task - the runnable to run on the UI thread
      • openOverlay

        public OverlayHandle openOverlay​(Section content,
                                         Placement placement,
                                         Section... focusTargets)
        Opens a modal overlay rendered on top of the UI and routes keys to it. UI-thread-only. Close overlays in reverse order of opening.
        Parameters:
        content - the overlay content section
        placement - resolves the overlay's bounds against the screen
        focusTargets - the sections Tab cycles between, or none to focus the content itself
        Returns:
        a handle that closes the overlay
      • schedule

        public Cancellable schedule​(java.time.Duration delay,
                                    java.lang.Runnable task)
        Schedules a one-shot task on the UI thread.
        Parameters:
        delay - the delay before the task runs
        task - the task to run on the UI thread
        Returns:
        a handle to cancel the scheduled task
      • scheduleAtFixedRate

        public Cancellable scheduleAtFixedRate​(java.time.Duration initialDelay,
                                               java.time.Duration period,
                                               java.lang.Runnable task)
        Schedules a repeating task on the UI thread.
        Parameters:
        initialDelay - the delay before the first run
        period - the period between successive runs
        task - the task to run on the UI thread
        Returns:
        a handle to cancel the scheduled task