Rig up key bindings

This commit is contained in:
Drew DeVault 2019-03-15 01:46:14 -04:00
parent 8d20e9218e
commit 24dfc47126
6 changed files with 231 additions and 203 deletions

View File

@ -103,38 +103,36 @@ q = :quit<Enter>
j = :next-message<Enter> j = :next-message<Enter>
<Down> = :next-message<Enter> <Down> = :next-message<Enter>
<C-d> = :next-message --scroll 50%<Enter> <C-d> = :next-message 50%<Enter>
<C-f> = :next-message --scroll 100%<Enter> <C-f> = :next-message 100%<Enter>
<PageDown> = :next-message --scroll 100%<Enter> <PgDn> = :next-message 100%<Enter>
<WheelDown> = :next-message --scroll 1<Enter>
k = :previous-message<Enter> k = :prev-message<Enter>
<Up> = :previous-message<Enter> <Up> = :prev-message<Enter>
<C-u> = :previous-message --scroll 50%<Enter> <C-u> = :prev-message 50%<Enter>
<C-b> = :previous-message --scroll 100%<Enter> <C-b> = :prev-message 100%<Enter>
<PageUp> = :previous-message --scroll 100%<Enter> <PgUp> = :prev-message 100%<Enter>
<WheelUp> = :previous-message --scroll 1<Enter>
g = :select-message 0<Enter> g = :select-message 0<Enter>
G = :select-message -1<Enter> G = :select-message -1<Enter>
J = :next-folder<Enter> J = :next-folder<Enter>
K = :previous-folder<Enter> K = :prev-folder<Enter>
l = :next-account<Enter> l = :next-account<Enter>
<Right> = :next-account<Enter> <Right> = :next-account<Enter>
h = :previous-account<Enter> h = :prev-account<Enter>
<Left> = :previous-account<Enter> <Left> = :prev-account<Enter>
<Enter> = :view-message<Enter> <Enter> = :view-message<Enter>
d = :confirm 'Really delete this message?' ':delete-message<Enter>'<Enter> d = :confirm 'Really delete this message?' ':delete-message<Enter>'<Enter>
c = :cd c = :cd<space>
$ = :term-exec $ = :term-exec
[mbinds] [mbinds]
# #
# Any key not bound is passed through to the sub-terminal. # Any key not bound is passed through to the sub-terminal.
<Ctrl+h> = :previous-account<Enter> <Ctrl+h> = :prev-account<Enter>
<Ctrl+l> = :next-account<Enter> <Ctrl+l> = :next-account<Enter>
[colors] [colors]

View File

