copyable

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package copyable finds the text a block's output offers to copy.

A program can offer text for the clipboard two ways. iTerm2's OSC 1337 CopyToClipboard and EndCopy bracket text it prints: what comes between them is shown as usual and is also the text to copy. OSC 52 carries the text in the sequence, base64 encoded, and nothing is shown. A terminal writes the clipboard on either. mdsh never writes the clipboard from output, which is saved in the file and run again by whoever opens it, so it offers each such text with a copy button, or a key in the TUI, instead.

Index

Constants

View Source
const MaxText = 1 << 20

MaxText caps the text one OSC 52 sequence can offer, as a guard against output made to be huge.

Variables

This section is empty.

Functions

func Has

func Has(s string) bool

Has reports whether s may offer copyable text, cheaply.

func Shown

func Shown(s string) string

Shown is s as a terminal shows it, near enough for copying: without escape sequences and control characters but newlines and tabs, and without a carriage return before a newline.

func Texts

func Texts(s string) []string

Texts is the copyable texts in s, in order: a region's text as shown, without its escape sequences and control characters, and each OSC 52 text.

Types

type Kind

type Kind int

Kind is what a Part is.

const (
	Plain  Kind = iota
	Open        // OSC 1337 CopyToClipboard: the shown text after it, to Close, is copyable
	Close       // OSC 1337 EndCopy, or the end of the output with a region open
	Hidden      // OSC 52: Text is offered but isn't shown
)

type Part

type Part struct {
	Kind Kind
	// Text is the output, for Plain, and the text offered, for Hidden.
	Text string
	// N numbers the copyable texts in the output from 1, for Open,
	// Close and Hidden.
	N int
}

A Part is a piece of output: text as it was printed, escapes and all, or a sequence that starts or ends a copyable region or offers text.

func Split

func Split(s string) []Part

Split cuts s, a block's output, into parts. Its other escape sequences stay in the Plain parts, for the caller to treat as it does any output. Output with no copyable text is one Plain part.

Jump to

Keyboard shortcuts

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