chatbubble

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 4 Imported by: 0

README

Chat Bubble

Role-aware speech bubble with width-aware wrapping.

chat-bubble preview

Install

glyph add chat-bubble

This copies chat-bubble.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 chat-bubble library to keep in sync.

Hello, world

package main

import (
	"fmt"

	chatbubble "github.com/truffle-dev/glyph/components/chat-bubble"
	"github.com/truffle-dev/glyph/components/theme"
)

func main() {
	b := chatbubble.New(theme.Default).
		WithRole(chatbubble.RoleAssistant).
		WithLabel("glyph").
		WithText("Welcome.").
		WithWidth(72)
	fmt.Println(b.View())
}

API surface

Package: chatbubble

Types

  • Role
  • Bubble

Functions and methods

  • New
  • WithRole
  • WithText
  • WithWidth
  • WithLabel
  • View

Dependencies

  • glyph component theme (installed automatically)
  • github.com/charmbracelet/lipgloss@v1.1.0
  • github.com/muesli/reflow@v0.3.0

Notes

Pair with chat-input and chat-thread for a full chat surface. Roles: user, assistant, system, tool.

See also

License

MIT, same as the rest of glyph.

Documentation

Overview

Package chatbubble renders a role-aware speech bubble with width-aware wrap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bubble

type Bubble struct {
	// contains filtered or unexported fields
}

Bubble renders one chat message.

func New

func New(t theme.Theme) Bubble

New constructs a bubble using the given theme.

func (Bubble) View

func (b Bubble) View() string

View renders the bubble to a string. Safe to call repeatedly.

func (Bubble) WithLabel

func (b Bubble) WithLabel(s string) Bubble

WithLabel sets the role label printed above the bubble. If empty, no label is rendered.

func (Bubble) WithRole

func (b Bubble) WithRole(r Role) Bubble

WithRole sets the role used for styling.

func (Bubble) WithText

func (b Bubble) WithText(s string) Bubble

WithText sets the body text.

func (Bubble) WithWidth

func (b Bubble) WithWidth(w int) Bubble

WithWidth caps the bubble's content width in cells.

type Role

type Role string

Role drives the bubble's color and alignment.

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleSystem    Role = "system"
	RoleTool      Role = "tool"
)

Jump to

Keyboard shortcuts

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