diff --git a/config.go b/config.go index 093485d..cfb19d3 100644 --- a/config.go +++ b/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", }, }, diff --git a/message_input.go b/message_input.go index ad6b100..00d846b 100644 --- a/message_input.go +++ b/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