Documentation
¶
Overview ¶
Package chatui contains the reusable terminal chat controls used by suga and other clients. It deliberately depends only on public packages so hosts do not need access to suga's internal application layers.
Index ¶
- Constants
- func ApprovalPrompt(tool, scopeDescription string, allowAlways bool) string
- func ApprovalPromptWithTranslator(t Translator, tool, scopeDescription string, allowAlways bool) string
- func PersistPrompt(action string) string
- func PersistPromptWithTranslator(t Translator, action string) string
- type ApprovalReply
- type CodeBlock
- type LiveText
- func (l *LiveText) Answer(text string)
- func (l *LiveText) CodeBlocks() []CodeBlock
- func (l *LiveText) Finish() bool
- func (l *LiveText) Handle(event StreamEvent) bool
- func (l *LiveText) SetCode(highlight bool, maxLines, width int)
- func (l *LiveText) SetMarkdown(color bool)
- func (l *LiveText) SetMarkdownTheme(theme string)
- func (l *LiveText) SetTranslator(tr Translator)
- func (l *LiveText) SetWholeLines(on bool)
- type MDTerm
- func (t *MDTerm) CodeBlocks() []CodeBlock
- func (t *MDTerm) Flush()
- func (t *MDTerm) Print(text string)
- func (t *MDTerm) SetCode(highlight bool, maxLines int)
- func (t *MDTerm) SetLinePrefix(prefix string)
- func (t *MDTerm) SetTheme(name string)
- func (t *MDTerm) SetTranslator(tr Translator)
- func (t *MDTerm) SetWidth(width int)
- func (t *MDTerm) Write(text string)
- type PersistReply
- type StreamEvent
- type Translator
Constants ¶
const ( StreamTextDelta = "text_delta" StreamMessageStop = "message_stop" StreamRetry = "retry" )
Variables ¶
This section is empty.
Functions ¶
func ApprovalPrompt ¶
ApprovalPrompt builds the compact answer line. allowAlways is false for an unsafe shell command: a deny scope is still useful, but an allow scope must never bypass the command safety matcher. Without a translator it falls back to the Chinese texts.
func ApprovalPromptWithTranslator ¶
func ApprovalPromptWithTranslator(t Translator, tool, scopeDescription string, allowAlways bool) string
ApprovalPromptWithTranslator builds the compact answer line with the injected host UI translator; the compatibility wrapper above keeps older callers in zh. It accepts the host's minimal translation contract (Translator).
func PersistPrompt ¶
PersistPrompt is explicit about the safe default: an empty answer keeps the rule in the current session, while only u/p request a file writeback.
func PersistPromptWithTranslator ¶
func PersistPromptWithTranslator(t Translator, action string) string
PersistPromptWithTranslator builds the rule writeback question using the injected translator while retaining the safe session-only default.
Types ¶
type ApprovalReply ¶
type ApprovalReply uint8
ApprovalReply is the decision made from the one-line answer to an approval question. The wiring layer turns the two persistent replies into session rules.
const ( ReplyDeny ApprovalReply = iota ReplyAllow ReplyAllowAlways ReplyDenyAlways )
func ParseApprovalReply ¶
func ParseApprovalReply(answer string) ApprovalReply
ParseApprovalReply accepts the stable answer aliases used by chat. Empty and unknown answers stay deny, preserving the old fail-closed behavior.
type CodeBlock ¶
CodeBlock is one fenced code block of a rendered message: the language of its fence, every line as the model wrote it and how many lines the fold limit hid (chat.code_max_lines). chat's :code command shows one of them again in full.
type LiveText ¶
type LiveText struct {
// contains filtered or unexported fields
}
LiveText owns one model message's streamed text, line buffering and optional markdown rendering. It has no dependency on suga's engine or application layers.
func NewLiveText ¶
func (*LiveText) CodeBlocks ¶
func (*LiveText) Handle ¶
func (l *LiveText) Handle(event StreamEvent) bool
Handle writes deltas and closes a model message. It returns true for stream events.
func (*LiveText) SetMarkdown ¶
func (*LiveText) SetMarkdownTheme ¶
func (*LiveText) SetTranslator ¶
func (l *LiveText) SetTranslator(tr Translator)
func (*LiveText) SetWholeLines ¶
type MDTerm ¶
type MDTerm struct {
// contains filtered or unexported fields
}
MDTerm renders markdown text line by line to a terminal writer. Zero value is not usable; call NewMDTerm.
func NewMDTerm ¶
NewMDTerm returns an MDTerm writing rendered lines to w; color styles them, with the dark theme's palette (SetTheme switches it).
func (*MDTerm) CodeBlocks ¶
CodeBlocks returns the code blocks of the most recent message that had one, in the order they appeared (:code).
func (*MDTerm) Flush ¶
func (t *MDTerm) Flush()
Flush renders the buffered, still incomplete line and ends the message: a code block left open does not carry into the next message.
func (*MDTerm) Print ¶
Print renders text that arrives as one piece (a final answer that was not streamed) and ends it on a line of its own. Empty text only ends the line its prefix was written on.
func (*MDTerm) SetCode ¶
SetCode configures fenced code blocks: highlight colors them by their language (chat.code_highlight; it needs color) and maxLines folds a block after that many lines (chat.code_max_lines, 0: no fold).
func (*MDTerm) SetLinePrefix ¶
SetLinePrefix sets the text printed at the start of every message's first line ("" removes it).
func (*MDTerm) SetTheme ¶
SetTheme switches the palette the elements are painted with (chat.theme, "dark" or "light"); an unknown name keeps the previous one.
func (*MDTerm) SetTranslator ¶
func (t *MDTerm) SetTranslator(tr Translator)
SetTranslator installs the host UI catalog of the lines the renderer writes itself (the folded-code notice); nil keeps the historical Chinese text.
type PersistReply ¶
type PersistReply uint8
PersistReply identifies the requested persistence destination. The wiring layer performs the writeback after the session rule has been installed in memory.
const ( PersistSession PersistReply = iota PersistUser PersistProject )
func ParsePersistReply ¶
func ParsePersistReply(answer string) PersistReply
ParsePersistReply keeps Enter as the safe default and recognizes only the explicit destinations shown in the follow-up question.
type StreamEvent ¶
StreamEvent is the smallest event contract needed by the streaming text area. Hosts adapt their engine-specific event type at the application boundary.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package lineedit is a copy of the VT100 line editor (Terminal) from golang.org/x/term v0.29.0 (terminal.go), made display-width aware.
|
Package lineedit is a copy of the VT100 line editor (Terminal) from golang.org/x/term v0.29.0 (terminal.go), made display-width aware. |
|
Package termtext removes terminal control sequences from text that came from a model, a tool or another external source before chat writes it to a terminal.
|
Package termtext removes terminal control sequences from text that came from a model, a tool or another external source before chat writes it to a terminal. |