Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

### Added
- Yank, delete and put use the system clipboard, like vim's `clipboard=unnamedplus`: every write to the unnamed register also goes to the clipboard, and `p`/`P` paste what's on it, so text moves between pholio and other apps. `"+` and `"*` name the clipboard; `"a`–`"z` and `"0`–`"9` stay internal. Text copied in another app pastes as lines when it ends in a newline, else inline; pholio's own yanks keep their shape (lines or a block). pholio uses `wl-copy`/`wl-paste`, `xclip` or `xsel`, or `pbcopy`/`pbpaste`, and without them (as over SSH) writes the clipboard with OSC 52, where puts use the internal register. In a terminal multiplexer pane with no `WAYLAND_DISPLAY` or `DISPLAY` (a herdr or tmux server started outside the desktop), pholio uses the Wayland display if exactly one live `wayland-*` socket is in `$XDG_RUNTIME_DIR`.

## [0.6.1] - 2026-10-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion cmd/pholio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func run(args []string) error {
// With no file argument this opens (or creates) today's Daily Note.
deps := app.Deps{
FS: fsys, Clock: clock, Watch: vault, Opener: seam.SystemOpener{}, Index: ix,
Trash: seam.NewSystemTrash(os.Getenv, home, clock),
Trash: seam.NewSystemTrash(os.Getenv, home, clock), Clipboard: seam.NewSystemClipboard(os.Getenv),
}
m, err := app.Start(deps, s)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ github.com/arran4/golang-ical v0.3.7 h1:ONEzzLJqP9aQpXzO6ArsdRshApsWIr6hkMV28RdI
github.com/arran4/golang-ical v0.3.7/go.mod h1:OnguFgjN0Hmx8jzpmWcC+AkHio94ujmLHKoaef7xQh8=
github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o=
github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w=
github.com/bits-and-blooms/bitset v1.24.6/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
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-20260811164956-006e29f97886 h1:rdnVWKgJpTVXKuKuJyxDJ+NFJdUaUqGvyGy61OcvlbA=
Expand All @@ -36,6 +37,7 @@ github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
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/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -48,12 +50,14 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss=
github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.24 h1:cpokDiIn0MGnhdHwuWnJBITySJ20QyNGnY2kR/ay2DU=
github.com/mattn/go-runewidth v0.0.24/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/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
Expand All @@ -72,5 +76,7 @@ golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
14 changes: 13 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Deps struct {
Index *index.Index
// Trash takes deleted Notes and folders (d in the tree, :delete).
Trash seam.Trash
// Clipboard, if set, is the system clipboard that yank and put use.
// When writing to it fails, the text is sent with OSC 52 instead.
Clipboard seam.Clipboard
}

