diff --git a/go.mod b/go.mod index 75d4a09..b8106b0 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.14 require ( github.com/alecthomas/chroma v0.7.1 + github.com/atotto/clipboard v0.1.2 github.com/disintegration/imaging v1.6.2 github.com/kyokomi/emoji v2.1.0+incompatible github.com/lithammer/fuzzysearch v1.1.0 diff --git a/go.sum b/go.sum index dfaa139..2081ea0 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/alecthomas/chroma v0.7.1/go.mod h1:gHw09mkX1Qp80JlYbmN9L3+4R5o6DJJ3GR github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= +github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY= +github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ= github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/ui/command-processor.go b/ui/command-processor.go index 10478cc..e9485c4 100644 --- a/ui/command-processor.go +++ b/ui/command-processor.go @@ -119,6 +119,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { "react": cmdReact, "download": cmdDownload, "open": cmdOpen, + "copy": cmdCopy, "sendevent": cmdSendEvent, "msendevent": cmdMSendEvent, "setstate": cmdSetState, diff --git a/ui/commands.go b/ui/commands.go index 4dd1482..27c9caf 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -34,6 +34,7 @@ import ( "github.com/lucasb-eyer/go-colorful" "github.com/russross/blackfriday/v2" + "github.com/atotto/clipboard" "maunium.net/go/mautrix" "maunium.net/go/mautrix/event" @@ -158,6 +159,7 @@ const ( SelectRedact = "redact" SelectDownload = "download" SelectOpen = "open" + SelectCopy = "copy" ) func cmdReply(cmd *Command) { @@ -176,6 +178,14 @@ func cmdOpen(cmd *Command) { cmd.Room.StartSelecting(SelectOpen, strings.Join(cmd.Args, " ")) } +func cmdCopy(cmd *Command) { + if clipboard.Unsupported { + cmd.Reply("Clipboard unsupported.") + } else { + cmd.Room.StartSelecting(SelectCopy, strings.Join(cmd.Args, " ")) + } +} + func cmdReact(cmd *Command) { if len(cmd.Args) == 0 { cmd.Reply("Usage: /react ") diff --git a/ui/room-view.go b/ui/room-view.go index 5792626..641e9d1 100644 --- a/ui/room-view.go +++ b/ui/room-view.go @@ -25,6 +25,7 @@ import ( "github.com/kyokomi/emoji" "github.com/mattn/go-runewidth" + "github.com/atotto/clipboard" "maunium.net/go/mauview" "maunium.net/go/tcell" @@ -204,6 +205,11 @@ func (view *RoomView) OnSelect(message *messages.UIMessage) { } go view.Download(msg.URL, path, view.selectReason == SelectOpen) } + case SelectCopy: + msg, ok := message.Renderer.(*messages.TextMessage) + if ok { + go clipboard.WriteAll(msg.PlainText()) + } } view.selecting = false view.selectContent = ""