aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorJulian Weigt <julian.weigt@gmail.com>2020-04-26 20:02:35 +0300
committerJulian Weigt <julian.weigt@gmail.com>2020-04-26 20:02:35 +0300
commit0f85fcc3fac833b1635af111e1a7024254fcf3c6 (patch)
treeec8018ac0e992fae4c882c196b91f9907aad5198 /ui
parent96bb87e8ac8f45d56d487ea6c16d67f057d97e1f (diff)
Implement copying to clipboard
"github.com/atotto/clipboard"
Diffstat (limited to 'ui')
-rw-r--r--ui/command-processor.go1
-rw-r--r--ui/commands.go10
-rw-r--r--ui/room-view.go6
3 files changed, 17 insertions, 0 deletions
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 <reaction>")
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 = ""