// focus is the pane that receives keys.
Expand All @@ -45,6 +48,7 @@ const (
// message lines, and at most one prompt or palette on top.
type Model struct {
deps Deps
clip *clipboard // nil without Deps.Clipboard
vault string
file *noteFile // the open Note's file; shared by copies, like the engine
ed editor.Model
Expand Down Expand Up @@ -99,6 +103,9 @@ func New(deps Deps, path string) (Model, error) {
exq: &exQueue{}, appearance: defaultAppearance(),
feeds: &feeds{byURL: map[string]*feed{}},
}
if deps.Clipboard != nil {
m.clip = &clipboard{sys: deps.Clipboard}
}
file, e, err := m.openEngine(path)
if err != nil {
return Model{}, err
Expand All @@ -121,6 +128,9 @@ func (m Model) openEngine(path string) (*noteFile, *engine.Engine, error) {
}
file.e = e
e.Msg = "" // the message line is the app's
if m.clip != nil {
e.Clipboard = m.clip
}
m.registerEx(e)
return file, e, nil
}
Expand Down Expand Up @@ -306,9 +316,11 @@ func (m Model) editorKey(msg tea.KeyPressMsg) (Model, tea.Cmd) {
m.quitAfterWrite = true
}
m, cmd := m.drainEx()
cmd = tea.Batch(cmd, m.clip.osc52())
if e.Quit { // :wq and :x, once written
e.Quit = false
return m.requestQuit()
m, quit := m.requestQuit()
return m, tea.Batch(cmd, quit)
}
return m, cmd
}
Expand Down
37 changes: 37 additions & 0 deletions internal/app/clipboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app

import (
tea "charm.land/bubbletea/v2"

"github.com/tedkulp/pholio/internal/seam"
)

// clipboard is the engines' clipboard: the system one, with OSC 52 for
// writes it can't take (no clipboard tool, as over SSH). OSC 52 can't be
// read back reliably, so reads still go to the system clipboard, and on
// failure the engine uses its own register. It is shared by Model copies.
type clipboard struct {
sys seam.Clipboard
pending *string // text waiting to go out as OSC 52
}

func (c *clipboard) Read() (string, error) { return c.sys.Read() }

func (c *clipboard) Write(text string) error {
err := c.sys.Write(text)
if err != nil {
c.pending = &text
}
return err
}

// osc52 takes the text waiting for OSC 52 and returns the command that
// sends it, or nil.
func (c *clipboard) osc52() tea.Cmd {
if c == nil || c.pending == nil {
return nil
}
text := *c.pending
c.pending = nil
return tea.SetClipboard(text)
}
76 changes: 76 additions & 0 deletions internal/app/clipboard_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package app_test

import (
"reflect"
"testing"

tea "charm.land/bubbletea/v2"

"github.com/tedkulp/pholio/internal/app"
"github.com/tedkulp/pholio/internal/seam"
"github.com/tedkulp/pholio/internal/seam/seamtest"
)

func clipApp(t *testing.T, cb *seamtest.Clipboard) app.Model {
t.Helper()
fsys := seamtest.NewMemFS(map[string]string{"/vault/a.md": "hello\n", "/vault/b.md": "bye\n"})
m, err := app.New(app.Deps{FS: fsys, Clipboard: cb}, "/vault/a.md")
if err != nil {
t.Fatal(err)
}
return resize(m, 80, 12)
}

func setsClipboard(cmd tea.Cmd, text string) bool {
want := tea.SetClipboard(text)()
for _, msg := range msgsOf(cmd) {
if reflect.DeepEqual(msg, want) {
return true
}
}
return false
}

func TestYankAndPutUseTheClipboard(t *testing.T) {
cb := &seamtest.Clipboard{}
m := clipApp(t, cb)
m, cmd := pressing(typeKeys(m, "y"), tea.KeyPressMsg{Code: 'y', Text: "y"})
if w := cb.Writes(); len(w) != 1 || w[0] != "hello\n" {
t.Errorf("writes = %q", w)
}
if setsClipboard(cmd, "hello\n") {
t.Error("OSC 52 sent although the clipboard tool worked")
}
cb.Set("X")
if m = typeKeys(m, "P"); m.Text() != "Xhello\n" {
t.Errorf("text = %q", m.Text())
}
}

func TestOpenedNoteUsesTheClipboard(t *testing.T) {
cb := &seamtest.Clipboard{}
m := clipApp(t, cb)
m = typeKeys(m, ":e /vault/b.md")
m = press(m, enter)
cb.Set("X")
if m = typeKeys(m, "P"); m.Text() != "Xbye\n" {
t.Errorf("text = %q", m.Text())
}
}

func TestNoClipboardToolFallsBackToOSC52(t *testing.T) {
cb := &seamtest.Clipboard{WriteErr: seam.ErrNoClipboard, ReadErr: seam.ErrNoClipboard}
m := clipApp(t, cb)
m, cmd := pressing(typeKeys(m, "y"), tea.KeyPressMsg{Code: 'y', Text: "y"})
if !setsClipboard(cmd, "hello\n") {
t.Errorf("no OSC 52 write in %#v", msgsOf(cmd))
}
// A put uses the register; the message line stays empty.
m, cmd = pressing(m, tea.KeyPressMsg{Code: 'p', Text: "p"})
if m.Text() != "hello\nhello\n" {
t.Errorf("text = %q", m.Text())
}
if setsClipboard(cmd, "hello\n") {
t.Error("OSC 52 sent again by a put")
}
}
41 changes: 41 additions & 0 deletions internal/engine/clipboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package engine

import "strings"

// Clipboard is the system clipboard. It is a seam.Clipboard, so the app
// passes its own.
type Clipboard interface {
Read() (string, error)
Write(text string) error
}

// isClipboardReg reports whether reg is one of the registers that are the
// clipboard: unnamed, "+ and "*.
func isClipboardReg(reg rune) bool { return reg == '"' || reg == '+' || reg == '*' }

// toClipboard writes r to the clipboard. A failed write is not reported:
// the registers still hold the text, and puts use them until a write
// succeeds, since the clipboard then holds something older.
func (e *Engine) toClipboard(r register) {
if e.Clipboard != nil {
e.clipStale = e.Clipboard.Write(r.text) != nil
}
}

// fromClipboard is the register a put from the clipboard uses. Text that
// matches the unnamed register is pholio's own, so the register is used
// and keeps its shape (lines or a block). Other text is pasted as lines
// when it ends in a newline, else inline. Without a readable, non-empty,
// up-to-date clipboard it falls back to the unnamed register.
func (e *Engine) fromClipboard() (register, bool) {
r, ok := e.regs['"']
if e.Clipboard == nil || e.clipStale {
return r, ok
}
text, err := e.Clipboard.Read()
if err != nil || text == "" || (ok && text == r.text) {
return r, ok
}
text = strings.ReplaceAll(text, "\r\n", "\n")
return register{text: text, linewise: strings.HasSuffix(text, "\n")}, true
}
Loading
Loading