feat: clipboard without OSC52
Signed-off-by: drew <me@andrinoff.com>
This commit is contained in:
parent
657aaae216
commit
5187ca8e8b
23 changed files with 1653 additions and 49 deletions
25
README.md
25
README.md
|
|
@ -312,6 +312,31 @@ if len(os.Getenv("DEBUG")) > 0 {
|
|||
To see what’s being logged in real time, run `tail -f debug.log` while you run
|
||||
your program in another window.
|
||||
|
||||
## Clipboard
|
||||
|
||||
Bubble Tea copies to and pastes from the system clipboard with
|
||||
`tea.SetClipboard`, `tea.SetPrimaryClipboard`, and `tea.ReadClipboard`. Copy
|
||||
results arrive as a `tea.ClipboardMsg`.
|
||||
|
||||
By default this uses OSC52, which requires terminal support. On terminals
|
||||
without it, such as Apple’s Terminal.app, Bubble Tea falls back to the
|
||||
operating system’s clipboard tools: `pbcopy` and `pbpaste` on macOS, and
|
||||
`wl-clipboard`, `xclip`, or `xsel` on Linux. Commands started with `tea.Exec`
|
||||
and `tea.ExecProcess` get the same treatment: when the terminal can’t handle
|
||||
OSC52, they run on a pseudo-terminal whose clipboard traffic is bridged for
|
||||
them.
|
||||
|
||||
A custom backend can be supplied with `tea.WithClipboardBackend`, and the
|
||||
fallback can be turned off entirely with `tea.WithoutClipboardFallback`. See
|
||||
the [clipboard example][clipboard-example] for a complete program.
|
||||
|
||||
Note that sessions reached over SSH always use OSC52, because the clipboard
|
||||
that matters is the one on the terminal the user is sitting at. Clipboard
|
||||
sequences passed through tmux can’t be traced back to the terminal running
|
||||
tmux, so tmux is assumed to support OSC52 as well.
|
||||
|
||||
[clipboard-example]: https://github.com/charmbracelet/bubbletea/tree/main/examples/clipboard
|
||||
|
||||
## Libraries we use with Bubble Tea
|
||||
|
||||
- [Bubbles][bubbles]: Common Bubble Tea components such as text inputs, viewports, spinners and so on
|
||||
|
|
|
|||
58
clipboard.go
58
clipboard.go
|
|
@ -1,5 +1,10 @@
|
|||
package tea
|
||||
|
||||
import (
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
)
|
||||
|
||||
// ClipboardMsg is a clipboard read message event. This message is emitted when
|
||||
// a terminal receives an OSC52 clipboard read message event.
|
||||
type ClipboardMsg struct {
|
||||
|
|
@ -68,3 +73,56 @@ type readPrimaryClipboardMsg struct{}
|
|||
func ReadPrimaryClipboard() Msg {
|
||||
return readPrimaryClipboardMsg{}
|
||||
}
|
||||
|
||||
// handleSetClipboard writes content to the given clipboard selection, either
|
||||
// through the program's clipboard backend or as an OSC52 sequence.
|
||||
func (p *Program) handleSetClipboard(selection ClipboardSelection, content string) {
|
||||
if p.clipboard == nil {
|
||||
switch selection {
|
||||
case uv.PrimaryClipboard:
|
||||
p.execute(ansi.SetPrimaryClipboard(content))
|
||||
default:
|
||||
p.execute(ansi.SetSystemClipboard(content))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := p.clipboard.Set(selection, content); err != nil {
|
||||
p.logClipboardError("set", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// handleReadClipboard reads the given clipboard selection and delivers the
|
||||
// result as a [ClipboardMsg].
|
||||
//
|
||||
// With a backend the message is produced as soon as the clipboard has been
|
||||
// read. Otherwise the terminal is queried with OSC52 and replies with a
|
||||
// [ClipboardMsg] of its own.
|
||||
func (p *Program) handleReadClipboard(selection ClipboardSelection) {
|
||||
if p.clipboard == nil {
|
||||
switch selection {
|
||||
case uv.PrimaryClipboard:
|
||||
p.execute(ansi.RequestPrimaryClipboard)
|
||||
default:
|
||||
p.execute(ansi.RequestSystemClipboard)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
content, err := p.clipboard.Get(selection)
|
||||
if err != nil {
|
||||
p.logClipboardError("read", err)
|
||||
}
|
||||
p.Send(ClipboardMsg{Content: content, Selection: selection})
|
||||
}()
|
||||
}
|
||||
|
||||
// logClipboardError logs a clipboard backend error when tracing is enabled.
|
||||
func (p *Program) logClipboardError(op string, err error) {
|
||||
if p.logger != nil {
|
||||
p.logger.Printf("clipboard: %s: %v", op, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
131
clipboard_backend.go
Normal file
131
clipboard_backend.go
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
package tea
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
)
|
||||
|
||||
// ErrClipboardUnavailable is returned by [ClipboardBackend] implementations
|
||||
// when no system clipboard is available.
|
||||
var ErrClipboardUnavailable = errors.New("bubbletea: clipboard unavailable")
|
||||
|
||||
// ClipboardSelection represents a clipboard selection. The two selections
|
||||
// Bubble Tea knows about are [uv.SystemClipboard] ('c') and
|
||||
// [uv.PrimaryClipboard] ('p').
|
||||
type ClipboardSelection = uv.ClipboardSelection
|
||||
|
||||
// ClipboardBackend performs clipboard operations outside of the terminal.
|
||||
//
|
||||
// Bubble Tea uses a backend automatically on terminals that are known not to
|
||||
// support OSC52 clipboard sequences, such as Apple's Terminal.app, by shelling
|
||||
// out to the operating system's clipboard tools (pbcopy and pbpaste on macOS,
|
||||
// wl-clipboard, xclip, or xsel on Linux).
|
||||
//
|
||||
// Provide your own backend with [WithClipboardBackend], or disable the
|
||||
// automatic fallback entirely with [WithoutClipboardFallback].
|
||||
type ClipboardBackend interface {
|
||||
// Set writes content to the given clipboard selection.
|
||||
Set(selection ClipboardSelection, content string) error
|
||||
|
||||
// Get reads the given clipboard selection. Implementations should
|
||||
// return [ErrClipboardUnavailable] when the selection cannot be read.
|
||||
Get(selection ClipboardSelection) (string, error)
|
||||
}
|
||||
|
||||
// Versions from which terminals are known to support OSC52 clipboard
|
||||
// sequences. They are intentionally conservative: a terminal that supports
|
||||
// OSC52 but is bridged anyway still works, because the system clipboard is the
|
||||
// same place the sequence would have written to.
|
||||
const (
|
||||
// vteOSC52Version is the VTE version that added OSC52 support.
|
||||
vteOSC52Version = 7600
|
||||
// konsoleOSC52Version is the Konsole version that added OSC52 support.
|
||||
konsoleOSC52Version = 230400
|
||||
)
|
||||
|
||||
// supportsOSC52 reports whether the terminal described by environ is expected
|
||||
// to support OSC52 clipboard sequences.
|
||||
func supportsOSC52(environ uv.Environ) bool {
|
||||
// Sessions reached over SSH use OSC52 to set the clipboard of the
|
||||
// terminal on the other end. Clipboard tools on the remote host would
|
||||
// target the wrong machine.
|
||||
if _, ok := environ.LookupEnv("SSH_TTY"); ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := environ.LookupEnv("SSH_CONNECTION"); ok {
|
||||
return true
|
||||
}
|
||||
|
||||
// Apple's Terminal.app does not support OSC52.
|
||||
if strings.EqualFold(environ.Getenv("TERM_PROGRAM"), "Apple_Terminal") {
|
||||
return false
|
||||
}
|
||||
|
||||
// The Linux console has no clipboard at all.
|
||||
if term := environ.Getenv("TERM"); term == "dumb" || strings.HasPrefix(term, "linux") {
|
||||
return false
|
||||
}
|
||||
|
||||
// VTE-based terminals only learned OSC52 in VTE 0.76.
|
||||
if vte, ok := environ.LookupEnv("VTE_VERSION"); ok {
|
||||
if v, err := strconv.Atoi(vte); err != nil || v < vteOSC52Version {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Konsole only learned OSC52 in 23.04.
|
||||
if konsole, ok := environ.LookupEnv("KONSOLE_VERSION"); ok {
|
||||
if v, err := strconv.Atoi(konsole); err != nil || v < konsoleOSC52Version {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// clipboardCommand returns the executable and arguments used for a clipboard
|
||||
// operation on the given selection. An empty name means the operation is not
|
||||
// supported.
|
||||
type clipboardCommand func(selection ClipboardSelection) (name string, args []string)
|
||||
|
||||
// commandClipboardBackend is a [ClipboardBackend] backed by command line
|
||||
// clipboard tools.
|
||||
type commandClipboardBackend struct {
|
||||
set clipboardCommand
|
||||
get clipboardCommand
|
||||
}
|
||||
|
||||
// Set writes content to the clipboard with the backend's set command.
|
||||
func (b commandClipboardBackend) Set(selection ClipboardSelection, content string) error {
|
||||
name, args := b.set(selection)
|
||||
if name == "" {
|
||||
return ErrClipboardUnavailable
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(context.Background(), name, args...)
|
||||
cmd.Stdin = strings.NewReader(content)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("bubbletea: %s: %w", name, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get reads the clipboard with the backend's get command.
|
||||
func (b commandClipboardBackend) Get(selection ClipboardSelection) (string, error) {
|
||||
name, args := b.get(selection)
|
||||
if name == "" {
|
||||
return "", ErrClipboardUnavailable
|
||||
}
|
||||
|
||||
out, err := exec.CommandContext(context.Background(), name, args...).Output()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("bubbletea: %s: %w", name, err)
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
||||
31
clipboard_darwin.go
Normal file
31
clipboard_darwin.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package tea
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
)
|
||||
|
||||
// newLocalClipboardBackend returns a clipboard backend backed by the macOS
|
||||
// pbcopy and pbpaste tools, or nil when they are not available.
|
||||
//
|
||||
// macOS only has a single general pasteboard, so the primary selection maps to
|
||||
// it as well.
|
||||
func newLocalClipboardBackend(uv.Environ) ClipboardBackend {
|
||||
pbcopy, err := exec.LookPath("pbcopy")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
pbpaste, err := exec.LookPath("pbpaste")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return commandClipboardBackend{
|
||||
set: func(ClipboardSelection) (string, []string) { return pbcopy, nil },
|
||||
get: func(ClipboardSelection) (string, []string) { return pbpaste, nil },
|
||||
}
|
||||
}
|
||||
229
clipboard_test.go
Normal file
229
clipboard_test.go
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
package tea
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
)
|
||||
|
||||
// stubClipboardCall records a single clipboard operation.
|
||||
type stubClipboardCall struct {
|
||||
selection byte
|
||||
content string
|
||||
}
|
||||
|
||||
// stubClipboardBackend is an in-memory [ClipboardBackend] for tests.
|
||||
type stubClipboardBackend struct {
|
||||
mu sync.Mutex
|
||||
setCalls []stubClipboardCall
|
||||
getCalls []byte
|
||||
getValues map[byte]string
|
||||
setErr error
|
||||
getErr error
|
||||
}
|
||||
|
||||
func (b *stubClipboardBackend) Set(selection ClipboardSelection, content string) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
b.setCalls = append(b.setCalls, stubClipboardCall{selection: selection, content: content})
|
||||
return b.setErr
|
||||
}
|
||||
|
||||
func (b *stubClipboardBackend) Get(selection ClipboardSelection) (string, error) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
b.getCalls = append(b.getCalls, selection)
|
||||
if b.getErr != nil {
|
||||
return "", b.getErr
|
||||
}
|
||||
return b.getValues[selection], nil
|
||||
}
|
||||
|
||||
func (b *stubClipboardBackend) setCallsFor() []stubClipboardCall {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return append([]stubClipboardCall(nil), b.setCalls...)
|
||||
}
|
||||
|
||||
func (b *stubClipboardBackend) getCallsFor() []byte {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return append([]byte(nil), b.getCalls...)
|
||||
}
|
||||
|
||||
// withTestTimeout returns an option that bounds the runtime of a program under
|
||||
// test, so a bug that prevents it from exiting fails the test instead of
|
||||
// hanging it.
|
||||
func withTestTimeout(t *testing.T) ProgramOption {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
|
||||
t.Cleanup(cancel)
|
||||
return WithContext(ctx)
|
||||
}
|
||||
|
||||
// clipboardTestModel quits as soon as it receives a clipboard message, so
|
||||
// tests don't need to poll for it.
|
||||
type clipboardTestModel struct {
|
||||
received chan ClipboardMsg
|
||||
}
|
||||
|
||||
func (m *clipboardTestModel) Init() Cmd { return nil }
|
||||
|
||||
func (m *clipboardTestModel) Update(msg Msg) (Model, Cmd) {
|
||||
if cm, ok := msg.(ClipboardMsg); ok {
|
||||
m.received <- cm
|
||||
return m, Quit
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *clipboardTestModel) View() View { return NewView("") }
|
||||
|
||||
func TestWithClipboardBackendIsUsed(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
backend := &stubClipboardBackend{getValues: map[byte]string{uv.SystemClipboard: "pasted"}}
|
||||
model := &clipboardTestModel{received: make(chan ClipboardMsg, 1)}
|
||||
|
||||
var out bytes.Buffer
|
||||
p := NewProgram(model,
|
||||
WithWindowSize(80, 24),
|
||||
WithEnvironment([]string{"TERM=xterm-256color"}),
|
||||
WithInput(&bytes.Buffer{}),
|
||||
WithOutput(&out),
|
||||
WithClipboardBackend(backend),
|
||||
withTestTimeout(t),
|
||||
)
|
||||
|
||||
go p.Send(sequenceMsg([]Cmd{SetClipboard("copied"), ReadClipboard}))
|
||||
|
||||
if _, err := p.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if got := out.String(); strings.Contains(got, "\x1b]52;") {
|
||||
t.Errorf("output contains an OSC52 sequence: %q", got)
|
||||
}
|
||||
|
||||
// The set may still be in flight when the read completes, so wait for it.
|
||||
deadline := time.Now().Add(time.Second)
|
||||
for len(backend.setCallsFor()) == 0 && time.Now().Before(deadline) {
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
calls := backend.setCallsFor()
|
||||
if len(calls) != 1 || calls[0].content != "copied" {
|
||||
t.Errorf("set calls = %v, want one call with %q", calls, "copied")
|
||||
}
|
||||
|
||||
select {
|
||||
case cm := <-model.received:
|
||||
if cm.Content != "pasted" {
|
||||
t.Errorf("ClipboardMsg content = %q, want %q", cm.Content, "pasted")
|
||||
}
|
||||
if cm.Clipboard() != uv.SystemClipboard {
|
||||
t.Errorf("ClipboardMsg selection = %q, want %q", cm.Clipboard(), uv.SystemClipboard)
|
||||
}
|
||||
default:
|
||||
t.Error("no ClipboardMsg received")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClipboardWithoutBackendUsesOSC52(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var out bytes.Buffer
|
||||
p := NewProgram(&testModel{},
|
||||
WithWindowSize(80, 24),
|
||||
WithOutput(&out),
|
||||
)
|
||||
|
||||
p.handleSetClipboard(uv.SystemClipboard, "hello")
|
||||
p.handleReadClipboard(uv.SystemClipboard)
|
||||
p.handleSetClipboard(uv.PrimaryClipboard, "primary")
|
||||
p.handleReadClipboard(uv.PrimaryClipboard)
|
||||
|
||||
if err := p.flush(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got := out.String()
|
||||
// base64("hello") is "aGVsbG8=", base64("primary") is "cHJpbWFyeQ==".
|
||||
for _, want := range []string{"\x1b]52;c;aGVsbG8=", "\x1b]52;c;?", "\x1b]52;p;cHJpbWFyeQ==", "\x1b]52;p;?"} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("output %q does not contain %q", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClipboardBackendErrorsDoNotHangReads(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
backend := &stubClipboardBackend{getErr: ErrClipboardUnavailable}
|
||||
model := &clipboardTestModel{received: make(chan ClipboardMsg, 1)}
|
||||
|
||||
var out bytes.Buffer
|
||||
p := NewProgram(model,
|
||||
WithWindowSize(80, 24),
|
||||
WithEnvironment([]string{"TERM=xterm-256color"}),
|
||||
WithInput(&bytes.Buffer{}),
|
||||
WithOutput(&out),
|
||||
WithClipboardBackend(backend),
|
||||
withTestTimeout(t),
|
||||
)
|
||||
|
||||
go p.Send(sequenceMsg([]Cmd{ReadClipboard}))
|
||||
|
||||
if _, err := p.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
select {
|
||||
case cm := <-model.received:
|
||||
if cm.Content != "" {
|
||||
t.Errorf("ClipboardMsg content = %q, want empty", cm.Content)
|
||||
}
|
||||
default:
|
||||
t.Error("no ClipboardMsg received")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClipboardFallbackDetection(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("apple terminal selects a backend on darwin", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := NewProgram(&testModel{}, WithEnvironment([]string{"TERM_PROGRAM=Apple_Terminal", "TERM=xterm-256color"}))
|
||||
if runtime.GOOS == "darwin" {
|
||||
if p.clipboard == nil {
|
||||
t.Error("expected a clipboard backend on darwin")
|
||||
}
|
||||
} else if p.clipboard != nil {
|
||||
t.Error("expected no clipboard backend without a terminal clipboard tool")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("supported terminal does not select a backend", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := NewProgram(&testModel{}, WithEnvironment([]string{"TERM_PROGRAM=iTerm.app", "TERM=xterm-256color"}))
|
||||
if p.clipboard != nil {
|
||||
t.Error("expected no clipboard backend on a terminal with OSC52 support")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("fallback can be disabled", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := NewProgram(&testModel{},
|
||||
WithEnvironment([]string{"TERM_PROGRAM=Apple_Terminal", "TERM=xterm-256color"}),
|
||||
WithoutClipboardFallback(),
|
||||
)
|
||||
if p.clipboard != nil {
|
||||
t.Error("expected no clipboard backend when the fallback is disabled")
|
||||
}
|
||||
})
|
||||
}
|
||||
98
clipboard_unix.go
Normal file
98
clipboard_unix.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
//go:build !windows && !darwin
|
||||
// +build !windows,!darwin
|
||||
|
||||
package tea
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
)
|
||||
|
||||
// newLocalClipboardBackend returns a clipboard backend backed by the system's
|
||||
// clipboard tools. Wayland sessions use wl-clipboard, X11 sessions use xclip
|
||||
// or xsel. It returns nil when no usable tool is found.
|
||||
func newLocalClipboardBackend(environ uv.Environ) ClipboardBackend {
|
||||
if environ.Getenv("WAYLAND_DISPLAY") != "" {
|
||||
if backend := waylandClipboardBackend(); backend != nil {
|
||||
return backend
|
||||
}
|
||||
}
|
||||
if environ.Getenv("DISPLAY") != "" {
|
||||
return xClipboardBackend()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// waylandClipboardBackend returns a backend backed by wl-copy and wl-paste, or
|
||||
// nil when they are not available.
|
||||
func waylandClipboardBackend() ClipboardBackend {
|
||||
copyPath, err := exec.LookPath("wl-copy")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
pastePath, err := exec.LookPath("wl-paste")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return commandClipboardBackend{
|
||||
set: func(selection ClipboardSelection) (string, []string) {
|
||||
if primarySelection(selection) {
|
||||
return copyPath, []string{"--primary"}
|
||||
}
|
||||
return copyPath, nil
|
||||
},
|
||||
get: func(selection ClipboardSelection) (string, []string) {
|
||||
// --no-newline avoids wl-paste appending a trailing newline,
|
||||
// which would corrupt the clipboard contents.
|
||||
args := []string{"--no-newline"}
|
||||
if primarySelection(selection) {
|
||||
args = append(args, "--primary")
|
||||
}
|
||||
return pastePath, args
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// xClipboardBackend returns a backend backed by xclip or xsel, or nil when
|
||||
// neither is available.
|
||||
func xClipboardBackend() ClipboardBackend {
|
||||
if xclip, err := exec.LookPath("xclip"); err == nil {
|
||||
return commandClipboardBackend{
|
||||
set: func(selection ClipboardSelection) (string, []string) {
|
||||
return xclip, []string{"-selection", xSelection(selection)}
|
||||
},
|
||||
get: func(selection ClipboardSelection) (string, []string) {
|
||||
return xclip, []string{"-selection", xSelection(selection), "-o"}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if xsel, err := exec.LookPath("xsel"); err == nil {
|
||||
return commandClipboardBackend{
|
||||
set: func(selection ClipboardSelection) (string, []string) {
|
||||
return xsel, []string{"--" + xSelection(selection), "--input"}
|
||||
},
|
||||
get: func(selection ClipboardSelection) (string, []string) {
|
||||
return xsel, []string{"--" + xSelection(selection), "--output"}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// xSelection returns the X11 selection name for the given selection.
|
||||
func xSelection(selection ClipboardSelection) string {
|
||||
if primarySelection(selection) {
|
||||
return "primary"
|
||||
}
|
||||
return "clipboard"
|
||||
}
|
||||
|
||||
// primarySelection reports whether selection refers to the primary (X11 and
|
||||
// Wayland only) clipboard.
|
||||
func primarySelection(selection ClipboardSelection) bool {
|
||||
return selection == uv.PrimaryClipboard
|
||||
}
|
||||
13
clipboard_windows.go
Normal file
13
clipboard_windows.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package tea
|
||||
|
||||
import uv "github.com/charmbracelet/ultraviolet"
|
||||
|
||||
// newLocalClipboardBackend always returns nil on Windows: Windows Terminal
|
||||
// supports OSC52 natively, and Windows has no clipboard tool that can read the
|
||||
// clipboard without an additional dependency.
|
||||
func newLocalClipboardBackend(uv.Environ) ClipboardBackend {
|
||||
return nil
|
||||
}
|
||||
78
examples/clipboard/main.go
Normal file
78
examples/clipboard/main.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package main
|
||||
|
||||
// An example of copying to and pasting from the system clipboard.
|
||||
//
|
||||
// Copying uses OSC52 when the terminal supports it. On terminals that don't
|
||||
// support OSC52, such as Apple's Terminal.app, Bubble Tea bridges the
|
||||
// clipboard through the operating system's clipboard tools (pbcopy/pbpaste on
|
||||
// macOS, wl-clipboard or xclip on Linux) instead.
|
||||
//
|
||||
// The same bridge applies to programs started with Exec and ExecProcess: when
|
||||
// the terminal can't handle OSC52, they run on a pseudo-terminal whose
|
||||
// clipboard traffic is intercepted and bridged.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
)
|
||||
|
||||
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
|
||||
|
||||
type model struct {
|
||||
input string
|
||||
copied string
|
||||
pasted string
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd { return nil }
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c", "esc":
|
||||
return m, tea.Quit
|
||||
case "enter":
|
||||
m.copied = m.input
|
||||
return m, tea.SetClipboard(m.input)
|
||||
case "ctrl+v":
|
||||
return m, tea.ReadClipboard
|
||||
case "backspace":
|
||||
if n := len(m.input); n > 0 {
|
||||
m.input = m.input[:n-1]
|
||||
}
|
||||
default:
|
||||
if text := msg.Key().Text; len(text) > 0 {
|
||||
m.input += text
|
||||
}
|
||||
}
|
||||
|
||||
case tea.ClipboardMsg:
|
||||
m.pasted = msg.Content
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m model) View() tea.View {
|
||||
var s strings.Builder
|
||||
s.WriteString("Type something, then:\n\n")
|
||||
s.WriteString(helpStyle.Render(" enter copy the input to the clipboard") + "\n")
|
||||
s.WriteString(helpStyle.Render(" ctrl+v paste the clipboard") + "\n")
|
||||
s.WriteString(helpStyle.Render(" esc quit") + "\n\n")
|
||||
s.WriteString("Input: " + m.input + "\n")
|
||||
s.WriteString("Copied: " + m.copied + "\n")
|
||||
s.WriteString("Pasted: " + m.pasted + "\n")
|
||||
return tea.NewView(s.String())
|
||||
}
|
||||
|
||||
func main() {
|
||||
if _, err := tea.NewProgram(model{}).Run(); err != nil {
|
||||
fmt.Println("Uh oh:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -24,11 +24,14 @@ require (
|
|||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/aymerick/douceur v0.2.0 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 // indirect
|
||||
github.com/charmbracelet/x/conpty v0.2.0 // indirect
|
||||
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/charmbracelet/x/xpty v0.1.4 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/creack/pty v1.1.24 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gorilla/css v1.0.1 // indirect
|
||||
|
|
@ -42,6 +45,6 @@ require (
|
|||
github.com/yuin/goldmark-emoji v1.0.5 // indirect
|
||||
golang.org/x/net v0.39.0 // indirect
|
||||
golang.org/x/sync v0.21.0 // indirect
|
||||
golang.org/x/sys v0.46.0 // indirect
|
||||
golang.org/x/sys v0.47.0 // indirect
|
||||
golang.org/x/text v0.24.0 // indirect
|
||||
)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 h1:3FmWo
|
|||
github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7/go.mod h1:f/jRa757WUmaOZrbPspXymbg/GnbF+rwe4OLsG7aXYo=
|
||||
github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI=
|
||||
github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ=
|
||||
github.com/charmbracelet/x/conpty v0.2.0 h1:eKtA2hm34qNfgJCDp/M6Dc0gLy7e07YEK4qAdNGOvVY=
|
||||
github.com/charmbracelet/x/conpty v0.2.0/go.mod h1:fexgUnVrZgw8scD49f6VSi0Ggj9GWYIrpedRthAwW/8=
|
||||
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250602192518-9e722df69bbb h1:oTM8tZxV7FY0ehvYjFuICouuhzE08UZYNqUIp/lDQdY=
|
||||
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250602192518-9e722df69bbb/go.mod h1:T9jr8CzFpjhFVHjNjKwbAD7KwBNyFnj2pntAO7F2zw0=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
|
||||
|
|
@ -38,10 +40,14 @@ github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8
|
|||
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||
github.com/charmbracelet/x/xpty v0.1.4 h1:4jaW7u+8AHQMxesiVc+zUMsspu7GyDwtJO+gy/tFtW4=
|
||||
github.com/charmbracelet/x/xpty v0.1.4/go.mod h1:7t8P7BpPiolHJ1pLzz7/4ujDbD+sUxI9yA3CBOLOIcU=
|
||||
github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
|
||||
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
|
||||
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
|
||||
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
|
||||
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
|
|
@ -81,7 +87,7 @@ golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
|||
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
||||
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
||||
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
||||
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||
|
|
|
|||
21
exec.go
21
exec.go
|
|
@ -108,12 +108,21 @@ func (p *Program) exec(c ExecCommand, fn ExecCallback) {
|
|||
return
|
||||
}
|
||||
|
||||
c.SetStdin(p.input)
|
||||
c.SetStdout(p.output)
|
||||
c.SetStderr(os.Stderr)
|
||||
var err error
|
||||
if osCmd, ok := c.(*osExecCommand); ok && p.clipboard != nil {
|
||||
// Bridge the command's OSC52 clipboard traffic through the
|
||||
// program's clipboard backend.
|
||||
err = p.execBridged(osCmd.Cmd)
|
||||
} else {
|
||||
c.SetStdin(p.input)
|
||||
c.SetStdout(p.output)
|
||||
c.SetStderr(os.Stderr)
|
||||
|
||||
// Execute system command.
|
||||
if err := c.Run(); err != nil {
|
||||
// Execute system command.
|
||||
err = c.Run()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
_ = p.RestoreTerminal() // also try to restore the terminal.
|
||||
if fn != nil {
|
||||
go p.Send(fn(err))
|
||||
|
|
@ -122,7 +131,7 @@ func (p *Program) exec(c ExecCommand, fn ExecCallback) {
|
|||
}
|
||||
|
||||
// Have the program re-capture input.
|
||||
err := p.RestoreTerminal()
|
||||
err = p.RestoreTerminal()
|
||||
if fn != nil {
|
||||
go p.Send(fn(err))
|
||||
}
|
||||
|
|
|
|||
107
exec_pty.go
Normal file
107
exec_pty.go
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
package tea
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"sync"
|
||||
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
"github.com/charmbracelet/x/term"
|
||||
xpty "github.com/charmbracelet/x/xpty"
|
||||
)
|
||||
|
||||
// execBridged runs c on a pseudo-terminal and bridges its clipboard traffic
|
||||
// through the program's clipboard backend. This is what makes copy and paste
|
||||
// work in external programs running on terminals without OSC52 support, in the
|
||||
// same way osc52pty does for a wrapped process.
|
||||
//
|
||||
// It must only be called while the program has released the terminal.
|
||||
func (p *Program) execBridged(c *exec.Cmd) error {
|
||||
width, height := p.width, p.height
|
||||
if width <= 0 || height <= 0 {
|
||||
// Let the pty keep its default size.
|
||||
width, height = -1, -1
|
||||
}
|
||||
if p.ttyOutput != nil {
|
||||
if w, h, err := term.GetSize(p.ttyOutput.Fd()); err == nil {
|
||||
width, height = w, h
|
||||
}
|
||||
}
|
||||
|
||||
pt, err := xpty.NewPty(width, height)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bubbletea: could not create pty: %w", err)
|
||||
}
|
||||
defer pt.Close() //nolint:errcheck
|
||||
|
||||
preparePtyCommand(c)
|
||||
if err := pt.Start(c); err != nil {
|
||||
return fmt.Errorf("bubbletea: could not start command on pty: %w", err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
done := make(chan struct{})
|
||||
var stopOnce sync.Once
|
||||
stop := func() { stopOnce.Do(func() { close(done) }) }
|
||||
defer stop()
|
||||
|
||||
var cancelInput func()
|
||||
if p.input != nil {
|
||||
input, err := uv.NewCancelReader(p.input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bubbletea: could not create pty input reader: %w", err)
|
||||
}
|
||||
defer input.Close() //nolint:errcheck
|
||||
cancelInput = func() { _ = input.Cancel() }
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
_, _ = io.Copy(pt, input)
|
||||
}()
|
||||
}
|
||||
|
||||
bridge := newOSC52Bridge(p.clipboard, p.output, pt)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
_, _ = io.Copy(bridge, pt)
|
||||
_ = bridge.Flush()
|
||||
}()
|
||||
|
||||
resize, stopResize := ptyResizeSignals()
|
||||
defer stopResize()
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case <-resize:
|
||||
if p.ttyOutput == nil {
|
||||
continue
|
||||
}
|
||||
if w, h, err := term.GetSize(p.ttyOutput.Fd()); err == nil {
|
||||
_ = pt.Resize(w, h)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
waitErr := xpty.WaitProcess(p.ctx, c)
|
||||
|
||||
// Stop forwarding and wait for the goroutines, so they don't steal input
|
||||
// from the program once it resumes.
|
||||
stop()
|
||||
if cancelInput != nil {
|
||||
cancelInput()
|
||||
}
|
||||
_ = pt.Close()
|
||||
wg.Wait()
|
||||
|
||||
if waitErr != nil {
|
||||
return fmt.Errorf("bubbletea: command failed: %w", waitErr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
31
exec_pty_unix.go
Normal file
31
exec_pty_unix.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix || zos
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix zos
|
||||
|
||||
package tea
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// preparePtyCommand makes the command a session leader with the pseudo-terminal
|
||||
// as its controlling terminal. Without it the command would not receive
|
||||
// SIGWINCH on resize, and the terminal's line discipline would not generate
|
||||
// signals such as SIGINT for it.
|
||||
func preparePtyCommand(c *exec.Cmd) {
|
||||
if c.SysProcAttr == nil {
|
||||
c.SysProcAttr = &syscall.SysProcAttr{}
|
||||
}
|
||||
c.SysProcAttr.Setsid = true
|
||||
c.SysProcAttr.Setctty = true
|
||||
}
|
||||
|
||||
// ptyResizeSignals returns a channel that receives terminal resize signals,
|
||||
// along with a function that stops listening for them.
|
||||
func ptyResizeSignals() (<-chan os.Signal, func()) {
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGWINCH)
|
||||
return sig, func() { signal.Stop(sig) }
|
||||
}
|
||||
99
exec_pty_unix_test.go
Normal file
99
exec_pty_unix_test.go
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix || zos
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix zos
|
||||
|
||||
package tea
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
)
|
||||
|
||||
func TestExecBridgedClipboardSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
backend := &stubClipboardBackend{}
|
||||
var out bytes.Buffer
|
||||
p := NewProgram(&testModel{},
|
||||
WithWindowSize(80, 24),
|
||||
WithInput(strings.NewReader("")),
|
||||
WithOutput(&out),
|
||||
WithClipboardBackend(backend),
|
||||
)
|
||||
|
||||
// The command copies "hello" with an OSC52 sequence surrounded by plain
|
||||
// output. The sequence must be intercepted, not forwarded.
|
||||
cmd := exec.Command("sh", "-c", `printf 'before\033]52;c;aGVsbG8=\a after'`)
|
||||
if err := p.execBridged(cmd); err != nil {
|
||||
t.Fatalf("execBridged: %v", err)
|
||||
}
|
||||
|
||||
if got := out.String(); got != "before after" {
|
||||
t.Errorf("output = %q, want %q", got, "before after")
|
||||
}
|
||||
calls := backend.setCallsFor()
|
||||
if len(calls) != 1 || calls[0].content != "hello" {
|
||||
t.Errorf("set calls = %v, want one call with %q", calls, "hello")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecBridgedClipboardRead(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
backend := &stubClipboardBackend{getValues: map[byte]string{uv.SystemClipboard: "hello"}}
|
||||
var out bytes.Buffer
|
||||
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
p := NewProgram(&testModel{},
|
||||
WithContext(ctx),
|
||||
WithWindowSize(80, 24),
|
||||
WithInput(strings.NewReader("")),
|
||||
WithOutput(&out),
|
||||
WithClipboardBackend(backend),
|
||||
)
|
||||
|
||||
// The command asks for the clipboard, then reads exactly as many bytes
|
||||
// as the reply takes. Raw mode is needed so the read returns without a
|
||||
// line delimiter, and echo is disabled so the reply is not echoed back
|
||||
// as command output. If the reply is never injected, the command blocks
|
||||
// until the context times out.
|
||||
cmd := exec.Command("sh", "-c", `stty raw -echo 2>/dev/null; printf '\033]52;c;?\a'; head -c 16 >/dev/null`)
|
||||
|
||||
if err := p.execBridged(cmd); err != nil {
|
||||
t.Fatalf("execBridged: %v", err)
|
||||
}
|
||||
|
||||
if got := backend.getCallsFor(); len(got) != 1 || got[0] != uv.SystemClipboard {
|
||||
t.Errorf("get calls = %v, want one call for %q", got, uv.SystemClipboard)
|
||||
}
|
||||
if got := out.String(); got != "" {
|
||||
t.Errorf("output = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecBridgedPlainOutput(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var out bytes.Buffer
|
||||
p := NewProgram(&testModel{},
|
||||
WithWindowSize(80, 24),
|
||||
WithInput(strings.NewReader("")),
|
||||
WithOutput(&out),
|
||||
WithClipboardBackend(&stubClipboardBackend{}),
|
||||
)
|
||||
|
||||
cmd := exec.Command("sh", "-c", `printf 'plain output'`)
|
||||
if err := p.execBridged(cmd); err != nil {
|
||||
t.Fatalf("execBridged: %v", err)
|
||||
}
|
||||
if got := out.String(); got != "plain output" {
|
||||
t.Errorf("output = %q, want %q", got, "plain output")
|
||||
}
|
||||
}
|
||||
20
exec_pty_windows.go
Normal file
20
exec_pty_windows.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package tea
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// preparePtyCommand is a no-op on Windows, where ConPTY handles the session
|
||||
// and console setup of the command.
|
||||
func preparePtyCommand(*exec.Cmd) {}
|
||||
|
||||
// ptyResizeSignals returns a channel that never receives a value: Windows has
|
||||
// no resize signal, and ConPTY reports resizes through the pseudo-terminal
|
||||
// itself.
|
||||
func ptyResizeSignals() (<-chan os.Signal, func()) {
|
||||
return nil, func() {}
|
||||
}
|
||||
5
go.mod
5
go.mod
|
|
@ -10,17 +10,20 @@ require (
|
|||
github.com/charmbracelet/x/ansi v0.11.7
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f
|
||||
github.com/charmbracelet/x/term v0.2.2
|
||||
github.com/charmbracelet/x/xpty v0.1.4
|
||||
github.com/lucasb-eyer/go-colorful v1.4.0
|
||||
github.com/muesli/cancelreader v0.2.2
|
||||
golang.org/x/sys v0.46.0
|
||||
golang.org/x/sys v0.47.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
|
||||
github.com/charmbracelet/x/conpty v0.2.0 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/creack/pty v1.1.24 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.23 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
|
|
|
|||
10
go.sum
10
go.sum
|
|
@ -6,6 +6,8 @@ github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 h1:3FmWo
|
|||
github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7/go.mod h1:f/jRa757WUmaOZrbPspXymbg/GnbF+rwe4OLsG7aXYo=
|
||||
github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI=
|
||||
github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ=
|
||||
github.com/charmbracelet/x/conpty v0.2.0 h1:eKtA2hm34qNfgJCDp/M6Dc0gLy7e07YEK4qAdNGOvVY=
|
||||
github.com/charmbracelet/x/conpty v0.2.0/go.mod h1:fexgUnVrZgw8scD49f6VSi0Ggj9GWYIrpedRthAwW/8=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f h1:UytXHv0UxnsDFmL/7Z9Q5SBYPwSuRLXHbwx+6LycZ2w=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||
|
|
@ -14,10 +16,14 @@ github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8
|
|||
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||
github.com/charmbracelet/x/xpty v0.1.4 h1:4jaW7u+8AHQMxesiVc+zUMsspu7GyDwtJO+gy/tFtW4=
|
||||
github.com/charmbracelet/x/xpty v0.1.4/go.mod h1:7t8P7BpPiolHJ1pLzz7/4ujDbD+sUxI9yA3CBOLOIcU=
|
||||
github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
|
||||
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
|
||||
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW4TvVgFr4=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw=
|
||||
|
|
@ -32,5 +38,5 @@ golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZ
|
|||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
||||
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
||||
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
||||
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
|
|
|
|||
24
options.go
24
options.go
|
|
@ -166,3 +166,27 @@ func WithWindowSize(width, height int) ProgramOption {
|
|||
p.height = height
|
||||
}
|
||||
}
|
||||
|
||||
// WithClipboardBackend sets the clipboard backend used to copy and paste
|
||||
// outside of the terminal. This overrides the automatic fallback that Bubble
|
||||
// Tea applies on terminals without OSC52 support, such as Apple's
|
||||
// Terminal.app.
|
||||
//
|
||||
// Passing a nil backend opts out of the fallback and always uses OSC52.
|
||||
//
|
||||
// See [ClipboardBackend] and [WithoutClipboardFallback].
|
||||
func WithClipboardBackend(backend ClipboardBackend) ProgramOption {
|
||||
return func(p *Program) {
|
||||
p.clipboard = backend
|
||||
p.clipboardBackendSet = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithoutClipboardFallback disables the operating system clipboard fallback
|
||||
// that Bubble Tea enables on terminals without OSC52 support. Clipboard
|
||||
// operations will always be sent to the terminal as OSC52 sequences.
|
||||
func WithoutClipboardFallback() ProgramOption {
|
||||
return func(p *Program) {
|
||||
p.disableClipboardFallback = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
279
osc52_scan.go
Normal file
279
osc52_scan.go
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
package tea
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Control bytes used by OSC52 clipboard sequences. A sequence is introduced by
|
||||
// ESC ']' (or the 8-bit equivalent 0x9d) and terminated by BEL, ST (ESC '\'),
|
||||
// or the 8-bit ST.
|
||||
const (
|
||||
oscByte = 0x1b
|
||||
osc8Byte = 0x9d
|
||||
stByte = 0x9c
|
||||
belByte = 0x07
|
||||
canByte = 0x18
|
||||
subByte = 0x1a
|
||||
)
|
||||
|
||||
// osc52Prefix is the OSC command number for clipboard operations.
|
||||
const osc52Prefix = "52;"
|
||||
|
||||
// osc52MaxPending bounds how many bytes are held back while waiting for an
|
||||
// OSC52 sequence to complete. A sequence longer than this is passed through
|
||||
// untouched rather than being intercepted.
|
||||
const osc52MaxPending = 1 << 20
|
||||
|
||||
// osc52Parse is the outcome of parsing an OSC52 sequence.
|
||||
type osc52Parse int
|
||||
|
||||
const (
|
||||
// osc52NeedMore means the sequence is incomplete and more bytes are
|
||||
// required before it can be parsed.
|
||||
osc52NeedMore osc52Parse = iota
|
||||
|
||||
// osc52Pass means the sequence is complete but is not a usable OSC52
|
||||
// sequence, and should be forwarded untouched.
|
||||
osc52Pass
|
||||
|
||||
// osc52Handle means the sequence is a well-formed OSC52 sequence that
|
||||
// should be handled by the bridge.
|
||||
osc52Handle
|
||||
)
|
||||
|
||||
// osc52Bridge intercepts OSC52 clipboard sequences in a terminal output stream
|
||||
// and performs the corresponding clipboard operations through a
|
||||
// [ClipboardBackend].
|
||||
//
|
||||
// This is what allows programs running on terminals without OSC52 support,
|
||||
// such as Apple's Terminal.app, to copy and paste. Set requests are consumed,
|
||||
// read requests are answered by injecting the response into the program's
|
||||
// terminal input via reply. All other bytes are forwarded to w untouched.
|
||||
type osc52Bridge struct {
|
||||
backend ClipboardBackend
|
||||
w io.Writer
|
||||
reply io.Writer
|
||||
|
||||
// pending holds bytes that may be the start of an OSC52 sequence which
|
||||
// has not been fully written yet.
|
||||
pending []byte
|
||||
}
|
||||
|
||||
// newOSC52Bridge returns a bridge that performs clipboard operations through
|
||||
// backend, forwards all other output to w, and injects clipboard replies into
|
||||
// reply.
|
||||
func newOSC52Bridge(backend ClipboardBackend, w, reply io.Writer) *osc52Bridge {
|
||||
return &osc52Bridge{backend: backend, w: w, reply: reply}
|
||||
}
|
||||
|
||||
// Write filters OSC52 sequences out of p. Everything else is forwarded to the
|
||||
// underlying writer.
|
||||
func (b *osc52Bridge) Write(p []byte) (int, error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
buf := p
|
||||
if len(b.pending) > 0 {
|
||||
buf = append(b.pending, p...)
|
||||
b.pending = nil
|
||||
}
|
||||
|
||||
out := make([]byte, 0, len(buf))
|
||||
for len(buf) > 0 {
|
||||
start, found := indexOSC52(buf)
|
||||
if !found {
|
||||
// Nothing to intercept. Forward everything except a trailing
|
||||
// partial introducer, which is held back until more data
|
||||
// arrives so a sequence split across writes can still be
|
||||
// intercepted.
|
||||
n := len(buf) - osc52PrefixLen(buf)
|
||||
out = append(out, buf[:n]...)
|
||||
b.pending = append(b.pending, buf[n:]...)
|
||||
break
|
||||
}
|
||||
|
||||
out = append(out, buf[:start]...)
|
||||
rest := buf[start:]
|
||||
|
||||
seqLen, selection, payload, terminator, status := parseOSC52(rest)
|
||||
switch status {
|
||||
case osc52NeedMore:
|
||||
if len(rest) > osc52MaxPending {
|
||||
// Never hold back unbounded data. Forward the sequence
|
||||
// untouched instead of intercepting it.
|
||||
out = append(out, rest...)
|
||||
} else {
|
||||
b.pending = append(b.pending, rest...)
|
||||
}
|
||||
rest = nil
|
||||
case osc52Pass:
|
||||
out = append(out, rest[:seqLen]...)
|
||||
case osc52Handle:
|
||||
if err := b.handle(selection, payload, terminator); err != nil {
|
||||
// Fail open: forward the sequence untouched so terminals
|
||||
// that do understand OSC52 can still act on it.
|
||||
out = append(out, rest[:seqLen]...)
|
||||
}
|
||||
}
|
||||
|
||||
if rest == nil {
|
||||
break
|
||||
}
|
||||
buf = rest[seqLen:]
|
||||
}
|
||||
|
||||
if len(out) == 0 {
|
||||
return len(p), nil
|
||||
}
|
||||
if _, err := b.w.Write(out); err != nil {
|
||||
return 0, fmt.Errorf("bubbletea: writing bridged output: %w", err)
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// handle performs the clipboard operation described by a parsed OSC52
|
||||
// sequence.
|
||||
func (b *osc52Bridge) handle(selection byte, payload []byte, terminator byte) error {
|
||||
if bytes.Equal(payload, []byte("?")) {
|
||||
content, err := b.backend.Get(selection)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bubbletea: reading clipboard: %w", err)
|
||||
}
|
||||
if _, err := b.reply.Write(encodeOSC52(selection, content, terminator)); err != nil {
|
||||
return fmt.Errorf("bubbletea: writing clipboard reply: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
decoded, err := base64.StdEncoding.DecodeString(string(payload))
|
||||
if err != nil {
|
||||
return fmt.Errorf("bubbletea: invalid OSC52 payload: %w", err)
|
||||
}
|
||||
if err := b.backend.Set(selection, string(decoded)); err != nil {
|
||||
return fmt.Errorf("bubbletea: writing clipboard: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// indexOSC52 returns the index of the first OSC52 introducer in b.
|
||||
func indexOSC52(b []byte) (int, bool) {
|
||||
for i := 0; i < len(b); i++ {
|
||||
switch b[i] {
|
||||
case osc8Byte:
|
||||
if bytes.HasPrefix(b[i+1:], []byte(osc52Prefix)) {
|
||||
return i, true
|
||||
}
|
||||
case oscByte:
|
||||
if i+1 < len(b) && b[i+1] == ']' && bytes.HasPrefix(b[i+2:], []byte(osc52Prefix)) {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// osc52PrefixLen returns the length of the longest suffix of b that could be
|
||||
// the beginning of an OSC52 introducer. Those bytes must not be forwarded
|
||||
// before it is known whether the sequence should be intercepted.
|
||||
//
|
||||
// A trailing ESC is held back as well, since a sequence split between writes
|
||||
// may start with it. Use [osc52Bridge.Flush] to emit anything that is still
|
||||
// held back once the stream ends.
|
||||
func osc52PrefixLen(b []byte) int {
|
||||
longest := 0
|
||||
for _, prefix := range []string{"\x1b", "\x1b]", "\x1b]5", "\x1b]52", "\x9d", "\x9d5", "\x9d52"} {
|
||||
if len(prefix) > longest && bytes.HasSuffix(b, []byte(prefix)) {
|
||||
longest = len(prefix)
|
||||
}
|
||||
}
|
||||
return longest
|
||||
}
|
||||
|
||||
// Flush writes any bytes held back while waiting for a sequence to complete.
|
||||
// It should be called once no more output is expected.
|
||||
func (b *osc52Bridge) Flush() error {
|
||||
if len(b.pending) == 0 {
|
||||
return nil
|
||||
}
|
||||
pending := b.pending
|
||||
b.pending = nil
|
||||
if _, err := b.w.Write(pending); err != nil {
|
||||
return fmt.Errorf("bubbletea: writing bridged output: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseOSC52 parses an OSC52 sequence at the start of b, which must begin with
|
||||
// an OSC52 introducer. It returns the length of the sequence, the selection,
|
||||
// the still-encoded payload, the terminator byte, and whether the sequence is
|
||||
// complete.
|
||||
func parseOSC52(b []byte) (n int, selection byte, payload []byte, terminator byte, status osc52Parse) {
|
||||
bodyStart := 1
|
||||
if b[0] == oscByte {
|
||||
bodyStart = 2
|
||||
}
|
||||
body := b[bodyStart:]
|
||||
|
||||
end, termLen, found := findOSCTerminator(body)
|
||||
if !found {
|
||||
return 0, 0, nil, 0, osc52NeedMore
|
||||
}
|
||||
|
||||
n = bodyStart + end + termLen
|
||||
terminator = body[end]
|
||||
if terminator == canByte || terminator == subByte {
|
||||
// The sequence was cancelled by its writer; leave it alone.
|
||||
return n, 0, nil, terminator, osc52Pass
|
||||
}
|
||||
if end < len(osc52Prefix) || !bytes.HasPrefix(body[:end], []byte(osc52Prefix)) {
|
||||
return n, 0, nil, terminator, osc52Pass
|
||||
}
|
||||
|
||||
rest := body[len(osc52Prefix):end]
|
||||
semi := bytes.IndexByte(rest, ';')
|
||||
if semi < 1 {
|
||||
// Missing a selection or a payload separator.
|
||||
return n, 0, nil, terminator, osc52Pass
|
||||
}
|
||||
return n, rest[0], rest[semi+1:], terminator, osc52Handle
|
||||
}
|
||||
|
||||
// findOSCTerminator scans body for the terminator of an OSC string. It returns
|
||||
// the length of the string data preceding the terminator, the length of the
|
||||
// terminator itself, and whether one was found.
|
||||
func findOSCTerminator(body []byte) (end, termLen int, found bool) {
|
||||
for i := 0; i < len(body); i++ {
|
||||
switch body[i] {
|
||||
case belByte, stByte, canByte, subByte:
|
||||
return i, 1, true
|
||||
case oscByte:
|
||||
if i+1 < len(body) && body[i+1] == '\\' {
|
||||
return i, 2, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
// encodeOSC52 builds an OSC52 sequence carrying content for the given
|
||||
// selection, terminated the same way the request was.
|
||||
func encodeOSC52(selection byte, content string, terminator byte) []byte {
|
||||
seq := make([]byte, 0, len(content)+len(osc52Prefix)+8)
|
||||
seq = append(seq, oscByte, ']')
|
||||
seq = append(seq, osc52Prefix...)
|
||||
seq = append(seq, selection, ';')
|
||||
seq = base64.StdEncoding.AppendEncode(seq, []byte(content))
|
||||
switch terminator {
|
||||
case oscByte:
|
||||
seq = append(seq, oscByte, '\\')
|
||||
case stByte:
|
||||
seq = append(seq, stByte)
|
||||
default:
|
||||
seq = append(seq, belByte)
|
||||
}
|
||||
return seq
|
||||
}
|
||||
331
osc52_scan_test.go
Normal file
331
osc52_scan_test.go
Normal file
|
|
@ -0,0 +1,331 @@
|
|||
package tea
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
uv "github.com/charmbracelet/ultraviolet"
|
||||
)
|
||||
|
||||
func TestSupportsOSC52(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
environ uv.Environ
|
||||
want bool
|
||||
}{
|
||||
{"default", uv.Environ{"TERM=xterm-256color"}, true},
|
||||
{"apple terminal", uv.Environ{"TERM_PROGRAM=Apple_Terminal"}, false},
|
||||
{"apple terminal case", uv.Environ{"TERM_PROGRAM=APPLE_TERMINAL"}, false},
|
||||
{"iterm", uv.Environ{"TERM_PROGRAM=iTerm.app"}, true},
|
||||
{"wezterm", uv.Environ{"TERM_PROGRAM=WezTerm"}, true},
|
||||
{"tmux", uv.Environ{"TERM_PROGRAM=tmux"}, true},
|
||||
{"windows terminal", uv.Environ{"WT_SESSION=abc", "TERM=xterm-256color"}, true},
|
||||
{"ssh tty", uv.Environ{"TERM_PROGRAM=Apple_Terminal", "SSH_TTY=/dev/ttys001"}, true},
|
||||
{"ssh connection", uv.Environ{"TERM_PROGRAM=Apple_Terminal", "SSH_CONNECTION=1.2.3.4 5 6.7.8.9 7"}, true},
|
||||
{"linux console", uv.Environ{"TERM=linux"}, false},
|
||||
{"dumb terminal", uv.Environ{"TERM=dumb"}, false},
|
||||
{"old vte", uv.Environ{"VTE_VERSION=7000"}, false},
|
||||
{"new vte", uv.Environ{"VTE_VERSION=7600"}, true},
|
||||
{"invalid vte", uv.Environ{"VTE_VERSION=unknown"}, false},
|
||||
{"old konsole", uv.Environ{"KONSOLE_VERSION=220000"}, false},
|
||||
{"new konsole", uv.Environ{"KONSOLE_VERSION=230400"}, true},
|
||||
{"invalid konsole", uv.Environ{"KONSOLE_VERSION=x"}, false},
|
||||
{"ssh overrides vte", uv.Environ{"VTE_VERSION=7000", "SSH_TTY=/dev/pts/0"}, true},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := supportsOSC52(test.environ); got != test.want {
|
||||
t.Errorf("supportsOSC52(%v) = %v, want %v", test.environ, got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeSet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
wantOutput string
|
||||
wantSelection byte
|
||||
wantContent string
|
||||
}{
|
||||
{
|
||||
name: "bel terminated",
|
||||
input: "\x1b]52;c;aGVsbG8=\x07",
|
||||
wantOutput: "",
|
||||
wantSelection: uv.SystemClipboard,
|
||||
wantContent: "hello",
|
||||
},
|
||||
{
|
||||
name: "st terminated",
|
||||
input: "\x1b]52;c;aGVsbG8=\x1b\\",
|
||||
wantOutput: "",
|
||||
wantSelection: uv.SystemClipboard,
|
||||
wantContent: "hello",
|
||||
},
|
||||
{
|
||||
name: "8-bit introducer and terminator",
|
||||
input: "\x9d52;c;aGVsbG8=\x9c",
|
||||
wantOutput: "",
|
||||
wantSelection: uv.SystemClipboard,
|
||||
wantContent: "hello",
|
||||
},
|
||||
{
|
||||
name: "surrounding output",
|
||||
input: "before\x1b]52;c;aGVsbG8=\x07after",
|
||||
wantOutput: "beforeafter",
|
||||
wantSelection: uv.SystemClipboard,
|
||||
wantContent: "hello",
|
||||
},
|
||||
{
|
||||
name: "primary selection",
|
||||
input: "\x1b]52;p;aGVsbG8=\x07",
|
||||
wantOutput: "",
|
||||
wantSelection: uv.PrimaryClipboard,
|
||||
wantContent: "hello",
|
||||
},
|
||||
{
|
||||
name: "empty payload",
|
||||
input: "\x1b]52;c;\x07",
|
||||
wantOutput: "",
|
||||
wantSelection: uv.SystemClipboard,
|
||||
wantContent: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
backend := &stubClipboardBackend{}
|
||||
output, _ := runOSC52Bridge(t, backend, test.input)
|
||||
|
||||
if output != test.wantOutput {
|
||||
t.Errorf("output = %q, want %q", output, test.wantOutput)
|
||||
}
|
||||
calls := backend.setCallsFor()
|
||||
if len(calls) != 1 {
|
||||
t.Fatalf("backend set calls = %d, want 1", len(calls))
|
||||
}
|
||||
if calls[0].selection != test.wantSelection {
|
||||
t.Errorf("selection = %q, want %q", calls[0].selection, test.wantSelection)
|
||||
}
|
||||
if calls[0].content != test.wantContent {
|
||||
t.Errorf("content = %q, want %q", calls[0].content, test.wantContent)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgePassThrough(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
}{
|
||||
{"plain text", "hello, world"},
|
||||
{"osc title", "\x1b]0;a title\x07"},
|
||||
{"osc hyperlink", "\x1b]8;;https://example.com\x07link\x1b]8;;\x07"},
|
||||
{"malformed payload", "\x1b]52;c;!!!not-base64!!!\x07"},
|
||||
{"missing selection", "\x1b]52;;aGVsbG8=\x07"},
|
||||
{"cancelled sequence", "\x1b]52;c;aGVsbG8=\x18"},
|
||||
{"substituted sequence", "\x1b]52;c;aGVsbG8=\x1a"},
|
||||
{"other command", "\x1b]10;rgb:ffff/ffff/ffff\x07"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
backend := &stubClipboardBackend{}
|
||||
output, _ := runOSC52Bridge(t, backend, test.input)
|
||||
|
||||
if output != test.input {
|
||||
t.Errorf("output = %q, want %q", output, test.input)
|
||||
}
|
||||
if calls := backend.setCallsFor(); len(calls) != 0 {
|
||||
t.Errorf("backend set calls = %d, want 0", len(calls))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeRead(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "bel terminated",
|
||||
input: "before\x1b]52;c;?\x07after",
|
||||
want: "beforeafter",
|
||||
},
|
||||
{
|
||||
name: "st terminated",
|
||||
input: "\x1b]52;c;?\x1b\\",
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
backend := &stubClipboardBackend{
|
||||
getValues: map[byte]string{uv.SystemClipboard: "hello"},
|
||||
}
|
||||
output, reply := runOSC52Bridge(t, backend, test.input)
|
||||
|
||||
if output != test.want {
|
||||
t.Errorf("output = %q, want %q", output, test.want)
|
||||
}
|
||||
wantReply := "\x1b]52;c;aGVsbG8=\x07"
|
||||
if strings.Contains(test.input, "\x1b\\") {
|
||||
wantReply = "\x1b]52;c;aGVsbG8=\x1b\\"
|
||||
}
|
||||
if reply != wantReply {
|
||||
t.Errorf("reply = %q, want %q", reply, wantReply)
|
||||
}
|
||||
if got := backend.getCallsFor(); len(got) != 1 || got[0] != uv.SystemClipboard {
|
||||
t.Errorf("backend get calls = %v, want [%q]", got, uv.SystemClipboard)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeSplit(t *testing.T) {
|
||||
seq := "\x1b]52;c;aGVsbG8=\x07"
|
||||
|
||||
for i := 1; i < len(seq); i++ {
|
||||
backend := &stubClipboardBackend{}
|
||||
output, _ := runOSC52Bridge(t, backend, seq[:i], seq[i:])
|
||||
|
||||
if output != "" {
|
||||
t.Errorf("split at %d: output = %q, want empty", i, output)
|
||||
}
|
||||
if calls := backend.setCallsFor(); len(calls) != 1 || calls[0].content != "hello" {
|
||||
t.Errorf("split at %d: set calls = %v, want one call with %q", i, calls, "hello")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeByteByByte(t *testing.T) {
|
||||
seq := "prefix\x1b]52;c;aGVsbG8=\x07suffix"
|
||||
chunks := make([]string, 0, len(seq))
|
||||
for _, r := range seq {
|
||||
chunks = append(chunks, string(r))
|
||||
}
|
||||
|
||||
backend := &stubClipboardBackend{}
|
||||
output, _ := runOSC52Bridge(t, backend, chunks...)
|
||||
|
||||
if output != "prefixsuffix" {
|
||||
t.Errorf("output = %q, want %q", output, "prefixsuffix")
|
||||
}
|
||||
if calls := backend.setCallsFor(); len(calls) != 1 || calls[0].content != "hello" {
|
||||
t.Errorf("set calls = %v, want one call with %q", calls, "hello")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeHoldsPartialPrefix(t *testing.T) {
|
||||
var output, reply bytes.Buffer
|
||||
bridge := newOSC52Bridge(&stubClipboardBackend{}, &output, &reply)
|
||||
|
||||
if _, err := bridge.Write([]byte("text\x1b]")); err != nil {
|
||||
t.Fatalf("write: %v", err)
|
||||
}
|
||||
if got := output.String(); got != "text" {
|
||||
t.Errorf("output = %q, want %q (partial introducer should be held back)", got, "text")
|
||||
}
|
||||
|
||||
backend := &stubClipboardBackend{}
|
||||
bridge.backend = backend
|
||||
if _, err := bridge.Write([]byte("52;c;aGVsbG8=\x07")); err != nil {
|
||||
t.Fatalf("write: %v", err)
|
||||
}
|
||||
if got := output.String(); got != "text" {
|
||||
t.Errorf("output = %q, want %q", got, "text")
|
||||
}
|
||||
if calls := backend.setCallsFor(); len(calls) != 1 || calls[0].content != "hello" {
|
||||
t.Errorf("set calls = %v, want one call with %q", calls, "hello")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeOversizedSequence(t *testing.T) {
|
||||
backend := &stubClipboardBackend{}
|
||||
huge := "\x1b]52;c;" + strings.Repeat("A", osc52MaxPending+1)
|
||||
|
||||
output, _ := runOSC52Bridge(t, backend, huge)
|
||||
|
||||
if !strings.HasPrefix(output, "\x1b]52;c;") {
|
||||
t.Errorf("oversized sequence should be forwarded untouched, got %q", output[:min(len(output), 32)])
|
||||
}
|
||||
if len(output) != len(huge) {
|
||||
t.Errorf("output length = %d, want %d", len(output), len(huge))
|
||||
}
|
||||
if calls := backend.setCallsFor(); len(calls) != 0 {
|
||||
t.Errorf("backend set calls = %d, want 0", len(calls))
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeFlush(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var output, reply bytes.Buffer
|
||||
bridge := newOSC52Bridge(&stubClipboardBackend{}, &output, &reply)
|
||||
|
||||
// A trailing ESC that never became a sequence is held back...
|
||||
if _, err := bridge.Write([]byte("text\x1b")); err != nil {
|
||||
t.Fatalf("write: %v", err)
|
||||
}
|
||||
if got := output.String(); got != "text" {
|
||||
t.Errorf("output before flush = %q, want %q", got, "text")
|
||||
}
|
||||
|
||||
// ...and is written once the stream has ended.
|
||||
if err := bridge.Flush(); err != nil {
|
||||
t.Fatalf("flush: %v", err)
|
||||
}
|
||||
if got := output.String(); got != "text\x1b" {
|
||||
t.Errorf("output after flush = %q, want %q", got, "text\x1b")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSC52BridgeBackendErrorsFailOpen(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("set error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
backend := &stubClipboardBackend{setErr: ErrClipboardUnavailable}
|
||||
input := "\x1b]52;c;aGVsbG8=\x07"
|
||||
output, _ := runOSC52Bridge(t, backend, input)
|
||||
if output != input {
|
||||
t.Errorf("output = %q, want %q", output, input)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("get error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
backend := &stubClipboardBackend{getErr: ErrClipboardUnavailable}
|
||||
input := "\x1b]52;c;?\x07"
|
||||
output, _ := runOSC52Bridge(t, backend, input)
|
||||
if output != input {
|
||||
t.Errorf("output = %q, want %q", output, input)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// runOSC52Bridge runs the bridge over the given chunks and returns everything
|
||||
// written to the output and reply writers.
|
||||
func runOSC52Bridge(t *testing.T, backend ClipboardBackend, chunks ...string) (string, string) {
|
||||
t.Helper()
|
||||
|
||||
var output, reply bytes.Buffer
|
||||
bridge := newOSC52Bridge(backend, &output, &reply)
|
||||
for _, chunk := range chunks {
|
||||
if _, err := bridge.Write([]byte(chunk)); err != nil {
|
||||
t.Fatalf("write %q: %v", chunk, err)
|
||||
}
|
||||
}
|
||||
return output.String(), reply.String()
|
||||
}
|
||||
27
tea.go
27
tea.go
|
|
@ -493,6 +493,19 @@ type Program struct {
|
|||
// UI but still want to take advantage of Bubble Tea's architecture.
|
||||
disableRenderer bool
|
||||
|
||||
// clipboard is the backend used to bridge clipboard operations when the
|
||||
// terminal does not support OSC52. When nil, clipboard operations are
|
||||
// written to the terminal as OSC52 sequences.
|
||||
clipboard ClipboardBackend
|
||||
|
||||
// clipboardBackendSet reports whether a clipboard backend was provided
|
||||
// explicitly with WithClipboardBackend.
|
||||
clipboardBackendSet bool
|
||||
|
||||
// disableClipboardFallback disables the operating system clipboard
|
||||
// fallback used on terminals without OSC52 support.
|
||||
disableClipboardFallback bool
|
||||
|
||||
// handlers is a list of channels that need to be waited on before the
|
||||
// program can exit.
|
||||
handlers channelHandlers
|
||||
|
|
@ -631,6 +644,12 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
|
|||
p.environ = os.Environ()
|
||||
}
|
||||
|
||||
// Fall back to the operating system clipboard on terminals that do not
|
||||
// support OSC52, such as Apple's Terminal.app.
|
||||
if !p.clipboardBackendSet && !p.disableClipboardFallback && !supportsOSC52(p.environ) {
|
||||
p.clipboard = newLocalClipboardBackend(p.environ)
|
||||
}
|
||||
|
||||
if p.fps < 1 {
|
||||
p.fps = defaultFPS
|
||||
} else if p.fps > maxFPS {
|
||||
|
|
@ -816,16 +835,16 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
|
|||
}
|
||||
|
||||
case readClipboardMsg:
|
||||
p.execute(ansi.RequestSystemClipboard)
|
||||
p.handleReadClipboard(uv.SystemClipboard)
|
||||
|
||||
case setClipboardMsg:
|
||||
p.execute(ansi.SetSystemClipboard(string(msg)))
|
||||
p.handleSetClipboard(uv.SystemClipboard, string(msg))
|
||||
|
||||
case readPrimaryClipboardMsg:
|
||||
p.execute(ansi.RequestPrimaryClipboard)
|
||||
p.handleReadClipboard(uv.PrimaryClipboard)
|
||||
|
||||
case setPrimaryClipboardMsg:
|
||||
p.execute(ansi.SetPrimaryClipboard(string(msg)))
|
||||
p.handleSetClipboard(uv.PrimaryClipboard, string(msg))
|
||||
|
||||
case backgroundColorMsg:
|
||||
p.execute(ansi.RequestBackgroundColor)
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
module tutorial
|
||||
|
||||
go 1.24.2
|
||||
|
||||
toolchain go1.24.10
|
||||
go 1.26.0
|
||||
|
||||
require charm.land/bubbletea/v2 v2.0.0-00010101000000-000000000000
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/colorprofile v0.4.1 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.6 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.4.3 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.7 // indirect
|
||||
github.com/charmbracelet/x/conpty v0.2.0 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.9.0 // indirect
|
||||
github.com/clipperhouse/stringish v0.1.1 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.19 // indirect
|
||||
github.com/charmbracelet/x/xpty v0.1.4 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/creack/pty v1.1.24 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.4.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.23 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
golang.org/x/sync v0.21.0 // indirect
|
||||
golang.org/x/sys v0.47.0 // indirect
|
||||
)
|
||||
|
||||
replace charm.land/bubbletea/v2 => ../
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
|
||||
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
|
||||
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 h1:eyFRbAmexyt43hVfeyBofiGSEmJ7krjLOYt/9CF5NKA=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8/go.mod h1:SQpCTRNBtzJkwku5ye4S3HEuthAlGy2n9VXZnWkEW98=
|
||||
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
|
||||
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
|
||||
github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
|
||||
github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 h1:3FmWoGNWK4STvqg0O0Aeav2T7rodWJAPeF0QpH+8gFw=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7/go.mod h1:f/jRa757WUmaOZrbPspXymbg/GnbF+rwe4OLsG7aXYo=
|
||||
github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI=
|
||||
github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ=
|
||||
github.com/charmbracelet/x/conpty v0.2.0 h1:eKtA2hm34qNfgJCDp/M6Dc0gLy7e07YEK4qAdNGOvVY=
|
||||
github.com/charmbracelet/x/conpty v0.2.0/go.mod h1:fexgUnVrZgw8scD49f6VSi0Ggj9GWYIrpedRthAwW/8=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f h1:UytXHv0UxnsDFmL/7Z9Q5SBYPwSuRLXHbwx+6LycZ2w=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||
|
|
@ -14,16 +16,18 @@ github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8
|
|||
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
|
||||
github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
|
||||
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
|
||||
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
|
||||
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||
github.com/charmbracelet/x/xpty v0.1.4 h1:4jaW7u+8AHQMxesiVc+zUMsspu7GyDwtJO+gy/tFtW4=
|
||||
github.com/charmbracelet/x/xpty v0.1.4/go.mod h1:7t8P7BpPiolHJ1pLzz7/4ujDbD+sUxI9yA3CBOLOIcU=
|
||||
github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
|
||||
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
|
||||
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW4TvVgFr4=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw=
|
||||
github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
|
|
@ -32,7 +36,7 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
|
|||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
||||
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
|
|
|
|||
Loading…
Reference in a new issue