newDashboardTab creates all Dashboard widgets and returns the tab.
(ctx context.Context, t terminalapi.Terminal)
| 254 | |
| 255 | // newDashboardTab creates all Dashboard widgets and returns the tab. |
| 256 | func newDashboardTab(ctx context.Context, t terminalapi.Terminal) (*dashWidgets, *tab.Tab, error) { |
| 257 | // ── Segment display ────────────────────────────────────────────────────── |
| 258 | sd, err := newSegmentDisplay(ctx, t) |
| 259 | if err != nil { |
| 260 | return nil, nil, err |
| 261 | } |
| 262 | |
| 263 | // ── Rolling text ───────────────────────────────────────────────────────── |
| 264 | rollT, err := text.New(text.RollContent()) |
| 265 | if err != nil { |
| 266 | return nil, nil, err |
| 267 | } |
| 268 | lineNum := 0 |
| 269 | go periodic(ctx, 1*time.Second, func() error { |
| 270 | err := rollT.Write(fmt.Sprintf("line %d\n", lineNum), text.WriteCellOpts(cell.FgColor(cell.ColorNumber(142)))) |
| 271 | lineNum++ |
| 272 | return err |
| 273 | }) |
| 274 | |
| 275 | // ── SparkLines ─────────────────────────────────────────────────────────── |
| 276 | spGreen, err := sparkline.New(sparkline.Color(cell.ColorGreen)) |
| 277 | if err != nil { |
| 278 | return nil, nil, err |
| 279 | } |
| 280 | go periodic(ctx, 250*time.Millisecond, func() error { |
| 281 | return spGreen.Add([]int{rand.Intn(101)}) |
| 282 | }) |
| 283 | |
| 284 | spRed, err := sparkline.New(sparkline.Color(cell.ColorRed)) |
| 285 | if err != nil { |
| 286 | return nil, nil, err |
| 287 | } |
| 288 | go periodic(ctx, 500*time.Millisecond, func() error { |
| 289 | return spRed.Add([]int{rand.Intn(101)}) |
| 290 | }) |
| 291 | |
| 292 | // ── Gauge ───────────────────────────────────────────────────────────────── |
| 293 | g, err := gauge.New(gauge.Color(cell.ColorNumber(75))) |
| 294 | if err != nil { |
| 295 | return nil, nil, err |
| 296 | } |
| 297 | progress := 35 |
| 298 | go periodic(ctx, 2*time.Second, func() error { |
| 299 | if err := g.Percent(progress, gauge.TextLabel(fmt.Sprintf("%d%%", progress))); err != nil { |
| 300 | return err |
| 301 | } |
| 302 | progress++ |
| 303 | if progress > 100 { |
| 304 | progress = 35 |
| 305 | } |
| 306 | return nil |
| 307 | }) |
| 308 | |
| 309 | // ── Heartbeat line chart ────────────────────────────────────────────────── |
| 310 | var hbInputs []float64 |
| 311 | for i := 0; i < 100; i++ { |
| 312 | v := math.Pow(math.Sin(float64(i)), 63) * math.Sin(float64(i)+1.5) * 8 |
| 313 | hbInputs = append(hbInputs, v) |
no test coverage detected