Index of every page on this site: llms.txt
All skills
meza avatar

/charm-tui

@982e21e
by mezameza/skills2 stars
Run it yourself

Design, build, refactor, and review Go terminal interfaces using Bubble Tea, Bubbles, Lip Gloss, and Bubblebook. Use whenever work involves Charm TUI components, message routing, focus, terminal layout, styling, component stories, or UI tests. Teaches one native v2 architecture with a coordinating root, reusable components, and isolated Bubblebook stories. Does not cover unrelated Charm services or authorize a v1 migration.

Use this Skill: https://skilld.dev/gh/meza/skills/charm-tui

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesresults-example.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Results component example

Read component design for the ownership contract. For integration, read input routing; for asynchronous population, read effects and ordering. Follow all applicable routes in component design when building or reviewing a component.

Worked component: a bounded results selector

This complete component file illustrates a small selector, not a replacement for the filtering, pagination, help, and delegates already supplied by Bubbles list. Use Bubbles list when those features are required. This example's narrower contract needs only replacement, movement, selection, and bounded rendering.

The component copies the input slice. Item contains immutable string values, so a shallow slice copy is sufficient. If items later contain mutable maps or slices, define ownership or copy those fields too. Keep the component pointer owned by its parent rather than copying a live component between parents.

SetItems preserves the selected position and clamps it when the collection shrinks; it does not preserve identity across sorting. If the product needs that behavior, look up the old selected ID in the new collection inside SetItems. Empty selection is represented by Selected returning false.

The code requires a Go toolchain with slices.Clone, min, and max. Use the application's pinned v2 dependency versions. Labels are plain single-line text without terminal control sequences. These style roles carry color and emphasis only; a surrounding component owns borders and padding.

package results

import (
    "slices"
    "strings"

    "charm.land/lipgloss/v2"
    "github.com/charmbracelet/x/ansi"
)

type Item struct {
    ID    string
    Label string
}

type ResultsStyles struct {
    Normal   lipgloss.Style
    Selected lipgloss.Style
    Empty    lipgloss.Style
}

type Results struct {
    items    []Item
    selected int
    styles   ResultsStyles
}

func NewResults(items []Item, styles ResultsStyles) *Results {
    component := &Results{styles: styles}
    component.SetItems(items)
    return component
}

func (component *Results) SetItems(items []Item) {
    component.items = slices.Clone(items)
    component.selected = min(component.selected, max(0, len(items)-1))
}

func (component *Results) Move(delta int) {
    if len(component.items) == 0 {
        return
    }
    // Clamp the delta first, so even extreme caller values cannot overflow.
    movement := max(-component.selected,
        min(delta, len(component.items)-1-component.selected))
    component.selected += movement
}

func (component *Results) Selected() (Item, bool) {
    if len(component.items) == 0 {
        return Item{}, false
    }
    return component.items[component.selected], true
}

func (component *Results) Render(width, height int) string {
    if width <= 0 || height <= 0 {
        return ""
    }
    if len(component.items) == 0 {
        return ansi.Truncate(component.styles.Empty.Render("No results"), width, "…")
    }

    // Center the selection where possible, while keeping the last page full.
    start := max(0, component.selected-height/2)
    start = min(start, max(0, len(component.items)-height))
    count := min(height, len(component.items)-start)
    lines := make([]string, 0, count)
    for index := start; index < start+count; index++ {
        marker := "  "
        style := component.styles.Normal
        if index == component.selected {
            marker = "> "
            style = component.styles.Selected
        }
        line := style.Render(marker + component.items[index].Label)
        lines = append(lines, ansi.Truncate(line, width, "…"))
    }
    return strings.Join(lines, "\n")
}

For two items, Move(1) selects the second, Move(1) again stays there, and SetItems(nil) makes Selected() return false. At height one, rendering shows the selected row. At nonpositive width or height it returns an empty string and retains the selection for the next usable allocation. The marker makes selection understandable without relying on color.

The ANSI helper accounts for terminal cells and styling sequences; byte slicing does not. See ANSI truncation source and the companion layout reference for frames, cursor coordinates, and richer text boundaries.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The Charm TUI skill provides architectural guidance and practical examples for building terminal user interfaces in Go using the Bubble Tea ecosystem. It promotes best practices like component isolation, deterministic rendering, and comprehensive testing. No malicious code, data exfiltration, or obfuscation patterns were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 982e21e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 weeks ago.

Activeupdated 3 months ago

README badge

README badge for meza/skills/charm-tui