Add $EDITOR, internal config for compose
This commit is contained in:
parent
9b2612eaf2
commit
065da5e372
4 changed files with 30 additions and 6 deletions
|
@ -18,7 +18,7 @@ func Compose(aerc *widgets.Aerc, args []string) error {
|
||||||
return errors.New("Usage: compose")
|
return errors.New("Usage: compose")
|
||||||
}
|
}
|
||||||
acct := aerc.SelectedAccount()
|
acct := aerc.SelectedAccount()
|
||||||
composer := widgets.NewComposer(acct.AccountConfig())
|
composer := widgets.NewComposer(aerc.Config(), acct.AccountConfig())
|
||||||
// TODO: Change tab name when message subject changes
|
// TODO: Change tab name when message subject changes
|
||||||
aerc.NewTab(composer, runewidth.Truncate(
|
aerc.NewTab(composer, runewidth.Truncate(
|
||||||
"New email", 32, "…"))
|
"New email", 32, "…"))
|
||||||
|
|
|
@ -57,6 +57,13 @@ pager=less -R
|
||||||
# Default: text/plain,text/html
|
# Default: text/plain,text/html
|
||||||
alternatives=text/plain,text/html
|
alternatives=text/plain,text/html
|
||||||
|
|
||||||
|
[compose]
|
||||||
|
#
|
||||||
|
# Specifies the command to run the editor with. It will be shown in an embedded
|
||||||
|
# terminal, though it may also launch a graphical window if the environment
|
||||||
|
# supports it. Defaults to $EDITOR, or vi.
|
||||||
|
editor=
|
||||||
|
|
||||||
[filters]
|
[filters]
|
||||||
#
|
#
|
||||||
# Filters allow you to pipe an email body through a shell command to render
|
# Filters allow you to pipe an email body through a shell command to render
|
||||||
|
|
|
@ -48,6 +48,10 @@ type BindingConfig struct {
|
||||||
Terminal *KeyBindings
|
Terminal *KeyBindings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ComposeConfig struct {
|
||||||
|
Editor string `ini:"editor"`
|
||||||
|
}
|
||||||
|
|
||||||
type FilterConfig struct {
|
type FilterConfig struct {
|
||||||
FilterType int
|
FilterType int
|
||||||
Filter string
|
Filter string
|
||||||
|
@ -63,6 +67,7 @@ type ViewerConfig struct {
|
||||||
|
|
||||||
type AercConfig struct {
|
type AercConfig struct {
|
||||||
Bindings BindingConfig
|
Bindings BindingConfig
|
||||||
|
Compose ComposeConfig
|
||||||
Ini *ini.File `ini:"-"`
|
Ini *ini.File `ini:"-"`
|
||||||
Accounts []AccountConfig `ini:"-"`
|
Accounts []AccountConfig `ini:"-"`
|
||||||
Filters []FilterConfig `ini:"-"`
|
Filters []FilterConfig `ini:"-"`
|
||||||
|
@ -206,6 +211,11 @@ func LoadConfig(root *string) (*AercConfig, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if compose, err := file.GetSection("compose"); err == nil {
|
||||||
|
if err := compose.MapTo(&config.Compose); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
if ui, err := file.GetSection("ui"); err == nil {
|
if ui, err := file.GetSection("ui"); err == nil {
|
||||||
if err := ui.MapTo(&config.Ui); err != nil {
|
if err := ui.MapTo(&config.Ui); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -36,7 +36,8 @@ type Composer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Let caller configure headers, initial body (for replies), etc
|
// TODO: Let caller configure headers, initial body (for replies), etc
|
||||||
func NewComposer(conf *config.AccountConfig) *Composer {
|
func NewComposer(conf *config.AercConfig,
|
||||||
|
acct *config.AccountConfig) *Composer {
|
||||||
grid := ui.NewGrid().Rows([]ui.GridSpec{
|
grid := ui.NewGrid().Rows([]ui.GridSpec{
|
||||||
{ui.SIZE_EXACT, 3},
|
{ui.SIZE_EXACT, 3},
|
||||||
{ui.SIZE_WEIGHT, 1},
|
{ui.SIZE_WEIGHT, 1},
|
||||||
|
@ -55,7 +56,7 @@ func NewComposer(conf *config.AccountConfig) *Composer {
|
||||||
})
|
})
|
||||||
|
|
||||||
to := newHeaderEditor("To", "")
|
to := newHeaderEditor("To", "")
|
||||||
from := newHeaderEditor("From", conf.From)
|
from := newHeaderEditor("From", acct.From)
|
||||||
subject := newHeaderEditor("Subject", "")
|
subject := newHeaderEditor("Subject", "")
|
||||||
headers.AddChild(to).At(0, 0)
|
headers.AddChild(to).At(0, 0)
|
||||||
headers.AddChild(from).At(0, 1)
|
headers.AddChild(from).At(0, 1)
|
||||||
|
@ -68,15 +69,21 @@ func NewComposer(conf *config.AccountConfig) *Composer {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: built-in config option, $EDITOR, then vi, in that order
|
editorName := conf.Compose.Editor
|
||||||
editor := exec.Command("vim", email.Name())
|
if editorName == "" {
|
||||||
|
editorName = os.Getenv("EDITOR")
|
||||||
|
}
|
||||||
|
if editorName == "" {
|
||||||
|
editorName = "vi"
|
||||||
|
}
|
||||||
|
editor := exec.Command(editorName, email.Name())
|
||||||
term, _ := NewTerminal(editor)
|
term, _ := NewTerminal(editor)
|
||||||
|
|
||||||
grid.AddChild(headers).At(0, 0)
|
grid.AddChild(headers).At(0, 0)
|
||||||
grid.AddChild(term).At(1, 0)
|
grid.AddChild(term).At(1, 0)
|
||||||
|
|
||||||
c := &Composer{
|
c := &Composer{
|
||||||
config: conf,
|
config: acct,
|
||||||
editor: term,
|
editor: term,
|
||||||
email: email,
|
email: email,
|
||||||
grid: grid,
|
grid: grid,
|
||||||
|
|
Loading…
Reference in a new issue