summary refs log tree commit diff stats
path: root/widgets/aerc.go
blob: cc93d921f08ea4d9e3ad18f30e09cd778ed83eea (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package widgets

import (
	"fmt"
	"log"
	"time"

	"github.com/gdamore/tcell"

	libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
)

type Aerc struct {
	grid        *libui.Grid
	tabs        *libui.Tabs
	statusbar   *libui.Stack
	statusline  *StatusLine
	interactive libui.Interactive
}

func NewAerc(logger *log.Logger) *Aerc {
	tabs := libui.NewTabs()

	mainGrid := libui.NewGrid().Rows([]libui.GridSpec{
		libui.GridSpec{libui.SIZE_EXACT, 1},
		libui.GridSpec{libui.SIZE_WEIGHT, 1},
	}).Columns([]libui.GridSpec{
		libui.GridSpec{libui.SIZE_EXACT, 20},
		libui.GridSpec{libui.SIZE_WEIGHT, 1},
	})

	statusbar := libui.NewStack()
	statusline := NewStatusLine()
	statusbar.Push(statusline)

	// TODO: Grab sidebar size from config and via :set command
	mainGrid.AddChild(libui.NewText("aerc").
		Strategy(libui.TEXT_CENTER).
		Color(tcell.ColorBlack, tcell.ColorWhite))
	mainGrid.AddChild(tabs.TabStrip).At(0, 1)
	mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)

	acctPlaceholder := func(sidebar, body rune, name string) {
		accountGrid := libui.NewGrid().Rows([]libui.GridSpec{
			libui.GridSpec{libui.SIZE_WEIGHT, 1},
			libui.GridSpec{libui.SIZE_EXACT, 1},
		}).Columns([]libui.GridSpec{
			libui.GridSpec{libui.SIZE_EXACT, 20},
			libui.GridSpec{libui.SIZE_WEIGHT, 1},
		})
		// Sidebar placeholder
		accountGrid.AddChild(libui.NewBordered(
			libui.NewFill(sidebar), libui.BORDER_RIGHT)).Span(2, 1)
		// Message list placeholder
		accountGrid.AddChild(libui.NewFill(body)).At(0, 1)
		// Statusbar
		accountGrid.AddChild(statusbar).At(1, 1)
		tabs.Add(accountGrid, name)
	}

	acctPlaceholder('.', '★', "白い星")
	acctPlaceholder(',', '☆', "empty stars")

	go (func() {
		for {
			time.Sleep(1 * time.Second)
			tabs.Select((tabs.Selected + 1) % 2)
		}
	})()

	return &Aerc{
		grid:       mainGrid,
		statusbar:  statusbar,
		statusline: statusline,
		tabs:       tabs,
	}
}

func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
	aerc.grid.OnInvalidate(onInvalidate)
}

func (aerc *Aerc) Invalidate() {
	aerc.grid.Invalidate()
}

func (aerc *Aerc) Draw(ctx *libui.Context) {
	aerc.grid.Draw(ctx)
}

func (aerc *Aerc) Event(event tcell.Event) bool {
	switch event := event.(type) {
	case *tcell.EventKey:
		if event.Rune() == ':' {
			exline := NewExLine(func(command string) {
				aerc.statusline.Push(fmt.Sprintf("TODO: execute %s", command),
					3*time.Second)
				aerc.statusbar.Pop()
				aerc.interactive = nil
			}, func() {
				aerc.statusbar.Pop()
				aerc.interactive = nil
			})
			aerc.interactive = exline
			aerc.statusbar.Push(exline)
			return true
		}
	}
	if aerc.interactive != nil {
		return aerc.interactive.Event(event)
	} else {
		return false
	}
}
"p"><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#000000" face="helvetica, arial"><a name="LazyParser">class <strong>LazyParser</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td> <td colspan=2><tt>Parse&nbsp;commands&nbsp;and&nbsp;extract&nbsp;information<br>&nbsp;</tt></td></tr> <tr><td>&nbsp;</td> <td width="100%">Methods defined here:<br> <dl><dt><a name="LazyParser-__add__"><strong>__add__</strong></a>(self, newpart)</dt></dl> <dl><dt><a name="LazyParser-__init__"><strong>__init__</strong></a>(self, line)</dt></dl> <dl><dt><a name="LazyParser-chunk"><strong>chunk</strong></a>(self, n, otherwise<font color="#909090">=''</font>)</dt><dd><tt>Chunks&nbsp;are&nbsp;pieces&nbsp;of&nbsp;the&nbsp;command&nbsp;seperated&nbsp;by&nbsp;spaces</tt></dd></dl> <dl><dt><a name="LazyParser-rest"><strong>rest</strong></a>(self, n, otherwise<font color="#909090">=''</font>)</dt><dd><tt>Rests&nbsp;are&nbsp;the&nbsp;strings&nbsp;which&nbsp;come&nbsp;after&nbsp;each&nbsp;word.</tt></dd></dl> <hr> Data descriptors defined here:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd> </dl> </td></tr></table></td></tr></table> </body></html>