@ -68,7 +68,7 @@ func (bindings *KeyBindings) GetBinding(
} }
var ( var (
keyNames map[string]tcell.Key keyNames map[string]KeyStroke
) )
func ParseKeyStrokes(keystrokes string) ([]KeyStroke, error) { func ParseKeyStrokes(keystrokes string) ([]KeyStroke, error) {
@ -95,9 +95,7 @@ func ParseKeyStrokes(keystrokes string) ([]KeyStroke, error) {
} }
name = name[:len(name)-1] name = name[:len(name)-1]
if key, ok := keyNames[strings.ToLower(name)]; ok { if key, ok := keyNames[strings.ToLower(name)]; ok {
strokes = append(strokes, KeyStroke{ strokes = append(strokes, key)
Key: key,
})
} else { } else {
return nil, errors.New(fmt.Sprintf("Unknown key '%s'", name)) return nil, errors.New(fmt.Sprintf("Unknown key '%s'", name))
} }
@ -129,156 +127,158 @@ func ParseBinding(input, output string) (*Binding, error) {
} }
func init() { func init() {
keyNames = make(map[string]tcell.Key) keyNames = make(map[string]KeyStroke)
keyNames["up"] = tcell.KeyUp keyNames["space"] = KeyStroke{tcell.KeyRune, ' '}
keyNames["down"] = tcell.KeyDown keyNames["enter"] = KeyStroke{tcell.KeyEnter, 0}
keyNames["right"] = tcell.KeyRight keyNames["up"] = KeyStroke{tcell.KeyUp, 0}
keyNames["left"] = tcell.KeyLeft keyNames["down"] = KeyStroke{tcell.KeyDown, 0}
keyNames["upleft"] = tcell.KeyUpLeft keyNames["right"] = KeyStroke{tcell.KeyRight, 0}
keyNames["upright"] = tcell.KeyUpRight keyNames["left"] = KeyStroke{tcell.KeyLeft, 0}
keyNames["downleft"] = tcell.KeyDownLeft keyNames["upleft"] = KeyStroke{tcell.KeyUpLeft, 0}
keyNames["downright"] = tcell.KeyDownRight keyNames["upright"] = KeyStroke{tcell.KeyUpRight, 0}
keyNames["center"] = tcell.KeyCenter keyNames["downleft"] = KeyStroke{tcell.KeyDownLeft, 0}
keyNames["pgup"] = tcell.KeyPgUp keyNames["downright"] = KeyStroke{tcell.KeyDownRight, 0}
keyNames["pgdn"] = tcell.KeyPgDn keyNames["center"] = KeyStroke{tcell.KeyCenter, 0}
keyNames["home"] = tcell.KeyHome keyNames["pgup"] = KeyStroke{tcell.KeyPgUp, 0}
keyNames["end"] = tcell.KeyEnd keyNames["pgdn"] = KeyStroke{tcell.KeyPgDn, 0}
keyNames["insert"] = tcell.KeyInsert keyNames["home"] = KeyStroke{tcell.KeyHome, 0}
keyNames["delete"] = tcell.KeyDelete keyNames["end"] = KeyStroke{tcell.KeyEnd, 0}
keyNames["help"] = tcell.KeyHelp keyNames["insert"] = KeyStroke{tcell.KeyInsert, 0}
keyNames["exit"] = tcell.KeyExit keyNames["delete"] = KeyStroke{tcell.KeyDelete, 0}
keyNames["clear"] = tcell.KeyClear keyNames["help"] = KeyStroke{tcell.KeyHelp, 0}
keyNames["cancel"] = tcell.KeyCancel keyNames["exit"] = KeyStroke{tcell.KeyExit, 0}
keyNames["print"] = tcell.KeyPrint keyNames["clear"] = KeyStroke{tcell.KeyClear, 0}
keyNames["pause"] = tcell.KeyPause keyNames["cancel"] = KeyStroke{tcell.KeyCancel, 0}
keyNames["backtab"] = tcell.KeyBacktab keyNames["print"] = KeyStroke{tcell.KeyPrint, 0}
keyNames["f1"] = tcell.KeyF1 keyNames["pause"] = KeyStroke{tcell.KeyPause, 0}
keyNames["f2"] = tcell.KeyF2 keyNames["backtab"] = KeyStroke{tcell.KeyBacktab, 0}
keyNames["f3"] = tcell.KeyF3 keyNames["f1"] = KeyStroke{tcell.KeyF1, 0}
keyNames["f4"] = tcell.KeyF4 keyNames["f2"] = KeyStroke{tcell.KeyF2, 0}
keyNames["f5"] = tcell.KeyF5 keyNames["f3"] = KeyStroke{tcell.KeyF3, 0}
keyNames["f6"] = tcell.KeyF6 keyNames["f4"] = KeyStroke{tcell.KeyF4, 0}
keyNames["f7"] = tcell.KeyF7 keyNames["f5"] = KeyStroke{tcell.KeyF5, 0}
keyNames["f8"] = tcell.KeyF8 keyNames["f6"] = KeyStroke{tcell.KeyF6, 0}
keyNames["f9"] = tcell.KeyF9 keyNames["f7"] = KeyStroke{tcell.KeyF7, 0}
keyNames["f10"] = tcell.KeyF10 keyNames["f8"] = KeyStroke{tcell.KeyF8, 0}
keyNames["f11"] = tcell.KeyF11 keyNames["f9"] = KeyStroke{tcell.KeyF9, 0}
keyNames["f12"] = tcell.KeyF12 keyNames["f10"] = KeyStroke{tcell.KeyF10, 0}
keyNames["f13"] = tcell.KeyF13 keyNames["f11"] = KeyStroke{tcell.KeyF11, 0}
keyNames["f14"] = tcell.KeyF14 keyNames["f12"] = KeyStroke{tcell.KeyF12, 0}
keyNames["f15"] = tcell.KeyF15 keyNames["f13"] = KeyStroke{tcell.KeyF13, 0}
keyNames["f16"] = tcell.KeyF16 keyNames["f14"] = KeyStroke{tcell.KeyF14, 0}
keyNames["f17"] = tcell.KeyF17 keyNames["f15"] = KeyStroke{tcell.KeyF15, 0}
keyNames["f18"] = tcell.KeyF18 keyNames["f16"] = KeyStroke{tcell.KeyF16, 0}
keyNames["f19"] = tcell.KeyF19 keyNames["f17"] = KeyStroke{tcell.KeyF17, 0}
keyNames["f20"] = tcell.KeyF20 keyNames["f18"] = KeyStroke{tcell.KeyF18, 0}
keyNames["f21"] = tcell.KeyF21 keyNames["f19"] = KeyStroke{tcell.KeyF19, 0}
keyNames["f22"] = tcell.KeyF22 keyNames["f20"] = KeyStroke{tcell.KeyF20, 0}
keyNames["f23"] = tcell.KeyF23 keyNames["f21"] = KeyStroke{tcell.KeyF21, 0}
keyNames["f24"] = tcell.KeyF24 keyNames["f22"] = KeyStroke{tcell.KeyF22, 0}
keyNames["f25"] = tcell.KeyF25 keyNames["f23"] = KeyStroke{tcell.KeyF23, 0}
keyNames["f26"] = tcell.KeyF26 keyNames["f24"] = KeyStroke{tcell.KeyF24, 0}
keyNames["f27"] = tcell.KeyF27 keyNames["f25"] = KeyStroke{tcell.KeyF25, 0}
keyNames["f28"] = tcell.KeyF28 keyNames["f26"] = KeyStroke{tcell.KeyF26, 0}
keyNames["f29"] = tcell.KeyF29 keyNames["f27"] = KeyStroke{tcell.KeyF27, 0}
keyNames["f30"] = tcell.KeyF30 keyNames["f28"] = KeyStroke{tcell.KeyF28, 0}
keyNames["f31"] = tcell.KeyF31 keyNames["f29"] = KeyStroke{tcell.KeyF29, 0}
keyNames["f32"] = tcell.KeyF32 keyNames["f30"] = KeyStroke{tcell.KeyF30, 0}
keyNames["f33"] = tcell.KeyF33 keyNames["f31"] = KeyStroke{tcell.KeyF31, 0}
keyNames["f34"] = tcell.KeyF34 keyNames["f32"] = KeyStroke{tcell.KeyF32, 0}
keyNames["f35"] = tcell.KeyF35 keyNames["f33"] = KeyStroke{tcell.KeyF33, 0}
keyNames["f36"] = tcell.KeyF36 keyNames["f34"] = KeyStroke{tcell.KeyF34, 0}
keyNames["f37"] = tcell.KeyF37 keyNames["f35"] = KeyStroke{tcell.KeyF35, 0}
keyNames["f38"] = tcell.KeyF38 keyNames["f36"] = KeyStroke{tcell.KeyF36, 0}
keyNames["f39"] = tcell.KeyF39 keyNames["f37"] = KeyStroke{tcell.KeyF37, 0}
keyNames["f40"] = tcell.KeyF40 keyNames["f38"] = KeyStroke{tcell.KeyF38, 0}
keyNames["f41"] = tcell.KeyF41 keyNames["f39"] = KeyStroke{tcell.KeyF39, 0}
keyNames["f42"] = tcell.KeyF42 keyNames["f40"] = KeyStroke{tcell.KeyF40, 0}
keyNames["f43"] = tcell.KeyF43 keyNames["f41"] = KeyStroke{tcell.KeyF41, 0}
keyNames["f44"] = tcell.KeyF44 keyNames["f42"] = KeyStroke{tcell.KeyF42, 0}
keyNames["f45"] = tcell.KeyF45 keyNames["f43"] = KeyStroke{tcell.KeyF43, 0}
keyNames["f46"] = tcell.KeyF46 keyNames["f44"] = KeyStroke{tcell.KeyF44, 0}
keyNames["f47"] = tcell.KeyF47 keyNames["f45"] = KeyStroke{tcell.KeyF45, 0}
keyNames["f48"] = tcell.KeyF48 keyNames["f46"] = KeyStroke{tcell.KeyF46, 0}
keyNames["f49"] = tcell.KeyF49 keyNames["f47"] = KeyStroke{tcell.KeyF47, 0}
keyNames["f50"] = tcell.KeyF50 keyNames["f48"] = KeyStroke{tcell.KeyF48, 0}
keyNames["f51"] = tcell.KeyF51 keyNames["f49"] = KeyStroke{tcell.KeyF49, 0}
keyNames["f52"] = tcell.KeyF52 keyNames["f50"] = KeyStroke{tcell.KeyF50, 0}
keyNames["f53"] = tcell.KeyF53 keyNames["f51"] = KeyStroke{tcell.KeyF51, 0}
keyNames["f54"] = tcell.KeyF54 keyNames["f52"] = KeyStroke{tcell.KeyF52, 0}
keyNames["f55"] = tcell.KeyF55 keyNames["f53"] = KeyStroke{tcell.KeyF53, 0}
keyNames["f56"] = tcell.KeyF56 keyNames["f54"] = KeyStroke{tcell.KeyF54, 0}
keyNames["f57"] = tcell.KeyF57 keyNames["f55"] = KeyStroke{tcell.KeyF55, 0}
keyNames["f58"] = tcell.KeyF58 keyNames["f56"] = KeyStroke{tcell.KeyF56, 0}
keyNames["f59"] = tcell.KeyF59 keyNames["f57"] = KeyStroke{tcell.KeyF57, 0}
keyNames["f60"] = tcell.KeyF60 keyNames["f58"] = KeyStroke{tcell.KeyF58, 0}
keyNames["f61"] = tcell.KeyF61 keyNames["f59"] = KeyStroke{tcell.KeyF59, 0}
keyNames["f62"] = tcell.KeyF62 keyNames["f60"] = KeyStroke{tcell.KeyF60, 0}
keyNames["f63"] = tcell.KeyF63 keyNames["f61"] = KeyStroke{tcell.KeyF61, 0}
keyNames["f64"] = tcell.KeyF64 keyNames["f62"] = KeyStroke{tcell.KeyF62, 0}
keyNames["c-space"] = tcell.KeyCtrlSpace keyNames["f63"] = KeyStroke{tcell.KeyF63, 0}
keyNames["c-a"] = tcell.KeyCtrlA keyNames["f64"] = KeyStroke{tcell.KeyF64, 0}
keyNames["c-b"] = tcell.KeyCtrlB keyNames["c-space"] = KeyStroke{tcell.KeyCtrlSpace, 0}
keyNames["c-c"] = tcell.KeyCtrlC keyNames["c-a"] = KeyStroke{tcell.KeyCtrlA, 0}
keyNames["c-d"] = tcell.KeyCtrlD keyNames["c-b"] = KeyStroke{tcell.KeyCtrlB, 0}
keyNames["c-e"] = tcell.KeyCtrlE keyNames["c-c"] = KeyStroke{tcell.KeyCtrlC, 0}
keyNames["c-f"] = tcell.KeyCtrlF keyNames["c-d"] = KeyStroke{tcell.KeyCtrlD, 0}
keyNames["c-g"] = tcell.KeyCtrlG keyNames["c-e"] = KeyStroke{tcell.KeyCtrlE, 0}
keyNames["c-h"] = tcell.KeyCtrlH keyNames["c-f"] = KeyStroke{tcell.KeyCtrlF, 0}
keyNames["c-i"] = tcell.KeyCtrlI keyNames["c-g"] = KeyStroke{tcell.KeyCtrlG, 0}
keyNames["c-j"] = tcell.KeyCtrlJ keyNames["c-h"] = KeyStroke{tcell.KeyCtrlH, 0}
keyNames["c-k"] = tcell.KeyCtrlK keyNames["c-i"] = KeyStroke{tcell.KeyCtrlI, 0}
keyNames["c-l"] = tcell.KeyCtrlL keyNames["c-j"] = KeyStroke{tcell.KeyCtrlJ, 0}
keyNames["c-m"] = tcell.KeyCtrlM keyNames["c-k"] = KeyStroke{tcell.KeyCtrlK, 0}
keyNames["c-n"] = tcell.KeyCtrlN keyNames["c-l"] = KeyStroke{tcell.KeyCtrlL, 0}
keyNames["c-o"] = tcell.KeyCtrlO keyNames["c-m"] = KeyStroke{tcell.KeyCtrlM, 0}
keyNames["c-p"] = tcell.KeyCtrlP keyNames["c-n"] = KeyStroke{tcell.KeyCtrlN, 0}
keyNames["c-q"] = tcell.KeyCtrlQ keyNames["c-o"] = KeyStroke{tcell.KeyCtrlO, 0}
keyNames["c-r"] = tcell.KeyCtrlR keyNames["c-p"] = KeyStroke{tcell.KeyCtrlP, 0}
keyNames["c-s"] = tcell.KeyCtrlS keyNames["c-q"] = KeyStroke{tcell.KeyCtrlQ, 0}
keyNames["c-t"] = tcell.KeyCtrlT keyNames["c-r"] = KeyStroke{tcell.KeyCtrlR, 0}
keyNames["c-u"] = tcell.KeyCtrlU keyNames["c-s"] = KeyStroke{tcell.KeyCtrlS, 0}
keyNames["c-v"] = tcell.KeyCtrlV keyNames["c-t"] = KeyStroke{tcell.KeyCtrlT, 0}
keyNames["c-w"] = tcell.KeyCtrlW keyNames["c-u"] = KeyStroke{tcell.KeyCtrlU, 0}
keyNames["c-x"] = tcell.KeyCtrlX keyNames["c-v"] = KeyStroke{tcell.KeyCtrlV, 0}
keyNames["c-y"] = tcell.KeyCtrlY keyNames["c-w"] = KeyStroke{tcell.KeyCtrlW, 0}
keyNames["c-z"] = tcell.KeyCtrlZ keyNames["c-x"] = KeyStroke{tcell.KeyCtrlX, 0}
keyNames["c-]"] = tcell.KeyCtrlLeftSq keyNames["c-y"] = KeyStroke{tcell.KeyCtrlY, 0}
keyNames["c-\\"] = tcell.KeyCtrlBackslash keyNames["c-z"] = KeyStroke{tcell.KeyCtrlZ, 0}
keyNames["c-["] = tcell.KeyCtrlRightSq keyNames["c-]"] = KeyStroke{tcell.KeyCtrlLeftSq, 0}
keyNames["c-^"] = tcell.KeyCtrlCarat keyNames["c-\\"] = KeyStroke{tcell.KeyCtrlBackslash, 0}
keyNames["c-_"] = tcell.KeyCtrlUnderscore keyNames["c-["] = KeyStroke{tcell.KeyCtrlRightSq, 0}
keyNames["NUL"] = tcell.KeyNUL keyNames["c-^"] = KeyStroke{tcell.KeyCtrlCarat, 0}
keyNames["SOH"] = tcell.KeySOH keyNames["c-_"] = KeyStroke{tcell.KeyCtrlUnderscore, 0}
keyNames["STX"] = tcell.KeySTX keyNames["NUL"] = KeyStroke{tcell.KeyNUL, 0}
keyNames["ETX"] = tcell.KeyETX keyNames["SOH"] = KeyStroke{tcell.KeySOH, 0}
keyNames["EOT"] = tcell.KeyEOT keyNames["STX"] = KeyStroke{tcell.KeySTX, 0}
keyNames["ENQ"] = tcell.KeyENQ keyNames["ETX"] = KeyStroke{tcell.KeyETX, 0}
keyNames["ACK"] = tcell.KeyACK keyNames["EOT"] = KeyStroke{tcell.KeyEOT, 0}
keyNames["BEL"] = tcell.KeyBEL keyNames["ENQ"] = KeyStroke{tcell.KeyENQ, 0}
keyNames["BS"] = tcell.KeyBS keyNames["ACK"] = KeyStroke{tcell.KeyACK, 0}
keyNames["TAB"] = tcell.KeyTAB keyNames["BEL"] = KeyStroke{tcell.KeyBEL, 0}
keyNames["LF"] = tcell.KeyLF keyNames["BS"] = KeyStroke{tcell.KeyBS, 0}
keyNames["VT"] = tcell.KeyVT keyNames["TAB"] = KeyStroke{tcell.KeyTAB, 0}
keyNames["FF"] = tcell.KeyFF keyNames["LF"] = KeyStroke{tcell.KeyLF, 0}
keyNames["CR"] = tcell.KeyCR keyNames["VT"] = KeyStroke{tcell.KeyVT, 0}
keyNames["SO"] = tcell.KeySO keyNames["FF"] = KeyStroke{tcell.KeyFF, 0}
keyNames["SI"] = tcell.KeySI keyNames["CR"] = KeyStroke{tcell.KeyCR, 0}
keyNames["DLE"] = tcell.KeyDLE keyNames["SO"] = KeyStroke{tcell.KeySO, 0}
keyNames["DC1"] = tcell.KeyDC1 keyNames["SI"] = KeyStroke{tcell.KeySI, 0}
keyNames["DC2"] = tcell.KeyDC2 keyNames["DLE"] = KeyStroke{tcell.KeyDLE, 0}
keyNames["DC3"] = tcell.KeyDC3 keyNames["DC1"] = KeyStroke{tcell.KeyDC1, 0}
keyNames["DC4"] = tcell.KeyDC4 keyNames["DC2"] = KeyStroke{tcell.KeyDC2, 0}
keyNames["NAK"] = tcell.KeyNAK keyNames["DC3"] = KeyStroke{tcell.KeyDC3, 0}
keyNames["SYN"] = tcell.KeySYN keyNames["DC4"] = KeyStroke{tcell.KeyDC4, 0}
keyNames["ETB"] = tcell.KeyETB keyNames["NAK"] = KeyStroke{tcell.KeyNAK, 0}
keyNames["CAN"] = tcell.KeyCAN keyNames["SYN"] = KeyStroke{tcell.KeySYN, 0}
keyNames["EM"] = tcell.KeyEM keyNames["ETB"] = KeyStroke{tcell.KeyETB, 0}
keyNames["SUB"] = tcell.KeySUB keyNames["CAN"] = KeyStroke{tcell.KeyCAN, 0}
keyNames["ESC"] = tcell.KeyESC keyNames["EM"] = KeyStroke{tcell.KeyEM, 0}
keyNames["FS"] = tcell.KeyFS keyNames["SUB"] = KeyStroke{tcell.KeySUB, 0}
keyNames["GS"] = tcell.KeyGS keyNames["ESC"] = KeyStroke{tcell.KeyESC, 0}
keyNames["RS"] = tcell.KeyRS keyNames["FS"] = KeyStroke{tcell.KeyFS, 0}
keyNames["US"] = tcell.KeyUS keyNames["GS"] = KeyStroke{tcell.KeyGS, 0}
keyNames["DEL"] = tcell.KeyDEL keyNames["RS"] = KeyStroke{tcell.KeyRS, 0}
keyNames["US"] = KeyStroke{tcell.KeyUS, 0}
keyNames["DEL"] = KeyStroke{tcell.KeyDEL, 0}
} }

View File

@ -14,7 +14,8 @@ import (
) )
type AccountView struct { type AccountView struct {
conf *config.AccountConfig acct *config.AccountConfig
conf *config.AercConfig
dirlist *DirectoryList dirlist *DirectoryList
grid *ui.Grid grid *ui.Grid
logger *log.Logger logger *log.Logger
@ -23,12 +24,13 @@ type AccountView struct {
runCmd func(cmd string) error runCmd func(cmd string) error
msglist *MessageList msglist *MessageList
msgStores map[string]*MessageStore msgStores map[string]*MessageStore
pendingKeys []config.KeyStroke
statusline *StatusLine statusline *StatusLine
statusbar *ui.Stack statusbar *ui.Stack
worker *types.Worker worker *types.Worker
} }
func NewAccountView(conf *config.AccountConfig, func NewAccountView(conf *config.AercConfig, acct *config.AccountConfig,
logger *log.Logger, runCmd func(cmd string) error) *AccountView { logger *log.Logger, runCmd func(cmd string) error) *AccountView {
statusbar := ui.NewStack() statusbar := ui.NewStack()
@ -44,24 +46,25 @@ func NewAccountView(conf *config.AccountConfig,
}) })
grid.AddChild(statusbar).At(1, 1) grid.AddChild(statusbar).At(1, 1)
worker, err := worker.NewWorker(conf.Source, logger) worker, err := worker.NewWorker(acct.Source, logger)
if err != nil { if err != nil {
statusline.Set(fmt.Sprintf("%s", err)) statusline.Set(fmt.Sprintf("%s", err))
return &AccountView{ return &AccountView{
conf: conf, acct: acct,
grid: grid, grid: grid,
logger: logger, logger: logger,
statusline: statusline, statusline: statusline,
} }
} }
dirlist := NewDirectoryList(conf, logger, worker) dirlist := NewDirectoryList(acct, logger, worker)
grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT)).Span(2, 1) grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT)).Span(2, 1)
msglist := NewMessageList(logger) msglist := NewMessageList(logger)
grid.AddChild(msglist).At(0, 1) grid.AddChild(msglist).At(0, 1)
acct := &AccountView{ view := &AccountView{
acct: acct,
conf: conf, conf: conf,
dirlist: dirlist, dirlist: dirlist,
grid: grid, grid: grid,
@ -79,19 +82,19 @@ func NewAccountView(conf *config.AccountConfig,
for { for {
msg := <-worker.Messages msg := <-worker.Messages
msg = worker.ProcessMessage(msg) msg = worker.ProcessMessage(msg)
acct.onMessage(msg) view.onMessage(msg)
} }
}() }()
worker.PostAction(&types.Configure{Config: conf}, nil) worker.PostAction(&types.Configure{Config: acct}, nil)
worker.PostAction(&types.Connect{}, acct.connected) worker.PostAction(&types.Connect{}, view.connected)
statusline.Set("Connecting...") statusline.Set("Connecting...")
return acct return view
} }
func (acct *AccountView) Name() string { func (acct *AccountView) Name() string {
return acct.conf.Name return acct.acct.Name
} }
func (acct *AccountView) Children() []ui.Drawable { func (acct *AccountView) Children() []ui.Drawable {
@ -112,28 +115,51 @@ func (acct *AccountView) Draw(ctx *ui.Context) {
acct.grid.Draw(ctx) acct.grid.Draw(ctx)
} }
func (acct *AccountView) beginExCommand() {
exline := NewExLine(func(command string) {
err := acct.runCmd(command)
if err != nil {
acct.statusline.Push(" "+err.Error(), 10*time.Second).
Color(tcell.ColorRed, tcell.ColorWhite)
}
acct.statusbar.Pop()
acct.interactive = nil
}, func() {
acct.statusbar.Pop()
acct.interactive = nil
})
acct.interactive = exline
acct.statusbar.Push(exline)
}
func (acct *AccountView) Event(event tcell.Event) bool { func (acct *AccountView) Event(event tcell.Event) bool {
if acct.interactive != nil { if acct.interactive != nil {
return acct.interactive.Event(event) return acct.interactive.Event(event)
} }
switch event := event.(type) { switch event := event.(type) {
case *tcell.EventKey: case *tcell.EventKey:
if event.Rune() == ':' { acct.pendingKeys = append(acct.pendingKeys, config.KeyStroke{
exline := NewExLine(func(command string) { Key: event.Key(),
err := acct.runCmd(command) Rune: event.Rune(),
if err != nil { })
acct.statusline.Push(" "+err.Error(), 10*time.Second). result, output := acct.conf.Lbinds.GetBinding(acct.pendingKeys)
Color(tcell.ColorRed, tcell.ColorWhite) switch result {
} case config.BINDING_FOUND:
acct.statusbar.Pop() acct.pendingKeys = []config.KeyStroke{}
acct.interactive = nil for _, stroke := range output {
}, func() { simulated := tcell.NewEventKey(
acct.statusbar.Pop() stroke.Key, stroke.Rune, tcell.ModNone)
acct.interactive = nil acct.Event(simulated)
}) }
acct.interactive = exline case config.BINDING_INCOMPLETE:
acct.statusbar.Push(exline) return false
return true case config.BINDING_NOT_FOUND:
acct.pendingKeys = []config.KeyStroke{}
if event.Rune() == ':' {
acct.beginExCommand()
return true
}
} }
} }
return false return false

View File

@ -45,7 +45,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
} }
for _, acct := range conf.Accounts { for _, acct := range conf.Accounts {
view := NewAccountView(&acct, logger, cmd) view := NewAccountView(conf, &acct, logger, cmd)
aerc.accounts[acct.Name] = view aerc.accounts[acct.Name] = view
tabs.Add(view, acct.Name) tabs.Add(view, acct.Name)
} }

View File

@ -121,10 +121,14 @@ func (ex *ExLine) Event(event tcell.Event) bool {
case tcell.KeyCtrlW: case tcell.KeyCtrlW:
ex.deleteWord() ex.deleteWord()
case tcell.KeyEnter: case tcell.KeyEnter:
ex.ctx.HideCursor() if ex.ctx != nil {
ex.ctx.HideCursor()
}
ex.commit(string(ex.command)) ex.commit(string(ex.command))
case tcell.KeyEsc, tcell.KeyCtrlC: case tcell.KeyEsc, tcell.KeyCtrlC:
ex.ctx.HideCursor() if ex.ctx != nil {
ex.ctx.HideCursor()
}
ex.cancel() ex.cancel()
case tcell.KeyRune: case tcell.KeyRune:
ex.insert(event.Rune()) ex.insert(event.Rune())

View File

@ -184,10 +184,10 @@ func (ml *MessageList) SetStore(store *MessageStore) {
func (ml *MessageList) nextPrev(delta int) { func (ml *MessageList) nextPrev(delta int) {
ml.selected += delta ml.selected += delta
if ml.selected < 0 { if ml.selected < 0 {
ml.selected = len(ml.store.Uids) - 1 ml.selected = 0
} }
if ml.selected >= len(ml.store.Uids) { if ml.selected >= len(ml.store.Uids) {
ml.selected = 0 ml.selected = len(ml.store.Uids) - 1
} }
// TODO: scrolling // TODO: scrolling
ml.Invalidate() ml.Invalidate()