Tutorial: Task Manager
In this tutorial you will build a Task Manager terminal app from scratch. Each step adds one new capability on top of the previous code, with a live WebAssembly terminal preview right beside it.
- A declarative card layout with
SingleBorder()and Flexbox - Interactive task toggling and
All / Open / Donefilters - A validated “Add task” form using
kitex.Formandextras/form - Shared application state with
extras/kites - Async data loading and refresh with
extras/wind - List-to-detail navigation with
extras/flight - Headless component and screen tests with
kitextest
Step 1: Describe the UI
Section titled “Step 1: Describe the UI”Start by modeling a single Task with its ID, title, urgency, and completion state:
type Task struct { ID int Title string Urgent bool Done bool}Next, build TaskManager as a functional component (kitex.FC). It reads the starter tasks and renders a bordered card (kitex.Box), a header row (kitex.Span), and each task line with kitex.Map and a stable Key:
var TaskManager = kitex.FC("TaskManager", func(_ kitex.NoProps) kitex.Node { tasks := defaultTasks() open, done := tasks.Counts()
return kitex.Box.Style(cardStyle, kitex.Box.Style(headerStyle, kitex.Span.Style(accentStyle, kitex.Text("● TASK MANAGER")), kitex.Span.Style(mutedStyle, kitex.Textf("%d open · %d done", open, done)), ), kitex.Box.Style(listStyle, kitex.Map([]Task(tasks), func(item Task, _ int) kitex.Node { return kitex.Box(kitex.BoxProps{ Key: strconv.Itoa(item.ID), Style: rowStyle(item), }, kitex.Text(taskLabel(item))) }), ), )})Starter data & styles
type TaskBoard []Task
func defaultTasks() TaskBoard { return TaskBoard{ {ID: 1, Title: "Learn Kite"}, {ID: 2, Title: "Ship the guide", Urgent: true}, {ID: 3, Title: "Review notes", Done: true}, }}
func (b TaskBoard) Counts() (open, done int) { for _, item := range b { if item.Done { done++ } else { open++ } } return open, done}
func (b TaskBoard) ByID(id int) (Task, bool) { for _, item := range b { if item.ID == id { return item, true } } return Task{}, false}
func taskLabel(item Task) string { mark := "[ ]" if item.Done { mark = "[x]" } label := mark + " " + item.Title if item.Urgent { label += " ! Urgent" } return label}
var ( colorCanvas = style.Hex("#0b1120") colorCard = style.Hex("#111a2e") colorRow = style.Hex("#182235") colorBorder = style.Hex("#334866") colorText = style.Hex("#e2e8f0") colorMuted = style.Hex("#8ca0ba") colorAccent = style.Hex("#38bdf8") colorSoft = style.Hex("#163a59") colorGreen = style.Hex("#34d399") colorAmber = style.Hex("#fbbf24")
cardStyle = style.S().Width(style.Percent(100)).Border(style.SingleBorder().Color(colorBorder)). Background(colorCard).Padding(1, 2) headerStyle = style.S().Display(style.DisplayFlex).FlexDirection(style.FlexRow). JustifyContent(style.JustifyBetween).Margin(0, 0, 1, 0) listStyle = style.S().Display(style.DisplayFlex).FlexDirection(style.FlexColumn) rowGapStyle = style.S().Display(style.DisplayFlex).FlexDirection(style.FlexRow).Gap(0, 1).Margin(0, 0, 1, 0)
accentStyle = style.S().Foreground(colorAccent).Bold(true) mutedStyle = style.S().Foreground(colorMuted) successStyle = style.S().Foreground(colorGreen).Bold(true) warnStyle = style.S().Foreground(colorAmber).Bold(true) titleStyle = style.S().Foreground(style.Hex("#ffffff")).Bold(true)
btnStyle = style.S().Border(style.EmptyBorder()).Padding(0, 1). Background(colorRow).Foreground(colorText).Reverse(false). Hover(style.S().Background(style.Hex("#24324d")).Foreground(style.Hex("#f8fafc")).Bold(true).Reverse(false)). Focus(style.S().Background(style.Hex("#24324d")).Foreground(style.Hex("#f8fafc")).Bold(true).Reverse(false)) activeBtnStyle = btnStyle.Background(colorSoft).Foreground(colorAccent).Bold(true) primaryBtnStyle = btnStyle.Background(style.Hex("#133450")).Foreground(style.Hex("#f8fafc")).Bold(true)
inputStyle = style.S().Width(style.Cells(22)).Border(style.EmptyBorder()).Padding(0, 1). Background(style.Hex("#1e293b")).Foreground(colorText). Focus(style.S().Background(style.Hex("#25354f")).Foreground(style.Hex("#ffffff"))) formRowStyle = style.S().Display(style.DisplayFlex).FlexDirection(style.FlexRow). AlignItems(style.AlignCenter).Gap(0, 1).Margin(0, 0, 1, 0) checkboxRowStyle = style.S().Display(style.DisplayFlex).FlexDirection(style.FlexRow). AlignItems(style.AlignCenter).Gap(0, 1).Foreground(colorText))
func rowStyle(item Task) style.Style { s := style.S().Width(style.Percent(100)).Padding(0, 1).Background(colorRow).Foreground(colorText) if item.Done { return s.Foreground(colorGreen) } if item.Urgent { return s.Foreground(colorAmber) } return s}
func rowBtnStyle(item Task) style.Style { return rowStyle(item).Border(style.EmptyBorder()).Reverse(false).TextAlign(style.TextAlignLeft). Hover(style.S().Background(colorSoft).Foreground(style.Hex("#ffffff"))). Focus(style.S().Background(colorSoft).Foreground(style.Hex("#ffffff")))}Step 2: Add interactivity and filters
Section titled “Step 2: Add interactivity and filters”Extract each row into a TaskRow component that renders a kitex.Button instead of a static kitex.Box. Keeping a stable Key lets Kitex preserve focus on the active row when tasks are toggled or filtered:
type TaskRowProps struct { Key string Task Task OnPress func()}
var TaskRow = kitex.FC("TaskRow", func(p TaskRowProps) kitex.Node { return kitex.Button(kitex.ButtonProps{ Key: p.Key, Style: rowBtnStyle(p.Task), OnPress: p.OnPress, }, kitex.Text(taskLabel(p.Task)))})Next, add a 1-row FilterBar with borderless All, Open, and Done buttons, and hold tasks and filter in kitex.UseState. Using setTasks.Update with slices.Clone keeps every state update immutable so Kitex detects changes reliably:
type FilterBarProps struct { Active string OnSelect func(string)}
var FilterBar = kitex.FC("FilterBar", func(p FilterBarProps) kitex.Node { return kitex.Box.Style(rowGapStyle, kitex.Map([]string{"All", "Open", "Done"}, func(name string, _ int) kitex.Node { s := btnStyle if p.Active == name { s = activeBtnStyle } return kitex.Button(kitex.ButtonProps{ Key: name, Style: s, OnPress: func() { p.OnSelect(name) }, }, kitex.Text(name)) }), )})Wire FilterBar and TaskRow together inside TaskManager:
var TaskManager = kitex.FC("TaskManager", func(_ kitex.NoProps) kitex.Node { tasks, setTasks := kitex.UseState(defaultTasks()) filter, setFilter := kitex.UseState("All")
open, done := tasks().Counts() visible := filterTasks(tasks(), filter())
return kitex.Box.Style(cardStyle, kitex.Box.Style(headerStyle, kitex.Span.Style(accentStyle, kitex.Text("● TASK MANAGER")), kitex.Span.Style(mutedStyle, kitex.Textf("%d open · %d done", open, done)), ), FilterBar.Props(FilterBarProps{Active: filter(), OnSelect: setFilter}), kitex.Box.Style(listStyle, kitex.Map(visible, func(item Task, _ int) kitex.Node { return TaskRow.Props(TaskRowProps{ Key: strconv.Itoa(item.ID), Task: item, OnPress: func() { setTasks.Update(func(b TaskBoard) TaskBoard { return toggleTask(b, item.ID) }) }, }) }), ), )})Filter & toggle helpers
func toggleTask(b TaskBoard, id int) TaskBoard { next := slices.Clone(b) for i := range next { if next[i].ID == id { next[i].Done = !next[i].Done break } } return next}
func filterTasks(b TaskBoard, mode string) []Task { if mode == "All" || mode == "" { return b } var out []Task for _, item := range b { if (mode == "Open" && !item.Done) || (mode == "Done" && item.Done) { out = append(out, item) } } return out}Step 3: Add tasks with a validated form
Section titled “Step 3: Add tasks with a validated form”Add form struct tags to Task so extras/form can decode the input and checkbox directly into a Task value, plus a small validator:
type Task struct { ID int Title string `form:"title"` Urgent bool `form:"urgent"` Done bool}
func validateTask(v Task) map[string]string { if strings.TrimSpace(v.Title) == "" { return map[string]string{"title": "Enter a task title first."} } return nil}Now create AddTaskForm with form.Use, f.HandleSubmit(saveTask), and f.Reset(). Wrap the Checkbox in kitex.Label so clicking "Urgent" toggles it, and render s.Errors["title"] inline with kitex.If:
type AddTaskFormProps struct { OnAdd func(Task)}
var AddTaskForm = kitex.FC("AddTaskForm", func(p AddTaskFormProps) kitex.Node { f := form.Use(form.Options[Task]{Validate: validateTask}) s := f.State()
saveTask := func(v Task) error { v.Title = strings.TrimSpace(v.Title) p.OnAdd(v) f.Reset() return nil }
return kitex.Box.Style(listStyle, kitex.Form(kitex.FormProps{ Ref: f.Ref, OnSubmit: f.HandleSubmit(saveTask), Style: formRowStyle, }, kitex.Input(kitex.InputProps{ Name: "title", Placeholder: "New task title", Style: inputStyle, }), kitex.Label(kitex.LabelProps{Style: checkboxRowStyle}, kitex.Checkbox(kitex.CheckboxProps{Name: "urgent"}), kitex.Text("Urgent"), ), kitex.Button(kitex.ButtonProps{Style: primaryBtnStyle}, kitex.Text("Add")), ), kitex.If(s.Errors["title"] != "", func() kitex.Node { return kitex.Box.Style(warnStyle.Margin(0, 0, 1, 0), kitex.Text(s.Errors["title"])) }), )})Step 4: Share state with Kites
Section titled “Step 4: Share state with Kites”When sibling components need the same board state, lift TaskBoard into a kites context. Give TaskBoard a pointer-receiver Toggle method for kites.Action, and subscribe Header to just the formatted summary string via kites.UseContext:
func (b *TaskBoard) Toggle(id int) { *b = toggleTask(*b, id)}
var boardCtx = kites.NewContext(defaultTasks())
var Header = kitex.FC("Header", func(_ kitex.NoProps) kitex.Node { summary := kites.UseContext(boardCtx, func(b TaskBoard) string { open, done := b.Counts() return fmt.Sprintf("%d open · %d done", open, done) })
return kitex.Box.Style(headerStyle, kitex.Span.Style(accentStyle, kitex.Text("● TASK MANAGER")), kitex.Span.Style(successStyle, kitex.Text(summary)), )})TaskList reads the slice from boardCtx, dispatches (*TaskBoard).Toggle, and both components receive an isolated store from boardCtx.Provider:
var TaskList = kitex.FC("TaskList", func(_ kitex.NoProps) kitex.Node { tasks := kites.UseContext(boardCtx, func(b TaskBoard) TaskBoard { return b }) toggle := kites.Action(boardCtx.Store(), (*TaskBoard).Toggle)
return kitex.Box.Style(listStyle, kitex.Map([]Task(tasks), func(item Task, _ int) kitex.Node { return TaskRow.Props(TaskRowProps{ Key: strconv.Itoa(item.ID), Task: item, OnPress: func() { toggle(item.ID) }, }) }), )})
// Mount with an isolated store per session:// store := kites.Create(defaultTasks())// root.Render(boardCtx.Provider(store, kitex.Box.Style(cardStyle, Header(), TaskList())))Step 5: Load async data with Wind
Section titled “Step 5: Load async data with Wind”Write a plain context-aware fetcher fetchTasks instead of managing goroutines manually:
func fetchTasks(ctx context.Context, _ string) (TaskBoard, error) { timer := time.NewTimer(1000 * time.Millisecond) defer timer.Stop()
select { case <-timer.C: return defaultTasks(), nil case <-ctx.Done(): return nil, ctx.Err() }}Pass fetchTasks to wind.Use. Wind tracks IsLoading, IsFetching, and IsError, cancels in-flight fetches on unmount, and exposes query.Refetch for the Refresh button:
var AsyncBoard = kitex.FC("AsyncBoard", func(_ kitex.NoProps) kitex.Node { query := wind.Use("tasks", fetchTasks)
badge, badgeStyle := "Synced", successStyle if query.IsFetching || query.IsLoading { badge, badgeStyle = "Syncing...", warnStyle } else if query.IsError { badge, badgeStyle = "Sync failed", warnStyle }
var body kitex.Node switch { case query.IsLoading: body = kitex.Box.Style(mutedStyle, kitex.Text("Loading tasks...")) case query.IsError: body = kitex.Box.Style(warnStyle, kitex.Text(query.Error.Error())) default: body = kitex.Box.Style(listStyle, kitex.Map([]Task(query.Data), func(item Task, _ int) kitex.Node { return TaskRow.Props(TaskRowProps{ Key: strconv.Itoa(item.ID), Task: item, }) }), ) }
return kitex.Box.Style(cardStyle, kitex.Box.Style(headerStyle, kitex.Span.Style(accentStyle, kitex.Text("● TASK MANAGER")), kitex.Span.Style(badgeStyle, kitex.Text(badge)), ), kitex.Box.Style(rowGapStyle, kitex.Button(kitex.ButtonProps{ Style: primaryBtnStyle, OnPress: query.Refetch, }, kitex.Text("Refresh")), ), body, )})Wrap the root in wind.Provider so every descendant shares the query cache:
client := wind.NewClient()defer client.Close()root.Render(wind.Provider(wind.ProviderProps{Client: client}, AsyncBoard()))Step 6: Navigate between screens with Flight
Section titled “Step 6: Navigate between screens with Flight”Define typed route structs and render them inside flight.Stack. Flight automatically scopes focus to the top screen and restores the list when popping back:
type ( TaskListRoute struct{} TaskDetailRoute struct{ ID int })
var App = kitex.FC("App", func(_ kitex.NoProps) kitex.Node { return flight.Stack(flight.StackProps{ InitialRoute: TaskListRoute{}, RenderRoute: func(r flight.Route) kitex.Node { switch route := r.(type) { case TaskDetailRoute: return DetailScreen.Props(route) default: return ListScreen() } }, })})ListScreen pushes TaskDetailRoute{ID: item.ID} onto the navigation stack when you press any task:
var ListScreen = kitex.FC("ListScreen", func(_ kitex.NoProps) kitex.Node { nav := flight.UseNavigation() tasks := kites.UseContext(boardCtx, func(b TaskBoard) TaskBoard { return b }) open, done := tasks.Counts()
return kitex.Box.Style(cardStyle, kitex.Box.Style(headerStyle, kitex.Span.Style(accentStyle, kitex.Text("● TASK MANAGER")), kitex.Span.Style(mutedStyle, kitex.Textf("List · %d open", open)), ), kitex.Box.Style(mutedStyle.Margin(0, 0, 1, 0), kitex.Textf("Select a task to inspect (%d done):", done)), kitex.Box.Style(listStyle, kitex.Map([]Task(tasks), func(item Task, _ int) kitex.Node { return TaskRow.Props(TaskRowProps{ Key: strconv.Itoa(item.ID), Task: item, OnPress: func() { nav.Push(TaskDetailRoute{ID: item.ID}) }, }) }), ), )})DetailScreen looks up the task, toggles its status in boardCtx, and returns to the list with nav.Pop:
var DetailScreen = kitex.FC("DetailScreen", func(route TaskDetailRoute) kitex.Node { nav := flight.UseNavigation() tasks := kites.UseContext(boardCtx, func(b TaskBoard) TaskBoard { return b }) toggle := kites.Action(boardCtx.Store(), (*TaskBoard).Toggle)
item, ok := tasks.ByID(route.ID) if !ok { return kitex.Button(kitex.ButtonProps{ Style: btnStyle, OnPress: nav.Pop, }, kitex.Text("← Back")) }
status, statusStyle := "Open", accentStyle if item.Done { status, statusStyle = "Done", successStyle } priority := "Normal" if item.Urgent { priority = "Urgent" }
return kitex.Box.Style(cardStyle, kitex.Box.Style(headerStyle, kitex.Span.Style(accentStyle, kitex.Text("● TASK MANAGER")), kitex.Span.Style(accentStyle, kitex.Text("Detail Screen")), ), kitex.Box.Style(titleStyle, kitex.Text(item.Title)), kitex.Box.Style(statusStyle.Margin(0, 0, 1, 0), kitex.Text(priority+" · "+status)), kitex.Box.Style(rowGapStyle.Margin(0), kitex.Button(kitex.ButtonProps{ Style: primaryBtnStyle, OnPress: func() { toggle(route.ID) }, }, kitex.Text("Toggle status")), kitex.Button(kitex.ButtonProps{ Style: btnStyle, OnPress: nav.Pop, }, kitex.Text("← Back")), ), )})Step 7: Test headlessly without a terminal
Section titled “Step 7: Test headlessly without a terminal”Verify components, navigation, and rendered cells in go test with extras/kitex/kitextest and testenv—no real TTY required:
func TestTaskManagerNavigation(t *testing.T) { store := kites.Create(defaultTasks()) h := kitextest.Render(t, boardCtx.Provider(store, App()), kitextest.WithSize(52, 13))
h.ExpectScreen(). ToContainText("TASK MANAGER"). ToContainText("Learn Kite")
h.Play("<Enter>") h.ExpectScreen(). ToContainText("Detail Screen"). ToContainText("Toggle status")
h.Play("<Enter>") h.ExpectScreen().ToContainText("Normal · Done") h.Env.MatchGolden(t, "task-detail-done")}