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.
This commit is contained in:
parent
a1763bf207
commit
d7975132b6
2 changed files with 17 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue