Implement copying to clipboard
"github.com/atotto/clipboard"
This commit is contained in:
parent
96bb87e8ac
commit
0f85fcc3fa
1
go.mod
1
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
|
||||
|
2
go.sum
2
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=
|
||||
|
@ -119,6 +119,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
|
||||
"react": cmdReact,
|
||||
"download": cmdDownload,
|
||||
"open": cmdOpen,
|
||||
"copy": cmdCopy,
|
||||
"sendevent": cmdSendEvent,
|
||||
"msendevent": cmdMSendEvent,
|
||||
"setstate": cmdSetState,
|
||||
|
@ -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 <reaction>")
|
||||
|
@ -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 = ""
|
||||
|
Loading…
Reference in New Issue
Block a user