chatinput

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: 4 Imported by: 0

README

Chat Input

Single-line chat prompt with placeholder, cursor, focus state, and submit/cancel key bindings.

chat-input preview

Install

glyph add chat-input

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

Hello, world

package main

import (
	"fmt"

	chatinput "github.com/truffle-dev/glyph/components/chat-input"
	"github.com/truffle-dev/glyph/components/theme"
)

func main() {
	i := chatinput.New(theme.Default).
		WithPlaceholder("Type a message…").
		WithPrompt("you › ").
		WithWidth(72).
		Focus()
	fmt.Println(i.View())
}

API surface

Package: chatinput

Types

  • SubmitMsg
  • CancelMsg
  • Input

Functions and methods

  • New
  • WithPlaceholder
  • WithPrompt
  • WithWidth
  • WithValue
  • Focus
  • Blur
  • Focused
  • Value
  • Reset
  • Init
  • Update
  • View

Dependencies

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

Notes

Emits chatinput.SubmitMsg on Enter and chatinput.CancelMsg on Esc. Pair with chat-thread and chat-bubble for a full chat surface.

See also

License

MIT, same as the rest of glyph.

Documentation

Overview

Package chatinput renders a single-line chat prompt with a placeholder, cursor, and submit/escape key bindings. It's a thin Bubble Tea model — the consumer owns the code and is expected to extend it (history, multi-line, slash commands, completions) by editing the file directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelMsg

type CancelMsg struct{}

CancelMsg is emitted when the user presses Esc.

type Input

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

Input is a Bubble Tea model for a chat-style single-line text input.

func New

func New(t theme.Theme) Input

New constructs an Input using the given theme. Focused by default.

func (Input) Blur

func (i Input) Blur() Input

Blur disables key input.

func (Input) Focus

func (i Input) Focus() Input

Focus enables key input.

func (Input) Focused

func (i Input) Focused() bool

Focused reports whether the input is currently accepting keys.

func (Input) Init

func (i Input) Init() tea.Cmd

Init implements tea.Model.

func (Input) Reset

func (i Input) Reset() Input

Reset clears the value to "".

func (Input) Update

func (i Input) Update(msg tea.Msg) (Input, tea.Cmd)

Update implements tea.Model.

func (Input) Value

func (i Input) Value() string

Value returns the current text.

func (Input) View

func (i Input) View() string

View renders the input. Safe to call repeatedly.

func (Input) WithPlaceholder

func (i Input) WithPlaceholder(s string) Input

WithPlaceholder sets the placeholder shown when the value is empty.

func (Input) WithPrompt

func (i Input) WithPrompt(s string) Input

WithPrompt sets the prompt prefix (default "> "). Use "" for no prompt.

func (Input) WithValue

func (i Input) WithValue(s string) Input

WithValue presets the value. Useful for restored sessions.

func (Input) WithWidth

func (i Input) WithWidth(w int) Input

WithWidth sets the overall input width in cells. Clamped to >= 8.

type SubmitMsg

type SubmitMsg struct {
	Value string
}

SubmitMsg is emitted when the user presses Enter on a non-empty value.

Jump to

Keyboard shortcuts

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