tui-spinner 0.2.3

Customizable animated spinner widgets for Ratatui — braille arcs, bouncing bars, rotating glyphs, and symbol styles
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# tui-spinner

[![Crates.io](https://img.shields.io/crates/v/tui-spinner.svg)](https://crates.io/crates/tui-spinner)
[![Docs.rs](https://docs.rs/tui-spinner/badge.svg)](https://docs.rs/tui-spinner)
[![Downloads](https://img.shields.io/crates/d/tui-spinner)](https://crates.io/crates/tui-spinner)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Customizable spinner widgets for [Ratatui](https://github.com/ratatui/ratatui) TUI applications.

---

## Widgets

| Widget | Shape | Motion | Key options |
|--------|-------|--------|-------------|
| [`LinearSpinner`]#linearspinner | Straight line | Scrolling window or bouncing dot | direction, flow, style |
| [`SquareSpinner`]#squarespinner | Square braille ring | Rotating arc | size, spin, centre |
| [`CircleSpinner`]#circlespinner | Circular braille ring | Rotating arc | radius, spin, arc_len |
| [`RectSpinner`]#rectspinner | Rectangle braille ring | Rotating arc | shape, spin, centre |
| [`BarSpinner`]#barspinner | Solid horizontal bar | Bouncing or continuous sweep | bar_style, motion, spin, track, fade_width |
| [`FluxSpinner`]#fluxspinner | Single-character glyph | Cycling frame sequence | frames, width, phase_step, spin |

---

## Previews

### All Widgets — Combined Overview

![Spinner Demo](examples/vhs/generated/spinner-demo.gif)

### SquareSpinner — Filled & Empty · CW ↻ and CCW ↺

![SquareSpinner Demo](examples/vhs/generated/square-spinner-demo.gif)

### CircleSpinner — Clockwise ↻ and Counter-Clockwise ↺

![CircleSpinner Demo](examples/vhs/generated/circle-spinner-demo.gif)

### LinearSpinner — Orientation & Direction

![LinearSpinner Demo](examples/vhs/generated/linear-spinner-demo.gif)

### BarSpinner — All symbol styles · Bounce & Loop

![BarSpinner Demo](examples/vhs/generated/bar-spinner-demo.gif)

### FluxSpinner — All frame presets

![FluxSpinner Demo](examples/vhs/generated/flux-spinner-demo.gif)

---

## Installation

```toml
[dependencies]
tui-spinner = "0.2"
```

---

## Quick Start

```rust
use ratatui::style::Color;
use tui_spinner::{
    BarMotion, BarSpinner, BarStyle, Centre, CircleSpinner, Direction, FluxFrames, FluxSpinner,
    Flow, LinearSpinner, LinearStyle, RectShape, RectSpinner, Spin, SquareSpinner,
};

// Vertical bouncing dot (Zed / Copilot style)
let v = LinearSpinner::new(tick)
    .direction(Direction::Vertical)
    .linear_style(LinearStyle::Braille)
    .active_color(Color::Cyan);

// Square arc, clockwise, filled centre
let sq = SquareSpinner::new(tick)
    .size(3)
    .spin(Spin::Clockwise)
    .centre(Centre::Filled)
    .arc_color(Color::Cyan);

// Circular arc, counter-clockwise
let circle = CircleSpinner::new(tick)
    .radius(5)
    .spin(Spin::CounterClockwise)
    .arc_color(Color::Magenta);

// Zed / Claude-style bouncing bar — fills available width automatically
let bar = BarSpinner::new(tick)
    .arc_color(Color::Cyan)
    .dim_color(Color::DarkGray);

// Continuous sweep (Loop motion) with a Star symbol style
let sweep = BarSpinner::new(tick)
    .bar_style(BarStyle::Star)
    .motion(BarMotion::Loop)
    .spin(Spin::Clockwise)
    .arc_color(Color::Yellow);

// Use preset constructors for common configurations
let preset = BarSpinner::claude(tick);   // 2-row orange bar

// Minimal 1×1 status-bar spinner
let flux = FluxSpinner::new(tick)
    .color(Color::Cyan);

// Wave of rotating glyphs
let wave = FluxSpinner::new(tick)
    .frames(FluxFrames::ORBIT)
    .width(8)
    .phase_step(1)
    .color(Color::LightBlue);
```

All widgets are **stateless** — just pass a monotonically-increasing `tick: u64` counter:

```rust
struct App { tick: u64 }

fn update(app: &mut App) {
    app.tick = app.tick.wrapping_add(1);
}
```

---

## Running the Examples

```sh
cargo run --example square_spinner   # SquareSpinner: Filled/Empty × CW/CCW
cargo run --example circle_spinner   # CircleSpinner: CW and CCW columns
cargo run --example linear_spinner   # LinearSpinner: all styles × orientation × direction
cargo run --example bar_spinner      # BarSpinner: Zed/Claude-style bouncing bar
cargo run --example flux_spinner     # FluxSpinner: all frame presets grid
cargo run --example spinner          # Combined overview of all widgets
```

---

## Widget Reference

### `LinearSpinner`

Horizontal scrolling window or vertical bouncing dot.

```text
Horizontal (Forwards):   ●●·  →  ·●●  →  ··●  →  ●··  → …
Horizontal (Backwards):  ··●  →  ·●●  →  ●●·  →  ●··  → …
Vertical:                ●       ·       ·
                         ·   →   ●   →   ·   → bounces back
                         ·       ·       ●
```

| Builder | Default | Description |
|---------|---------|-------------|
| `direction(Direction)` | `Horizontal` | Animation axis |
| `flow(Flow)` | `Forwards` | Animation direction |
| `linear_style(LinearStyle)` | `Classic` | Symbol set for active/inactive slots |
| `total_slots(n)` | `3` | Total number of slots |
| `lit_slots(n)` | `2` | Simultaneously lit slots (horizontal only) |
| `ticks_per_step(n)` | `3` | Ticks per step (higher = slower) |
| `active_color(c)` | `White` | Lit symbol colour |
| `inactive_color(c)` | `DarkGray` | Dim symbol colour |
| `block(b)` || Optional `Block` wrapper |
| `style(s)` || Base widget style |

#### `Direction`

| Variant | Description |
|---------|-------------|
| `Horizontal` | Scrolling window across a row (default) |
| `Vertical` | Single dot bouncing up and down a column |

#### `Flow`

| Variant | Description |
|---------|-------------|
| `Forwards` | Normal direction — left-to-right / upward-first (default) |
| `Backwards` | Reversed — right-to-left / downward-first |

#### `LinearStyle`

| Variant | Active | Inactive |
|---------|--------|----------|
| `Classic` | `` | `·` |
| `Square` | `` | `` |
| `Diamond` | `` | `` |
| `Bar` | `` | `` |
| `Braille` | `` | `` |
| `Arrow` | ``/`` | ``/`` |

---

### `SquareSpinner`

Braille-dot arc rotating around a square ring, with optional filled centre.

| Builder | Default | Description |
|---------|---------|-------------|
| `size(n)` | `2` | Arc thickness / square size (2–8) |
| `spin(Spin)` | `Clockwise` | Rotation direction |
| `centre(Centre)` | `Filled` | Interior fill mode |
| `arc_color(c)` | `White` | Rotating arc colour |
| `dim_color(c)` | `DarkGray` | Centre fill / dim ring colour |
| `ticks_per_step(n)` | `1` | Ticks per arc step |
| `alignment(a)` | `Left` | Horizontal alignment |
| `block(b)` || Optional `Block` wrapper |

> **Note:** `SquareSpinner` is a convenience wrapper around `RectSpinner`.
> For new code prefer `RectSpinner::new(tick).shape(RectShape::Square(n))`.

---

### `CircleSpinner`

Braille-dot arc rotating around a circular ring computed with the midpoint
circle algorithm.

| Builder | Default | Description |
|---------|---------|-------------|
| `radius(n)` | `4` | Circle radius in braille dots |
| `arc_len(n)` | `0` (auto ¼) | Bright arc length in perimeter dots |
| `spin(Spin)` | `Clockwise` | Rotation direction |
| `ticks_per_step(n)` | `1` | Ticks per arc step |
| `arc_color(c)` | `White` | Bright arc colour |
| `dim_color(c)` | `DarkGray` | Dim ring colour |
| `alignment(a)` | `Left` | Horizontal alignment |
| `block(b)` || Optional `Block` wrapper |

Use `.char_size()` → `(cols, rows)` to query the exact rendered size.

---

### `RectSpinner`

Braille-dot arc rotating around a configurable rectangle.

| Builder | Default | Description |
|---------|---------|-------------|
| `shape(RectShape)` | `Square(2)` | Shape and size |
| `spin(Spin)` | `Clockwise` | Rotation direction |
| `centre(Centre)` | `Filled` | Interior fill mode |
| `outer_color(c)` | `Cyan` | Rotating arc colour |
| `inner_color(c)` | `DarkGray` | Centre fill colour |
| `ticks_per_step(n)` | `1` | Ticks per arc step |
| `alignment(a)` | `Left` | Horizontal alignment |
| `block(b)` || Optional `Block` wrapper |

#### `RectShape`

| Variant | Description |
|---------|-------------|
| `Square(n)` | Square output; `n` = arc thickness / size (2–8) |

---

### `Spin` (shared)

| Variant | Description |
|---------|-------------|
| `Clockwise` | Arc travels clockwise (default) |
| `CounterClockwise` | Arc travels counter-clockwise |

### `Centre` (shared)

| Variant | Description |
|---------|-------------|
| `Filled` | Solid interior block (default) |
| `Empty` | No interior fill |

---

### `BarSpinner`

A solid braille or symbol bar with a glowing arc that **bounces** (ping-pong) or **sweeps continuously** (loop).  The arc edges taper through a density ramp for a soft comet-glow look.

Set `width(0)` (the default) to fill the available area automatically.

#### Preset constructors

```rust
BarSpinner::zed(tick)       // 1 row · cyan   · Rail track
BarSpinner::claude(tick)    // 2 rows · orange · Rail track
BarSpinner::minimal(tick)   // 1 row · white  · Empty track (arc floats)
BarSpinner::solid(tick)     // 1 row · cyan   · Full track · fade=0
```

#### Builder reference

| Builder | Default | Description |
|---------|---------|-------------|
| `width(n)` | `0` (auto-fill) | Fixed column count; `0` = fill area |
| `height(n)` | `1` | Bar height in rows |
| `arc_width(n)` | `0` (auto ⅓) | Bright arc width in character columns |
| `spin(Spin)` | `Clockwise` | Starting direction |
| `motion(BarMotion)` | `Bounce` | Edge behaviour: bounce or loop |
| `bar_style(BarStyle)` | `Braille` | Glyph set for arc and track |
| `track(BarTrack)` | `Rail` | Background track appearance |
| `fade_width(n)` | `3` | Gradient ramp width (0 = sharp cutoff) |
| `arc_char(byte)` | `0xFF` (``) | Braille byte for arc centre cells |
| `arc_color(c)` | `Cyan` | Bright arc colour |
| `dim_color(c)` | `DarkGray` | Background track colour |
| `with_colors(arc, dim)` || Set both colours in one call |
| `ticks_per_step(n)` | `1` | Ticks per step (higher = slower) |
| `alignment(a)` | `Left` | Horizontal alignment |
| `block(b)` || Optional `Block` wrapper |

#### `BarMotion`

| Variant | Description |
|---------|-------------|
| `Bounce` | Reverses at each edge — ping-pong (default) |
| `Loop` | Wraps around: exits one edge, re-enters from the other |

#### `BarStyle`

| Variant | Arc | Track |
|---------|-----|-------|
| `Braille` | `` | `` |
| `Block` | `` | `` |
| `Shade` | `` | `` |
| `Dot` | `` | `·` |
| `Diamond` | `` | `` |
| `Square` | `` | `` |
| `Star` | `` | `` |
| `Heart` | `` | `` |
| `Arrow` | `` | `` |
| `Circle` | `` | `` |
| `Spark` | `` | `` |
| `Cross` | `` | `` |
| `Progress` | `` | `` |
| `Thick` | `` | `` |
| `Wave` | `` | `˜` |
| `Pip` | `` | `·` |

#### `BarTrack`

| Variant | Byte | Glyph | Effect |
|---------|------|-------|--------|
| `Rail` | `0xC0` | `` | Bottom-two-dot baseline (default) |
| `Full` | `0xFF` | `` | Full-density track |
| `Empty` | `0x00` | `` | Invisible — arc floats |
| `Custom(u8)` | any || User-defined braille byte |

---

### `FluxSpinner`

A compact single-character spinner that cycles through a frame sequence.
At `1×1` it is a minimal status-bar indicator; scaled up with
[`width`](FluxSpinner::width) / [`height`](FluxSpinner::height) it
produces a travelling diagonal wave controlled by
[`phase_step`](FluxSpinner::phase_step).

| Builder | Default | Description |
|---------|---------|-------------|
| `frames(f)` | `FluxFrames::BRAILLE` | Frame sequence (any `&'static [char]`) |
| `width(n)` | `1` | Width in character columns |
| `height(n)` | `1` | Height in character rows |
| `spin(Spin)` | `Clockwise` | Frame sequence direction |
| `ticks_per_step(n)` | `1` | Ticks per frame (higher = slower) |
| `phase_step(n)` | `1` | Frame offset between adjacent cells |
| `color(c)` | `Cyan` | Glyph colour |
| `alignment(a)` | `Left` | Horizontal alignment |
| `block(b)` || Optional `Block` wrapper |

#### `FluxFrames` presets

| Preset | Glyphs | Frames | Description |
|--------|--------|--------|-------------|
| `BRAILLE` | `⣾ ⣷ ⣯ ⣟ ⡿ ⢿ ⣽ ⣻` | 8 | Full cell, one dot missing (default) |
| `ORBIT` | `⠁ ⠈ ⠐ ⠠ ⢀ ⡀ ⠄ ⠂` | 8 | Single dot orbiting |
| `CLASSIC` | `⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏` | 10 | Classic braille spinner |
| `LINE` | `│ ╱ ─ ╲` | 4 | Rotating line |
| `BLOCK` | `▖ ▘ ▝ ▗` | 4 | Quarter-block rotation |
| `ARC` | `◜ ◝ ◞ ◟` | 4 | Quarter-arc rotation |
| `CLOCK` | `◷ ◶ ◵ ◴` | 4 | Quarter-circle pie slice |
| `MOON` | `◓ ◑ ◒ ◐` | 4 | Half-circle moon phase |
| `TRIANGLES` | `▲ ▶ ▼ ◀` | 4 | Filled triangle rotation |
| `PULSE` | `⣀ ⣤ ⣶ ⣾ ⣿ ⣾ ⣶ ⣤` | 8 | Braille fill pulse |
| `BOUNCE` | `⠉ ⠒ ⣀ ⠒` | 4 | Braille dot bouncing |
| `HALF` | `▀ ▐ ▄ ▌` | 4 | Half-block rotation |
| `SQUARE` | `◰ ◳ ◲ ◱` | 4 | Filled square quadrant |
| `DICE` | `⚀ ⚁ ⚂ ⚃ ⚄ ⚅` | 6 | Dice faces |
| `BAR` | `▁ ▂ ▃ ▄ ▅ ▆ ▇ █` | 8 | Growing bar |
| `CORNERS` | `┌ ┐ ┘ └` | 4 | Box corners |
| `CIRCLE_FILL` | `○ ◔ ◑ ◕ ●` | 5 | Circle filling |
| `PISTON` | `▁ ▃ ▅ ▇ █ ▇ ▅ ▃` | 8 | Bouncing bar |
| `STAR` | `✶ ✷ ✸ ✹` | 4 | Star density ramp |
| `PAIR` | `⠉ ⠘ ⠰ ⢠ ⣀ ⡄ ⠆ ⠃` | 8 | Two dots rotating together |
| `DIAMOND` | `◇ ◈ ◆ ◈` | 4 | Diamond pulse |

Pass **any** `&'static [char]` for a fully custom animation:

```rust
let custom = FluxSpinner::new(tick)
    .frames(&['◐', '◓', '◑', '◒'])
    .color(Color::Cyan);
```

#### `phase_step` wave effect

```text
width = 6, phase_step = 1, Clockwise
⣾⣷⣯⣟⡿⢿   (tick 0)
⣷⣯⣟⡿⢿⣽   (tick 1)
⣯⣟⡿⢿⣽⣻   (tick 2)  …
```

With `Spin::CounterClockwise` the wave travels in the opposite direction.

---

## Generating Demo GIFs

```sh
# Requires VHS: https://github.com/charmbracelet/vhs
vhs examples/vhs/square-spinner-demo.tape
vhs examples/vhs/circle-spinner-demo.tape
vhs examples/vhs/linear-spinner-demo.tape
vhs examples/vhs/bar-spinner-demo.tape
vhs examples/vhs/flux-spinner-demo.tape
vhs examples/vhs/spinner-demo.tape

# Or via justfile:
just vhs-all
```

GIF files are tracked with **Git LFS** (see `.gitattributes`).

---

## License

MIT — see [LICENSE](LICENSE).