pushTip -> addTip; make it nicer to use.

This commit is contained in:
Qi Xiao 2016-02-13 19:27:21 +01:00
parent c08ae1ea54
commit 55e3f4b029
5 changed files with 18 additions and 23 deletions

View File

@ -164,8 +164,7 @@ func (c EvalCaller) Call(ed *Editor) {
ec := eval.NewTopEvalCtx(ed.evaler, "[editor]", "", ports)
ex := ec.PCall(c.Caller, []eval.Value{})
if ex != nil {
// XXX will disappear very quickly
ed.pushTip("function error: " + ex.Error())
ed.notify("function error: %s", ex.Error())
}
out.Close()

View File

@ -102,7 +102,7 @@ func startInsert(ed *Editor) {
func defaultCommand(ed *Editor) {
k := ed.lastKey
ed.pushTip(fmt.Sprintf("Unbound: %s", k))
ed.addTip("Unbound: %s", k)
}
func startCommand(ed *Editor) {
@ -232,7 +232,7 @@ func insertLastWord(ed *Editor) {
if err == nil {
ed.insertAtDot(lastWord(lastLine))
} else {
ed.pushTip(err.Error())
ed.addTip("db error: %s", err.Error())
}
}
@ -291,7 +291,7 @@ func defaultInsert(ed *Editor) {
if k.Mod == 0 && k.Rune > 0 && unicode.IsGraphic(k.Rune) {
insertKey(ed)
} else {
ed.pushTip(fmt.Sprintf("Unbound: %s", k))
ed.addTip("Unbound: %s", k)
}
}
@ -337,7 +337,7 @@ func startHistory(ed *Editor) {
if ed.prevHistory() {
ed.mode = modeHistory
} else {
ed.pushTip("no matching history item")
ed.addTip("no matching history item")
}
}

View File

@ -1,7 +1,6 @@
package edit
import (
"fmt"
"io/ioutil"
"os"
"path"
@ -130,7 +129,7 @@ func complArgInner(head string, ed *Editor, formHead bool) []*candidate {
cands := []*candidate{}
if err != nil {
ed.pushTip(fmt.Sprintf("cannot list directory %s: %v", dir, err))
ed.addTip("cannot list directory %s: %v", dir, err)
return cands
}

View File

@ -1,9 +1,6 @@
package edit
import (
"fmt"
"unicode/utf8"
)
import "unicode/utf8"
type styled struct {
text string
@ -68,9 +65,9 @@ func startCompletionInner(ed *Editor, completePrefix bool) {
}
if c.candidates == nil {
ed.pushTip("unsupported completion :(")
ed.addTip("unsupported completion :(")
} else if len(c.candidates) == 0 {
ed.pushTip(fmt.Sprintf("no candidate for %s", c.completer))
ed.addTip("no candidate for %s", c.completer)
} else {
if completePrefix {
// If there is a non-empty longest common prefix, insert it and

View File

@ -108,12 +108,12 @@ func (ed *Editor) flash() {
// TODO implement fish-like flash effect
}
func (ed *Editor) pushTip(more string) {
ed.tips = append(ed.tips, more)
func (ed *Editor) addTip(format string, args ...interface{}) {
ed.tips = append(ed.tips, fmt.Sprintf(format, args))
}
func (ed *Editor) notify(msg string) {
ed.notifications = append(ed.notifications, msg)
func (ed *Editor) notify(format string, args ...interface{}) {
ed.notifications = append(ed.notifications, fmt.Sprintf(format, args...))
}
func (ed *Editor) refresh(fullRefresh bool) error {
@ -129,7 +129,7 @@ func (ed *Editor) refresh(fullRefresh bool) error {
_, err := ed.evaler.Compile(name, src, n)
if err != nil {
if err, ok := err.(*errutil.ContextualError); ok {
ed.pushTip("compiler error highlighted")
ed.addTip("compiler error highlighted")
p := err.Pos()
for i, token := range ed.tokens {
if token.Node.Begin() <= p && p < token.Node.End() {
@ -301,19 +301,19 @@ MainLoop:
case syscall.SIGCHLD:
// ignore
default:
ed.pushTip(fmt.Sprintf("ignored signal %s", sig))
ed.addTip("ignored signal %s", sig)
}
case err := <-ed.reader.ErrorChan():
ed.notify(err.Error())
ed.notify("reader error: %s", err.Error())
case mouse := <-ed.reader.MouseChan():
ed.pushTip(fmt.Sprint("mouse:", mouse))
ed.addTip("mouse: %#v", mouse)
case <-ed.reader.CPRChan():
// Ignore CPR
case k := <-ed.reader.KeyChan():
lookupKey:
keyBinding, ok := keyBindings[ed.mode]
if !ok {
ed.pushTip("No binding for current mode")
ed.addTip("No binding for current mode")
continue
}