aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-13 16:24:05 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-13 16:53:02 -0400
commitbb46b2b7e15ba839475973ae44d5a833c6f2b265 (patch)
treef4f5036a314e965e4dc1261119e1478b4935d677
parent17bd2dc4dbb3b43b1917c942100834c1341f2194 (diff)
Spec out review message screen
-rw-r--r--lib/ui/grid.go6
-rw-r--r--widgets/compose.go64
2 files changed, 61 insertions, 9 deletions
diff --git a/lib/ui/grid.go b/lib/ui/grid.go
index f36a16a..5011a81 100644
--- a/lib/ui/grid.go
+++ b/lib/ui/grid.go
@@ -181,10 +181,10 @@ func (grid *Grid) AddChild(content Drawable) *GridCell {
return cell
}
-func (grid *Grid) RemoveChild(cell *GridCell) {
+func (grid *Grid) RemoveChild(content Drawable) {
grid.mutex.Lock()
- for i, _cell := range grid.cells {
- if _cell == cell {
+ for i, cell := range grid.cells {
+ if cell.Content == content {
grid.cells = append(grid.cells[:i], grid.cells[i+1:]...)
break
}
diff --git a/widgets/compose.go b/widgets/compose.go
index 3d74301..5b7a1ba 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -12,11 +12,6 @@ import (
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
)
-type headerEditor struct {
- name string
- input *ui.TextInput
-}
-
type Composer struct {
headers struct {
from *headerEditor
@@ -29,6 +24,7 @@ type Composer struct {
editor *Terminal
email *os.File
grid *ui.Grid
+ review *reviewMessage
focusable []ui.DrawableInteractive
focused int
@@ -74,7 +70,7 @@ func NewComposer(conf *config.AccountConfig) *Composer {
grid.AddChild(headers).At(0, 0)
grid.AddChild(term).At(1, 0)
- return &Composer{
+ c := &Composer{
config: conf,
editor: term,
email: email,
@@ -83,6 +79,10 @@ func NewComposer(conf *config.AccountConfig) *Composer {
focused: 1,
focusable: []ui.DrawableInteractive{from, to, subject, term},
}
+
+ term.OnClose = c.termClosed
+
+ return c
}
func (c *Composer) Draw(ctx *ui.Context) {
@@ -107,6 +107,13 @@ func (c *Composer) Focus(focus bool) {
c.focusable[c.focused].Focus(focus)
}
+func (c *Composer) termClosed(err error) {
+ // TODO: do we care about that error (note: yes, we do)
+ c.grid.RemoveChild(c.editor)
+ c.grid.AddChild(newReviewMessage(c)).At(1, 0)
+ c.editor.Destroy()
+}
+
func (c *Composer) PrevField() {
c.focusable[c.focused].Focus(false)
c.focused--
@@ -122,6 +129,11 @@ func (c *Composer) NextField() {
c.focusable[c.focused].Focus(true)
}
+type headerEditor struct {
+ name string
+ input *ui.TextInput
+}
+
func newHeaderEditor(name string, value string) *headerEditor {
return &headerEditor{
input: ui.NewTextInput(value),
@@ -154,3 +166,43 @@ func (he *headerEditor) Focus(focused bool) {
func (he *headerEditor) Event(event tcell.Event) bool {
return he.input.Event(event)
}
+
+type reviewMessage struct {
+ composer *Composer
+ grid *ui.Grid
+}
+
+func newReviewMessage(composer *Composer) *reviewMessage {
+ grid := ui.NewGrid().Rows([]ui.GridSpec{
+ {ui.SIZE_EXACT, 2},
+ {ui.SIZE_EXACT, 1},
+ {ui.SIZE_WEIGHT, 1},
+ }).Columns([]ui.GridSpec{
+ {ui.SIZE_WEIGHT, 1},
+ })
+ grid.AddChild(ui.NewText(
+ "Send this email? [y]es/[n]o/[e]dit/[a]ttach file")).At(0, 0)
+ grid.AddChild(ui.NewText("Attachments:").
+ Reverse(true)).At(1, 0)
+ // TODO: Attachments
+ grid.AddChild(ui.NewText("(none)")).At(2, 0)
+
+ return &reviewMessage{
+ composer: composer,
+ grid: grid,
+ }
+}
+
+func (rm *reviewMessage) Invalidate() {
+ rm.grid.Invalidate()
+}
+
+func (rm *reviewMessage) OnInvalidate(fn func(ui.Drawable)) {
+ rm.grid.OnInvalidate(func(_ ui.Drawable) {
+ fn(rm)
+ })
+}
+
+func (rm *reviewMessage) Draw(ctx *ui.Context) {
+ rm.grid.Draw(ctx)
+}