add: clipboard functionality in room view

CTRL+V now checks if the clipboard contains an image and pastes it into the room.

The library used for clipboard functionality requires an additional
dependency:

> Linux: require X11 dev package. For instance, install libx11-dev or xorg-dev or libX11-devel to access X window system.
This commit is contained in:
i401
2023-10-05 22:33:21 +02:00
parent 09a9279558
commit 8472803cd0
6 changed files with 103 additions and 36 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/kyokomi/emoji/v2"
"github.com/mattn/go-runewidth"
"github.com/zyedidia/clipboard"
pasteclip "golang.design/x/clipboard"
"go.mau.fi/mauview"
"go.mau.fi/tcell"
@ -376,7 +377,14 @@ func (view *RoomView) OnKeyEvent(event mauview.KeyEvent) bool {
case "send":
view.InputSubmit(view.input.GetText())
return true
case "paste":
cb := pasteclip.Read(pasteclip.FmtImage)
if cb != nil {
view.SendMessageMedia(string(cb))
}
return true
}
return view.input.OnKeyEvent(event)
}