chatthread

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 5 Imported by: 0

README

Chat Thread

Vertically scrolling conversation surface.

chat-thread preview

Install

glyph add chat-thread

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

Hello, world

package main

import (
	"fmt"

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

func main() {
	t := chatthread.New(theme.Default).WithSize(72, 12)
	t = t.Append(chatthread.Message{
		Role:  chatbubble.RoleAssistant,
		Label: "glyph",
		Text:  "Welcome.",
	})
	fmt.Println(t.View())
}

API surface

Package: chatthread

Types

  • Message
  • Thread

Functions and methods

  • New
  • WithSize
  • WithMessages
  • Append
  • Messages
  • ScrollUp
  • ScrollDown
  • ScrollToBottom
  • ScrollToTop
  • Init
  • Update
  • View

Dependencies

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

Notes

Pair with chat-input for a full chat surface. Drive Append() from your tea.Model when the input fires SubmitMsg.

See also

License

MIT, same as the rest of glyph.

Documentation

Overview

Package chatthread renders a vertically-stacked conversation of role-aware chat bubbles with viewport-style scrolling. It composes chat-bubble and expects the consumer to drive Append/Scroll via their own tea.Model.

Scroll is measured in lines from the bottom. offset == 0 means the latest message is visible at the bottom of the viewport. Increase offset to look back in history.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Role  chatbubble.Role
	Label string
	Text  string
}

Message is one row in the thread.

type Thread

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

Thread holds an ordered list of messages and a line-based scroll offset.

func New

func New(t theme.Theme) Thread

New constructs an empty thread.

func (Thread) Append

func (th Thread) Append(m Message) Thread

Append adds a message to the bottom of the thread. Snaps to the bottom unless the user has scrolled up — preserve their position in that case.

func (Thread) Init

func (th Thread) Init() tea.Cmd

Init implements tea.Model.

func (Thread) Messages

func (th Thread) Messages() []Message

Messages returns the current message list.

func (Thread) ScrollDown

func (th Thread) ScrollDown(n int) Thread

ScrollDown moves the viewport down by n lines.

func (Thread) ScrollToBottom

func (th Thread) ScrollToBottom() Thread

ScrollToBottom snaps to the latest line.

func (Thread) ScrollToTop

func (th Thread) ScrollToTop() Thread

ScrollToTop scrolls all the way up.

func (Thread) ScrollUp

func (th Thread) ScrollUp(n int) Thread

ScrollUp moves the viewport up by n lines.

func (Thread) Update

func (th Thread) Update(msg tea.Msg) (Thread, tea.Cmd)

Update handles arrow-key and page scrolling. Unknown messages are no-ops.

func (Thread) View

func (th Thread) View() string

View renders the thread to a fixed-size string.

func (Thread) WithMessages

func (th Thread) WithMessages(msgs []Message) Thread

WithMessages replaces the entire message list and snaps to the bottom.

func (Thread) WithSize

func (th Thread) WithSize(w, h int) Thread

WithSize sets the rendered width and height in cells.

Jump to

Keyboard shortcuts

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