You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/progress.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -405,6 +405,35 @@ The default messages are `done`, `failed`, and `skipped`. `Done()` advances to t
405
405
-`Len() int`
406
406
-`VisibleLen() int`
407
407
408
+
### Runnable Demos
409
+
410
+
The `examples` directory contains runnable progress demos. They do not perform real network downloads; all work is simulated with in-memory data, timers, and goroutines.
411
+
412
+
Fixed worker slot and safe logging demo:
413
+
414
+
```bash
415
+
go run ./examples/progress-multi-demo
416
+
```
417
+
418
+
Render mode demo:
419
+
420
+
```bash
421
+
go run ./examples/progress-render-mode-demo auto
422
+
go run ./examples/progress-render-mode-demo dynamic
423
+
go run ./examples/progress-render-mode-demo plain
424
+
go run ./examples/progress-render-mode-demo disabled
425
+
```
426
+
427
+
`auto` selects `RenderDynamic` for interactive terminals and `RenderPlain` for non-interactive writers. `plain` is useful for CI logs and redirected output. `disabled` suppresses progress rendering while keeping log output.
428
+
429
+
Byte tracker and concurrent writer demo:
430
+
431
+
```bash
432
+
go run ./examples/progress-byte-tracker-demo
433
+
```
434
+
435
+
This demo shows both `ByteTracker.Add()` from simulated chunk workers and `NewConcurrentWriterWithInterval()` with `io.Copy()` over an in-memory reader.
For simple two-dimensional data, set headers first and pass a slice of rows:
203
+
204
+
```go
205
+
tb:= table.New("Jobs")
206
+
tb.SetHeads("Name", "Status", "Duration")
207
+
tb.SetRows([][]any{
208
+
{"build", "ok", "12s"},
209
+
{"test", "failed", "31s"},
210
+
})
211
+
tb.Println()
212
+
```
213
+
214
+
Table styles and borders are configurable:
215
+
216
+
```go
217
+
tb:= table.New("Release",
218
+
table.WithStyle(table.StyleRounded),
219
+
table.WithBorderFlags(table.BorderAll),
220
+
table.WithShowRowNumber(true),
221
+
)
222
+
tb.SetHeads("Package", "Status")
223
+
tb.AddRow("cliui", "ready")
224
+
tb.AddRow("docs", "updated")
225
+
tb.Println()
226
+
```
227
+
228
+
Built-in styles include `StyleSimple`, `StyleMySql`, `StyleMarkdown`, `StyleBold`, `StyleBoldBorder`, `StyleRounded`, `StyleDouble`, and `StyleMinimal`.
229
+
230
+
For long text, configure column width and overflow behavior:
231
+
232
+
```go
233
+
tb:= table.New("Tasks")
234
+
tb.SetHeads("Task", "Description")
235
+
tb.AddRow("download", "Fetch archive from mirror and verify checksum")
236
+
tb.AddRow("extract", "Unpack files into the selected destination")
237
+
tb.WithOptions(
238
+
table.WithColumnWidths(12, 32),
239
+
table.WithColMaxWidth(32),
240
+
table.WithOverflowFlag(table.OverflowWrap),
241
+
)
242
+
tb.Println()
243
+
```
244
+
245
+
Use `OverflowCut` to truncate long content, or `OverflowWrap` to wrap it across multiple display lines. Use `WithSortColumn(index, ascending)` to sort rows by a column:
246
+
247
+
```go
248
+
tb:= table.New("Results")
249
+
tb.SetHeads("Name", "Status")
250
+
tb.AddRow("test", "failed")
251
+
tb.AddRow("build", "ok")
252
+
tb.WithOptions(table.WithSortColumn(0, true))
253
+
tb.Println()
254
+
```
255
+
181
256
### JSON
182
257
183
258
`JSON` prints formatted structured objects. It is useful for debugging, showing API responses, or returning machine-readable output.
0 commit comments