ayn2op 3 年之前
父節點
當前提交
5fa71c2662
共有 2 個文件被更改,包括 29 次插入3 次删除
  1. 7 3
      config.go
  2. 22 0
      message_input.go

+ 7 - 3
config.go

@@ -23,6 +23,7 @@ type (
 	MessageInputKeysConfig struct {
 		CommonKeysConfig `yaml:",inline"`
 		Send             string `yaml:"send"`
+		LaunchEditor     string `yaml:"launch_editor"`
 	}
 
 	KeysConfig struct {
@@ -62,9 +63,10 @@ type (
 )
 
 type Config struct {
-	Mouse         bool `yaml:"mouse"`
-	MessagesLimit uint `yaml:"messages_limit"`
-	Timestamps    bool `yaml:"timestamps"`
+	Mouse         bool   `yaml:"mouse"`
+	MessagesLimit uint   `yaml:"messages_limit"`
+	Timestamps    bool   `yaml:"timestamps"`
+	Editor        string `yaml:"editor"`
 
 	Keys  KeysConfig  `yaml:"keys"`
 	Theme ThemeConfig `yaml:"theme"`
@@ -98,6 +100,7 @@ func newConfig() (*Config, error) {
 		Mouse:         true,
 		Timestamps:    false,
 		MessagesLimit: 50,
+		Editor:        "default",
 
 		Keys: KeysConfig{
 			MessagesText: MessagesTextKeysConfig{
@@ -108,6 +111,7 @@ func newConfig() (*Config, error) {
 			MessageInput: MessageInputKeysConfig{
 				CommonKeysConfig: commonKeys,
 				Send:             "Enter",
+				LaunchEditor:     "Ctrl+E",
 			},
 		},
 

+ 22 - 0
message_input.go

@@ -2,6 +2,8 @@ package main
 
 import (
 	"log"
+	"os"
+	"os/exec"
 	"strings"
 
 	"github.com/diamondburned/arikawa/v3/api"
@@ -44,6 +46,26 @@ func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
 	case cfg.Keys.MessageInput.Send:
 		mi.sendAction()
 		return nil
+	case cfg.Keys.MessageInput.LaunchEditor:
+		e := cfg.Editor
+		if e == "default" {
+			e = os.Getenv("EDITOR")
+		}
+
+		cmd := exec.Command(e)
+		var b strings.Builder
+		cmd.Stdout = &b
+
+		app.Suspend(func() {
+			err := cmd.Run()
+			if err != nil {
+				log.Println(err)
+				return
+			}
+		})
+
+		mi.SetText(b.String())
+		return nil
 	case cfg.Keys.MessageInput.Cancel:
 		mi.reset()
 		return nil