paste

package
v1.65.6 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

* ChatCLI - Paste Detection * cli/paste/detector.go * Copyright (c) 2024 Edilson Freitas * License: MIT

Index

Constants

View Source
const PasteDisplayThreshold = 150

PasteDisplayThreshold is the maximum number of characters that will be rendered directly in the go-prompt input line. Pastes larger than this are replaced by a compact placeholder to avoid terminal corruption.

View Source
const PlaceholderPrefix = "\u00ab" // «

PlaceholderPrefix is the sentinel used to identify paste placeholders in the go-prompt buffer so the executor can swap them for real content.

View Source
const PlaceholderSuffix = "\u00bb" // »

Variables

This section is empty.

Functions

func IsPlaceholder added in v1.64.0

func IsPlaceholder(s string) bool

IsPlaceholder checks if a string contains a paste placeholder.

func MakePlaceholder added in v1.64.0

func MakePlaceholder(charCount, lineCount int) string

MakePlaceholder builds the placeholder string shown in the prompt input line for large pastes (e.g., «1234 chars | 5 lines»).

Types

type BracketedPasteParser

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

BracketedPasteParser wraps a ConsoleParser to detect bracketed paste sequences. It implements go-prompt's ConsoleParser interface.

func NewBracketedPasteParser

func NewBracketedPasteParser(inner prompt.ConsoleParser, onPaste func(Info)) *BracketedPasteParser

NewBracketedPasteParser creates a new parser that wraps an existing ConsoleParser. The onPaste callback is invoked when a paste operation is detected.

func (*BracketedPasteParser) GetWinSize

func (p *BracketedPasteParser) GetWinSize() *prompt.WinSize

GetWinSize returns the terminal window size.

func (*BracketedPasteParser) Read

func (p *BracketedPasteParser) Read() ([]byte, error)

Read reads bytes from the inner parser and processes bracketed paste sequences.

func (*BracketedPasteParser) Setup

func (p *BracketedPasteParser) Setup() error

Setup initializes the parser and enables bracketed paste mode.

func (*BracketedPasteParser) TearDown

func (p *BracketedPasteParser) TearDown() error

TearDown disables bracketed paste mode and cleans up.

type Info

type Info struct {
	Content     string
	CharCount   int
	LineCount   int
	Placeholder string // non-empty when a placeholder was injected into go-prompt
}

Info holds metadata about a detected paste operation.

func DetectInLine

func DetectInLine(line string) (string, *Info)

DetectInLine strips bracketed paste markers from a line read via bufio and returns paste info if markers were found. This is used for agent mode where we read directly from stdin instead of go-prompt.

Jump to

Keyboard shortcuts

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