kbd

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: MIT Imports: 3 Imported by: 0

README

Kbd

Render terminal-styled keycap glyphs for single keys, chords, and key sequences.

kbd preview

Install

glyph add kbd

This copies kbd.go (and its test file) into your repo at the path your glyph.json aliases declare. After install, the file is yours: edit it, refactor it, rename it. There is no kbd library to keep in sync.

Hello, world

package main

import (
	"fmt"

	"github.com/truffle-dev/glyph/components/kbd"
)

func main() {
	fmt.Println(kbd.Render("Ctrl"))
	fmt.Println(kbd.Chord("Ctrl", "K"))
	fmt.Println(kbd.Sequence(kbd.Chord("g"), kbd.Chord("g")))
}

API surface

Package: kbd

Types

  • Style

Constants

  • ChordSeparator
  • SequenceSeparator

Functions

  • Render
  • RenderStyled
  • Chord
  • Sequence

Dependencies

  • glyph component theme (installed automatically)
  • github.com/charmbracelet/bubbletea@v1.3.10
  • github.com/charmbracelet/lipgloss@v1.1.0

Notes

Stateless rendering primitive. Call kbd.Render("Ctrl") or kbd.Chord("Ctrl", "K") from inside your existing View() and place the result wherever a keycap belongs. The atom reads theme.Default automatically; pass a Style to RenderStyled when you need to override a single color. Compose into hint rows with kbd.Sequence(kbd.Chord("g"), kbd.Chord("g")) for keystroke series.

See also

License

MIT, same as the rest of glyph.

Documentation

Overview

Package kbd renders single keystrokes and chords as terminal-styled keycap glyphs. It is the atom that turns "ctrl+k" into a readable ⌃ K inside hint rows, command palettes, and modals.

The package is stateless: there is no Model, no Update, no message. Callers invoke Render, Chord, or Sequence from inside their own View and place the resulting string wherever a keycap belongs. Colors flow from the shared theme so the atom drops into any parent surface without coordination.

Index

Constants

View Source
const ChordSeparator = " + "

ChordSeparator is placed between caps inside a single chord.

View Source
const SequenceSeparator = " , "

SequenceSeparator is placed between chords in a keystroke series like "g g" or "Ctrl+K then P".

Variables

This section is empty.

Functions

func Chord

func Chord(keys ...string) string

Chord renders a sequence of keys joined with ChordSeparator. Empty keys are skipped. Returns "" when no usable keys are passed.

func Render

func Render(key string) string

Render formats a single key as a styled keycap using the default theme. Returns "" when key is empty.

func RenderStyled

func RenderStyled(key string, s Style) string

RenderStyled formats a single key with explicit style overrides. Any zero-value field in s falls back to the default theme palette.

func Sequence

func Sequence(chords ...string) string

Sequence joins already-rendered chord strings with SequenceSeparator. Empty entries are skipped so callers can pass conditional chords without filtering at the call site.

Types

type Style

type Style struct {
	Foreground lipgloss.Color
	Background lipgloss.Color
	Border     lipgloss.Color
}

Style overrides the per-cap colors. Zero values fall back to the theme palette: Foreground -> Text, Border -> Border. Background defaults to unset (transparent) so the cap composes onto any parent surface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL