Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kei-k23/spinix
Spinix ๐ is a Go package that provides terminal-based highly customizable and performance loading animations, including spinners and progress bars.
https://github.com/kei-k23/spinix
cli go lib library progress-bar spinner terminal
Last synced: 19 days ago
JSON representation
Spinix ๐ is a Go package that provides terminal-based highly customizable and performance loading animations, including spinners and progress bars.
- Host: GitHub
- URL: https://github.com/kei-k23/spinix
- Owner: Kei-K23
- License: mit
- Created: 2024-10-26T15:16:51.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-25T05:13:54.000Z (about 1 month ago)
- Last Synced: 2024-12-17T00:13:45.523Z (19 days ago)
- Topics: cli, go, lib, library, progress-bar, spinner, terminal
- Language: Go
- Homepage:
- Size: 108 KB
- Stars: 18
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spinix
[![Go Test](https://github.com/Kei-K23/spinix/actions/workflows/test.yml/badge.svg)](https://github.com/Kei-K23/spinix/actions/workflows/test.yml)
**Spinix** ๐ is a **Go package** that provides terminal-based loading animations, including spinners and progress bars. It supports customizable themes, colors, and speeds, allowing developers to create visually appealing loading indicators that can fit various terminal environments and aesthetics.
## Features
- **Spinners**: Multiple spinner styles with customizable speed and colors.
- **Progress Bars**: A customizable progress bar with adjustable width, characters, and styles.
- **Thread Safety**: Safe to use in concurrent environments with mutexes.
- **Customizable Themes**: Use predefined themes or create your own custom spinner themes.## Installation
To install **Spinix**, use `go get`:
```bash
go get github.com/Kei-K23/spinix
```## Usage
### Spinners
Hereโs how to create and use a spinner:
```go
package mainimport (
"time"
"github.com/Kei-K23/spinix"
)func main() {
spinner := spinix.NewSpinner().
SetSpinnerColor("\033[34m").
SetMessage("Loading...").
SetMessageColor("\033[36m").
SetSpeed(100 * time.Millisecond) // Adjust speed if necessaryspinner.Start()
// Simulate some work
time.Sleep(5 * time.Second)spinner.Stop()
// spinix.NewSpinner() will also create spinner with default properties
// e.g
// spinner := spinix.NewSpinner()
// spinner.Start()
// time.Sleep(5 * time.Second)
// spinner.Stop()
}```
### Progress Bars
Creating and using a progress bar is just as straightforward:
```go
package mainimport (
"time"
"github.com/Kei-K23/spinix"
)func main() {
progressBar := spinix.NewProgressBar().
SetWidth(50).
SetColor("\033[32m").
SetLabel("Progress:")progressBar.Start()
for i := 0; i <= 100; i++ {
progressBar.Update(i)
time.Sleep(50 * time.Millisecond) // Simulate work
}progressBar.Stop()
// spinix.NewProgressBar() will also create progress bar with default properties.
// e.g
// progressBar := spinix.NewProgressBar()
// progressBar.Start()
// for i := 0; i <= 100; i++ {
// progressBar.Update(i)
// time.Sleep(50 * time.Millisecond) // Simulate work
// }
// progressBar.Stop()
}
```## Customization
### Spinners
You can customize the spinner's message, colors, speed, theme and define a custom callback function that will run once the and spinner is completed:
```go
func main() {
spinner := spinix.NewSpinner().
SetMessage("Processing...").
SetMessageColor("\033[33m").
SetCustomTheme([]string{"โ", "โ", "โ", "โ ", "โ", "โ", "โ", "โ", "โ", "โ ", "โ", "โ"}).
SetSpinnerColor("\033[31m"). // Red color (you can use every color you want with that format but spinner color will not work with emoji spinner)
SetSpeed(200 * time.Millisecond).
SetCallback(func() {
fmt.Println("The callback function has executed!")
})spinner.Start()
time.Sleep(2 * time.Second) // Simulate a task
spinner.Stop()
}
```### Progress Bars
You can customize the progress bar's message, width, color, appearance and define a custom callback function that will run once the and progress bar is completed:
```go
func main() {
progressBar := spinix.NewProgressBar().
SetWidth(60).
SetBarChar("โ").
SetEmptyChar("โ").
SetBorders("[", "]").
SetShowPercentage(true).
SetCallback(func() {
fmt.Println("The callback function has executed!")
})progressBar.Start()
for i := 0; i <= 100; i++ {
progressBar.Update(i)
time.Sleep(50 * time.Millisecond) // Simulate work
}progressBar.Stop()
}
```## Use Predefined Spinner and Progress bar
### Spinners
You can also use predefined spinner themes that provided by **spinix**:
See all available predefined spinner themes below```go
func main() {
spinner := spinix.NewSpinner().
SetMessage("Processing...").
SetMessageColor("\033[33m").
SetTheme(spinix.SpinnerRotatingArrow)spinner.Start()
// Simulate some work
time.Sleep(5 * time.Second)spinner.Stop()
}
```### Progress Bars
You can use predefined progress bar style that provided by **spinix**:
See all available predefined progress bar styles below```go
func main() {
progressBar := spinix.NewProgressBar().
SetStyle(spinix.PbStyleBasic).
SetShowPercentage(true)progressBar.Start()
for i := 0; i <= 100; i++ {
progressBar.Update(i)
time.Sleep(50 * time.Millisecond) // Simulate work
}progressBar.Stop()
}
```## Available Spinner Themes
The **Spinix** package comes with several predefined spinner themes. Hereโs a list of the available styles along with their visualizations:
| Spinner Theme | Visualization |
| ------------------------ | -------------------------------------------- |
| **SpinnerClassicDots** | โ โ โ น โ ธ โ ผ โ ด โ ฆ โ ง โ โ |
| **SpinnerLineTheme** | - \ |
| **SpinnerPulsatingDot** | โ โ โ โ |
| **SpinnerGrowingBlock** | โ โ โ โ โ โ โ โ โ โ โ โ |
| **SpinnerRotatingArrow** | โ โ โ โ โ โ โ โ |
| **SpinnerArcLoader** | โ โ โ โ โก โ |
| **SpinnerClock** | ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ |
| **SpinnerCircleDots** | โ โ โ โ |
| **SpinnerBouncingBall** | โ โ โ โ |
| **SpinnerFadingSquares** | โ โ โ โ |
| **SpinnerDotsFading** | โ โ โ โ โ โ โ โ |
| **SpinnerEarth** | ๐ ๐ ๐ |
| **SpinnerSnake** | โ โ โ โข โก โ โ โ |
| **SpinnerTriangle** | โข โฃ โค โฅ |
| **SpinnerSpiral** | โ โ โ โ โ โ โ โ |
| **SpinnerWave** | โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ |
| **SpinnerWeather** | ๐ค๏ธ โ ๐ฅ๏ธ โ๏ธ ๐ง๏ธ โ๏ธ ๐ฉ๏ธ ๐จ๏ธ |
| **SpinnerRunningPerson** | ๐๐จ ๐๐จ๐จ ๐๐จ๐จ๐จ ๐โโ๏ธ๐จ ๐โโ๏ธ๐จ๐จ ๐โโ๏ธ๐จ ๐โโ๏ธ๐จ๐จ |
| **SpinnerRunningCat** | ๐ฑ๐จ ๐๐จ ๐ฑ๐จ๐จ ๐๐จ๐จ |
| **SpinnerRunningDog** | ๐๐จ ๐ถ๐จ ๐โ๐ฆบ๐จ ๐๐จ๐จ |
| **SpinnerCycling** | ๐ด ๐ดโโ๏ธ ๐ดโโ๏ธ ๐ต ๐ตโโ๏ธ ๐ตโโ๏ธ |
| **SpinnerCarLoading** | ๐๐จ ๐๐จ ๐๐จ ๐๐จ ๐๐จ ๐๐จ |
| **SpinnerRocket** | ๐ ๐๐จ ๐๐จ๐จ ๐๐จ๐จ๐จ ๐๐ ๐๐ |
| **SpinnerOrbit** | ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ |
| **SpinnerTrain** | ๐ ๐ ๐ ๐ ๐ ๐ |
| **SpinnerAirplane** | โ๏ธ ๐ซ ๐ฌ โ๏ธ๐จ โ๏ธ๐จ๐จ |
| **SpinnerFireworks** | ๐ ๐ ๐๐ ๐๐ |
| **SpinnerPizzaDelivery** | ๐๐จ ๐๐จ ๐ญ๐จ ๐๐จ |
| **SpinnerHeartbeat** | ๐ ๐ ๐ ๐ ๐ ๐ ๐ |## Available Progress Bar Styles
The ProgressBar can be styled using various predefined styles. Hereโs a list of available styles:
| Progress Bar Style | Description |
| --------------------------- | ------------------------------------------------------------ |
| **PbStyleBasic** | ===========================------------- 69% |
| **PbStyleClassic** | [############################..] 95% |
| **PbStyleMinimal** | **\*\***\*\*\***\*\*** 79% |
| **PbStyleBold** | โฎโ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โฏ 93% |
| **PbStyleDashed** | [โฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฎโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏโฏ] 61% |
| **PbStyleElegant** | โฌโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฐโฑโฑโฑโฑโฑโฑโฑโฑโญ 79 |
| **PbStyleEmoji** | ๐ฉ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐โจโจโจโจโจโจโจโจ๐ฏ 71% |
| **PbStyleFuturistic** | โฆโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโง 59% |
| **PbStyleGreenDevelopment** | ๐ฑ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ๐ฟ\_\_\_\_๐ณ 91% |## Example
Hereโs a complete example that demonstrates both the spinner and the progress bar together:
```go
package mainimport (
"time"
"github.com/Kei-K23/spinix"
)func main() {
spinner := spinix.NewSpinner()
progressBar := spinix.NewProgressBar()spinner.SetMessage("Loading Data...")
spinner.Start()
progressBar.SetWidth(50)
progressBar.SetColor("\033[36m") // Cyan
progressBar.Start()for i := 0; i <= 100; i++ {
progressBar.Update(i)
time.Sleep(50 * time.Millisecond) // Simulate work
}progressBar.Stop()
spinner.Stop()
}
```## Demo
The demo run for the progress bar with style as `green`.
![green-progress-bar](./images/green.gif)
## Contributing
Contributions are welcome! Please feel free to open issues, submit pull requests, or provide feedback.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
## Contributors
Thanks to all the amazing contributors for making **spinix** better!