summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-07-16 18:43:08 +0100
committerDrew DeVault <sir@cmpwn.com>2019-07-17 17:12:52 -0400
commitd7975132b62942530da6c4907bed3eb3ab99e4a3 (patch)
tree605a2e0f1dfdf20ddbb6797524d3ea7ef3d90814 /widgets
parenta1763bf2079400693515772dcb2ad09c53f36e4e (diff)
downloadaerc-d7975132b62942530da6c4907bed3eb3ab99e4a3.tar.gz
Show currently pressed keys in statusline
This patch adds the currently pressed keys to the statusline. This is
useful when keybindings are multiple keys long and you might forget
which keys are already pressed.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/aerc.go3
-rw-r--r--widgets/status.go15
2 files changed, 17 insertions, 1 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index e113830..a73caec 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -58,6 +58,8 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
 		tabs:       tabs,
 	}
 
+	statusline.SetAerc(aerc)
+
 	for i, acct := range conf.Accounts {
 		view := NewAccountView(conf, &conf.Accounts[i], logger, aerc)
 		aerc.accounts[acct.Name] = view
@@ -150,6 +152,7 @@ func (aerc *Aerc) Event(event tcell.Event) bool {
 			Key:  event.Key(),
 			Rune: event.Rune(),
 		})
+		aerc.statusline.Invalidate()
 		bindings := aerc.getBindings()
 		incomplete := false
 		result, strokes := bindings.GetBinding(aerc.pendingKeys)
diff --git a/widgets/status.go b/widgets/status.go
index c7764f8..8d0a1ae 100644
--- a/widgets/status.go
+++ b/widgets/status.go
@@ -4,6 +4,7 @@ import (
 	"time"
 
 	"github.com/gdamore/tcell"
+	"github.com/mattn/go-runewidth"
 
 	"git.sr.ht/~sircmpwn/aerc/lib/ui"
 )
@@ -12,6 +13,7 @@ type StatusLine struct {
 	ui.Invalidatable
 	stack    []*StatusMessage
 	fallback StatusMessage
+	aerc     *Aerc
 }
 
 type StatusMessage struct {
@@ -42,7 +44,14 @@ func (status *StatusLine) Draw(ctx *ui.Context) {
 	style := tcell.StyleDefault.
 		Background(line.bg).Foreground(line.fg).Reverse(true)
 	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
-	ctx.Printf(0, 0, style, "%s", line.message)
+	pendingKeys := ""
+	if status.aerc != nil {
+		for _, pendingKey := range status.aerc.pendingKeys {
+			pendingKeys += string(pendingKey.Rune)
+		}
+	}
+	message := runewidth.FillRight(line.message, ctx.Width()-len(pendingKeys)-5)
+	ctx.Printf(0, 0, style, "%s%s", message, pendingKeys)
 }
 
 func (status *StatusLine) Set(text string) *StatusMessage {
@@ -79,6 +88,10 @@ func (status *StatusLine) Expire() {
 	status.stack = nil
 }
 
+func (status *StatusLine) SetAerc(aerc *Aerc) {
+	status.aerc = aerc
+}
+
 func (msg *StatusMessage) Color(bg tcell.Color, fg tcell.Color) {
 	msg.bg = bg
 	msg.fg = fg
g@mmvi <unknown> 2006-09-26 13:24:14 +0200 changed order of colordefs in config.h's, changed config.arg.h to fit to new dmenu' href='/acidbong/suckless/dwm/commit/config.default.h?h=2.7&id=97ced11e531f4e51d7ee248ae654a2b04daaad1c'>97ced11 ^
19390b1 ^
b515765 ^

b515765 ^
19dcbc5 ^






42fd392 ^
19dcbc5 ^












42fd392 ^
19dcbc5 ^










b515765 ^

d6a6eca ^
2dd5212 ^
b515765 ^

d6a6eca ^
e21d93b ^
a08d83b ^
b515765 ^
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