java.lang.Object
org.strassburger.tui4j.formatting.layout.Spinner
All Implemented Interfaces:
Runnable, Renderable

public class Spinner extends Object implements Renderable, Runnable
A terminal spinner animation
  • Constructor Details

    • Spinner

      public Spinner()
      Create a new spinner with default settings

      Example usage:

       
       Spinner spinner = new Spinner()
               .setMessage(StyledText.text("Loading some stuff..."))
               .setSpinnerColor(AnsiColor.CYAN)
               .setSpeedMs(100)
               .setSpinnerFrames(SpinnerFrames.SYNTHWAVE);
       printer.print(spinner);
      
       for (int i = 0; i < 50; i++) {
           try {
               Thread.sleep(100);
               spinner.setMessage(StyledText.text("Loading some stuff... " + (i + 1) * 2 + "%") );
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }
       }
      
       spinner.stop(StyledText.text("✔ Loading complete!").fg(AnsiColor.GREEN).bold());
       
       
    • Spinner

      public Spinner(StyledText message)
      Create a spinner with a custom message

      Example usage:

       
       Spinner spinner = new Spinner()
               .setMessage(StyledText.text("Loading some stuff..."))
               .setSpinnerColor(AnsiColor.CYAN)
               .setSpeedMs(100)
               .setSpinnerFrames(SpinnerFrames.SYNTHWAVE);
       printer.print(spinner);
      
       for (int i = 0; i < 50; i++) {
           try {
               Thread.sleep(100);
               spinner.setMessage(StyledText.text("Loading some stuff... " + (i + 1) * 2 + "%") );
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }
       }
      
       spinner.stop(StyledText.text("✔ Loading complete!").fg(AnsiColor.GREEN).bold());
       
       
      Parameters:
      message - The message to display next to the spinner
  • Method Details

    • stop

      public void stop()
      Stop the spinner without printing a final message
    • stop

      public void stop(StyledText finalMessage)
      Stop the spinner and print a final message
    • setMessage

      public Spinner setMessage(StyledText message)
      Update the message displayed next to the spinner
    • getSpinnerFrames

      public List<StyledText> getSpinnerFrames()
    • setSpinnerFrames

      public Spinner setSpinnerFrames(List<StyledText> spinnerFrames)
      Set the frames used for the spinner animation. All frames must be non-empty and of equal length.
      You can find a collection of predefined spinner frames in the SpinnerFrames class.
      Throws:
      IllegalArgumentException - if the frames are invalid
    • getSpeedMs

      public int getSpeedMs()
    • setSpeedMs

      public Spinner setSpeedMs(int speedMs)
      Set the speed of the spinner animation in milliseconds
    • getSpinnerColor

      public Color getSpinnerColor()
    • setSpinnerColor

      public Spinner setSpinnerColor(Color spinnerColor)
      Set the color of the spinner
    • run

      public void run()
      The spinner animation loop
      Specified by:
      run in interface Runnable
    • render

      public void render(Printer printer, int width, int height)
      Render the spinner (starts the spinner)
      Specified by:
      render in interface Renderable
      Parameters:
      printer - the printer to use
      width - the available width
      height - the available height