File: edit.go

package info (click to toggle)
aerc 0.20.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,164 kB
  • sloc: ansic: 1,148; python: 1,000; sh: 553; awk: 330; makefile: 23
file content (46 lines) | stat: -rw-r--r-- 940 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package compose

import (
	"errors"

	"git.sr.ht/~rjarry/aerc/app"
	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/config"
)

type Edit struct {
	Edit   bool `opt:"-e" desc:"Force [compose].edit-headers = true."`
	NoEdit bool `opt:"-E" desc:"Force [compose].edit-headers = false."`
}

func init() {
	commands.Register(Edit{})
}

func (Edit) Description() string {
	return "(Re-)open text editor to edit the message in progress."
}

func (Edit) Context() commands.CommandContext {
	return commands.COMPOSE_REVIEW
}

func (Edit) Aliases() []string {
	return []string{"edit"}
}

func (e Edit) Execute(args []string) error {
	composer, ok := app.SelectedTabContent().(*app.Composer)
	if !ok {
		return errors.New("only valid while composing")
	}

	editHeaders := (config.Compose.EditHeaders || e.Edit) && !e.NoEdit

	err := composer.ShowTerminal(editHeaders)
	if err != nil {
		return err
	}
	composer.FocusTerminal()
	return nil
}