Timeline
Key bindings
Section titled “Key bindings”| Key | Action |
|---|---|
↑ / k | Move selection up one lane |
↓ / j | Move selection down one lane |
← / h | Scroll timeline left |
→ / l | Scroll timeline right |
Home / g | Jump to first lane, scroll to start |
End / G | Jump to last lane |
Ctrl+D | Half-page down (lanes) |
Ctrl+U | Half-page up (lanes) |
+ / = | Zoom in (1.2×) |
- | Zoom out (0.8×) |
0 | Reset zoom and scroll to default |
Enter | Select lane (fires onSelect) |
Data model
Section titled “Data model”Each TimelineLane has a name and a list of TimelineItem entries with start/end times. The timeline renders all items for each lane in a single row:
tl := components.NewTimeline()tl.SetLanes([]components.TimelineLane{ { Name: "Build", Items: []components.TimelineItem{ {Label: "compile", Start: t0, End: t1}, {Label: "test", Start: t1, End: t2}, }, },})
Usage
start := time.Date(2026, 1, 1, 9, 0, 0, 0, time.UTC)mid := start.Add(2 * time.Hour)end := start.Add(4 * time.Hour)
tl := components.NewTimeline(). SetLanes([]components.TimelineLane{ {ID: "build", Name: "Build", StartTime: start, EndTime: &mid}, {ID: "test", Name: "Test", StartTime: mid, EndTime: &end}, }). SetLabelWidth(12). SetShowLegend(true)tl.SetTimeRange(start, end)
fmt.Println(tl != nil)Methods
| Method | Signature | Description |
|---|---|---|
AddLane | func (t *Timeline) AddLane(lane TimelineLane) *Timeline | AddLane adds a single lane to the timeline. |
ClearLanes | func (t *Timeline) ClearLanes() *Timeline | ClearLanes removes all lanes. |
GetLaneCount | func (t *Timeline) GetLaneCount() int | GetLaneCount returns the number of lanes. |
GetSelectedLane | func (t *Timeline) GetSelectedLane() *TimelineLane | GetSelectedLane returns the currently selected lane, or nil if none. |
SetBarStyleFn | func (t *Timeline) SetBarStyleFn(fn func(status *theme.Status) (rune, tcell.Color)) *Timeline | SetBarStyleFn sets a custom function for determining bar character and color. If not set, uses the Status.Color() for coloring. |
SetLabelWidth | func (t *Timeline) SetLabelWidth(width int) *Timeline | SetLabelWidth sets the width of the label column. |
SetLanes | func (t *Timeline) SetLanes(lanes []TimelineLane) *Timeline | SetLanes sets the timeline lanes. |
SetOnSelect | func (t *Timeline) SetOnSelect(fn func(lane *TimelineLane)) *Timeline | SetOnSelect sets the callback for lane selection. |
SetShowLegend | func (t *Timeline) SetShowLegend(show bool) *Timeline | SetShowLegend enables/disables the legend display. |
SetTimeRange | func (t *Timeline) SetTimeRange(start, end time.Time) *Timeline | SetTimeRange manually sets the time range for the timeline. If not called, the range is calculated from lane data. |
SetZoom | func (t *Timeline) SetZoom(level float64) *Timeline | SetZoom sets the zoom level. |
Zoom | func (t *Timeline) Zoom() float64 | Zoom returns the current zoom level. |
Types
type TimelineLane struct TimelineLane represents a horizontal lane in the timeline. | Field | Type | Description |
|---|---|---|
ID | string | Unique identifier |
Name | string | Display name |
Status | *theme.Status | Typed status for color/icon |
StartTime | time.Time | When the lane starts |
EndTime | *time.Time | When the lane ends (nil = ongoing) |
Data | any | Optional user data |