Class ConsoleLoader

java.lang.Object
org.daiitech.naftah.utils.ConsoleLoader

public final class ConsoleLoader extends Object
Utility class for displaying a console-based loading spinner animation.

The spinner runs on a separate thread and can be started/stopped using static methods. It uses ANSI escape codes to clear the terminal screen for visual effect.

Example usage:


 ConsoleLoader.startLoader("Loading...");
 // do work
 ConsoleLoader.stopLoader();
 
Author:
Chakib Daii
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static Thread
    Background thread responsible for rendering the spinner animation.
    private static final char[]
    Characters used to animate the spinner.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Starts the loader spinner in a separate thread.
    static void
    Stops the loader spinner if running and clears the screen.

    Methods inherited from class java.lang.Object

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

    • SPINNER

      private static final char[] SPINNER
      Characters used to animate the spinner.
    • LOADER_THREAD

      private static Thread LOADER_THREAD
      Background thread responsible for rendering the spinner animation.
  • Constructor Details

    • ConsoleLoader

      private ConsoleLoader()
      Private constructor to prevent instantiation. Always throws a NaftahBugError when called.
  • Method Details

    • startLoader

      public static void startLoader(String text)
      Starts the loader spinner in a separate thread.
      Parameters:
      text - the message to display alongside the spinner
    • stopLoader

      public static void stopLoader()
      Stops the loader spinner if running and clears the screen.