Class Spinner
java.lang.Object
org.strassburger.tui4j.formatting.layout.Spinner
- All Implemented Interfaces:
Runnable,Renderable
A terminal spinner animation
-
Constructor Summary
ConstructorsConstructorDescriptionSpinner()Create a new spinner with default settingsSpinner(StyledText message) Create a spinner with a custom message -
Method Summary
Modifier and TypeMethodDescriptionintvoidRender the spinner (starts the spinner)voidrun()The spinner animation loopsetMessage(StyledText message) Update the message displayed next to the spinnersetSpeedMs(int speedMs) Set the speed of the spinner animation in millisecondssetSpinnerColor(Color spinnerColor) Set the color of the spinnersetSpinnerFrames(List<StyledText> spinnerFrames) Set the frames used for the spinner animation.voidstop()Stop the spinner without printing a final messagevoidstop(StyledText finalMessage) Stop the spinner and print a final message
-
Constructor Details
-
Spinner
public Spinner()Create a new spinner with default settingsExample 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
Create a spinner with a custom messageExample 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
Stop the spinner and print a final message -
setMessage
Update the message displayed next to the spinner -
getSpinnerFrames
-
setSpinnerFrames
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 theSpinnerFramesclass.- Throws:
IllegalArgumentException- if the frames are invalid
-
getSpeedMs
public int getSpeedMs() -
setSpeedMs
Set the speed of the spinner animation in milliseconds -
getSpinnerColor
-
setSpinnerColor
Set the color of the spinner -
run
public void run()The spinner animation loop -
render
Render the spinner (starts the spinner)- Specified by:
renderin interfaceRenderable- Parameters:
printer- the printer to usewidth- the available widthheight- the available height
-