Class Spinner

java.lang.Object
com.tnsai.utils.Spinner
All Implemented Interfaces:
AutoCloseable

public class Spinner extends Object implements AutoCloseable
Terminal spinner for showing loading state. Example:
 Spinner spinner = new Spinner("Thinking");
 spinner.start();
 // Do some work
 spinner.stop();
 
Or using try-with-resources:
 try (Spinner spinner = new Spinner("Processing")) {
     // Do some work
 }
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Spinner(String message)
    Creates a spinner with the given message.
    Spinner(String message, String[] bulletChars, boolean showInterruptHint)
    Creates a spinner with custom configuration.
    Spinner(String message, String[] bulletChars, boolean showInterruptHint, PrintStream output)
    Creates a spinner with custom output stream.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    AutoCloseable implementation for try-with-resources.
    static void
    main(String[] args)
    Example usage.
    void
    Starts the spinner animation.
    void
    Stops the spinner animation.
    void
    updateMessage(String newMessage)
    Updates the spinner message while it's running.

    Methods inherited from class java.lang.Object

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

    • Spinner

      public Spinner(String message)
      Creates a spinner with the given message.
    • Spinner

      public Spinner(String message, String[] bulletChars, boolean showInterruptHint)
      Creates a spinner with custom configuration.
      Parameters:
      message - Message to display next to spinner
      bulletChars - Custom bullet animation characters (null for default)
      showInterruptHint - Show "(esc to interrupt)" hint
    • Spinner

      public Spinner(String message, String[] bulletChars, boolean showInterruptHint, PrintStream output)
      Creates a spinner with custom output stream.
  • Method Details

    • start

      public void start()
      Starts the spinner animation.
    • stop

      public void stop()
      Stops the spinner animation.
    • updateMessage

      public void updateMessage(String newMessage)
      Updates the spinner message while it's running.
    • close

      public void close()
      AutoCloseable implementation for try-with-resources.
      Specified by:
      close in interface AutoCloseable
    • main

      public static void main(String[] args)
      Example usage.