about summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-13 16:04:01 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-13 16:04:01 -0400
commit17bd2dc4dbb3b43b1917c942100834c1341f2194 (patch)
tree59b3c0cc12eb387975451fc6dd5d24d60cc9154a /widgets
parentbda74452a81963d20c099a1252caadde7049de10 (diff)
downloadaerc-17bd2dc4dbb3b43b1917c942100834c1341f2194.tar.gz
Populate "From" header from config for new emails
Diffstat (limited to 'widgets')
-rw-r--r--widgets/account.go4
-rw-r--r--widgets/compose.go32
2 files changed, 24 insertions, 12 deletions
diff --git a/widgets/account.go b/widgets/account.go
index a8cd9ad..c01b15f 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -80,6 +80,10 @@ func NewAccountView(conf *config.AercConfig, acct *config.AccountConfig,
 	return view
 }
 
+func (acct *AccountView) AccountConfig() *config.AccountConfig {
+	return acct.acct
+}
+
 func (acct *AccountView) Name() string {
 	return acct.acct.Name
 }
diff --git a/widgets/compose.go b/widgets/compose.go
index f07e3ee..3d74301 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -1,11 +1,14 @@
 package widgets
 
 import (
+	"io/ioutil"
+	"os"
 	"os/exec"
 
 	"github.com/gdamore/tcell"
 	"github.com/mattn/go-runewidth"
 
+	"git.sr.ht/~sircmpwn/aerc2/config"
 	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
 )
 
@@ -21,7 +24,10 @@ type Composer struct {
 		to      *headerEditor
 	}
 
+	config *config.AccountConfig
+
 	editor *Terminal
+	email  *os.File
 	grid   *ui.Grid
 
 	focusable []ui.DrawableInteractive
@@ -29,7 +35,7 @@ type Composer struct {
 }
 
 // TODO: Let caller configure headers, initial body (for replies), etc
-func NewComposer() *Composer {
+func NewComposer(conf *config.AccountConfig) *Composer {
 	grid := ui.NewGrid().Rows([]ui.GridSpec{
 		{ui.SIZE_EXACT, 3},
 		{ui.SIZE_WEIGHT, 1},
@@ -48,32 +54,34 @@ func NewComposer() *Composer {
 	})
 
 	to := newHeaderEditor("To", "")
-	from := newHeaderEditor("From", "")
+	from := newHeaderEditor("From", conf.From)
 	subject := newHeaderEditor("Subject", "")
 	headers.AddChild(to).At(0, 0)
 	headers.AddChild(from).At(0, 1)
 	headers.AddChild(subject).At(1, 0).Span(1, 2)
 	headers.AddChild(ui.NewFill(' ')).At(2, 0).Span(1, 2)
 
+	email, err := ioutil.TempFile("", "aerc-compose-*.eml")
+	if err != nil {
+		// TODO: handle this better
+		return nil
+	}
+
 	// TODO: built-in config option, $EDITOR, then vi, in that order
-	// TODO: temp file
-	editor := exec.Command("vim")
+	editor := exec.Command("vim", email.Name())
 	term, _ := NewTerminal(editor)
 
 	grid.AddChild(headers).At(0, 0)
 	grid.AddChild(term).At(1, 0)
 
 	return &Composer{
-		grid:   grid,
+		config: conf,
 		editor: term,
+		email:  email,
+		grid:   grid,
 		// You have to backtab to get to "From", since you usually don't edit it
-		focused: 1,
-		focusable: []ui.DrawableInteractive{
-			from,
-			to,
-			subject,
-			term,
-		},
+		focused:   1,
+		focusable: []ui.DrawableInteractive{from, to, subject, term},
 	}
 }