Editor
This commit is contained in:
parent
a39264f048
commit
5fa71c2662
2 changed files with 29 additions and 3 deletions
10
config.go
10
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",
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue