Change menu contents to be a string (#1954)
This commit is contained in:
1 parent
6718a36334
commit
ffe4c97560
3 files changed
+40
-39
No files matched your search
@@ -547,11 +547,11 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
exportOpts()
|
||||
|
||||
gState.mutex.Lock()
|
||||
gState.data["maps"] = listBinds(gOpts.keys).String()
|
||||
gState.data["cmaps"] = listBinds(gOpts.cmdkeys).String()
|
||||
gState.data["cmds"] = listCmds().String()
|
||||
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd).String()
|
||||
gState.data["history"] = listHistory(app.cmdHistory).String()
|
||||
gState.data["maps"] = listBinds(gOpts.keys)
|
||||
gState.data["cmaps"] = listBinds(gOpts.cmdkeys)
|
||||
gState.data["cmds"] = listCmds()
|
||||
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)
|
||||
gState.data["history"] = listHistory(app.cmdHistory)
|
||||
gState.mutex.Unlock()
|
||||
|
||||
cmd := shellCommand(s, args)
|
||||
|
||||
@@ -691,11 +691,11 @@ func menuComplete(app *app, dir int) {
|
||||
ind := len(app.ui.cmdTmp) - len([]rune(last))
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdTmp[:ind], []rune(comp)...)
|
||||
}
|
||||
app.ui.menuBuf = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)
|
||||
app.ui.menu = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)
|
||||
}
|
||||
|
||||
func update(app *app) {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menu = ""
|
||||
app.menuCompActive = false
|
||||
|
||||
switch {
|
||||
@@ -786,7 +786,7 @@ func normal(app *app) {
|
||||
app.cmdHistoryInd = 0
|
||||
app.menuCompActive = false
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menu = ""
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
@@ -995,7 +995,7 @@ func insert(app *app, arg string) {
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menu = ""
|
||||
app.menuCompActive = false
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
}
|
||||
@@ -1635,14 +1635,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
return
|
||||
}
|
||||
normal(app)
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.menu = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-load: "
|
||||
case "mark-remove":
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
return
|
||||
}
|
||||
normal(app)
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.menu = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-remove: "
|
||||
case "rename":
|
||||
if !app.nav.init {
|
||||
@@ -1824,13 +1824,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
normal(app)
|
||||
case "cmd-complete":
|
||||
matches := doComplete(app)
|
||||
app.ui.menuBuf = listMatches(app.ui.screen, matches, -1)
|
||||
app.ui.menu = listMatches(app.ui.screen, matches, -1)
|
||||
case "cmd-menu-complete":
|
||||
menuComplete(app, 1)
|
||||
case "cmd-menu-complete-back":
|
||||
menuComplete(app, -1)
|
||||
case "cmd-menu-accept":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menu = ""
|
||||
app.menuCompActive = false
|
||||
case "cmd-enter":
|
||||
s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...))
|
||||
@@ -1838,7 +1838,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menu = ""
|
||||
app.menuCompActive = false
|
||||
|
||||
app.ui.cmdAccLeft = nil
|
||||
|
||||
@@ -629,7 +629,7 @@ type ui struct {
|
||||
keyChan chan string
|
||||
tevChan chan tcell.Event
|
||||
evChan chan tcell.Event
|
||||
menuBuf *bytes.Buffer
|
||||
menu string
|
||||
cmdPrefix string
|
||||
cmdAccLeft []rune
|
||||
cmdAccRight []rune
|
||||
@@ -1095,8 +1095,8 @@ func (ui *ui) draw(nav *nav) {
|
||||
ui.drawBox()
|
||||
}
|
||||
|
||||
if ui.menuBuf != nil {
|
||||
lines := strings.Split(ui.menuBuf.String(), "\n")
|
||||
if ui.menu != "" {
|
||||
lines := strings.Split(ui.menu, "\n")
|
||||
|
||||
lines = lines[:len(lines)-1]
|
||||
|
||||
@@ -1116,7 +1116,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
}
|
||||
|
||||
ui.screen.Show()
|
||||
if ui.menuBuf == nil && ui.cmdPrefix == "" && ui.sxScreen.sixel != nil {
|
||||
if ui.menu == "" && ui.cmdPrefix == "" && ui.sxScreen.sixel != nil {
|
||||
ui.sxScreen.lastFile = ui.regPrev.path
|
||||
ui.sxScreen.showSixels()
|
||||
}
|
||||
@@ -1136,7 +1136,7 @@ func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok b
|
||||
return
|
||||
}
|
||||
|
||||
func listExprMap(binds map[string]expr, title string) *bytes.Buffer {
|
||||
func listExprMap(binds map[string]expr, title string) string {
|
||||
t := new(tabwriter.Writer)
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
@@ -1153,18 +1153,18 @@ func listExprMap(binds map[string]expr, title string) *bytes.Buffer {
|
||||
}
|
||||
t.Flush()
|
||||
|
||||
return b
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func listBinds(binds map[string]expr) *bytes.Buffer {
|
||||
func listBinds(binds map[string]expr) string {
|
||||
return listExprMap(binds, "keys")
|
||||
}
|
||||
|
||||
func listCmds() *bytes.Buffer {
|
||||
func listCmds() string {
|
||||
return listExprMap(gOpts.cmds, "name")
|
||||
}
|
||||
|
||||
func listJumps(jumps []string, ind int) *bytes.Buffer {
|
||||
func listJumps(jumps []string, ind int) string {
|
||||
t := new(tabwriter.Writer)
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
@@ -1185,10 +1185,10 @@ func listJumps(jumps []string, ind int) *bytes.Buffer {
|
||||
}
|
||||
t.Flush()
|
||||
|
||||
return b
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func listHistory(history []cmdItem) *bytes.Buffer {
|
||||
func listHistory(history []cmdItem) string {
|
||||
t := new(tabwriter.Writer)
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
@@ -1201,10 +1201,10 @@ func listHistory(history []cmdItem) *bytes.Buffer {
|
||||
}
|
||||
t.Flush()
|
||||
|
||||
return b
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func listMarks(marks map[string]string) *bytes.Buffer {
|
||||
func listMarks(marks map[string]string) string {
|
||||
t := new(tabwriter.Writer)
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
@@ -1221,7 +1221,7 @@ func listMarks(marks map[string]string) *bytes.Buffer {
|
||||
}
|
||||
t.Flush()
|
||||
|
||||
return b
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (ui *ui) pollEvent() tcell.Event {
|
||||
@@ -1320,7 +1320,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
if val == "<esc>" && len(ui.keyAcc) != 0 {
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
ui.menuBuf = nil
|
||||
ui.menu = ""
|
||||
return draw
|
||||
}
|
||||
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
||||
@@ -1337,7 +1337,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
ui.menuBuf = nil
|
||||
ui.menu = ""
|
||||
return draw
|
||||
default:
|
||||
if ok {
|
||||
@@ -1361,11 +1361,11 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
ui.menuBuf = nil
|
||||
ui.menu = ""
|
||||
return expr
|
||||
}
|
||||
if gOpts.showbinds {
|
||||
ui.menuBuf = listBinds(binds)
|
||||
ui.menu = listBinds(binds)
|
||||
}
|
||||
return draw
|
||||
}
|
||||
@@ -1414,7 +1414,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
ui.echoerrf("unknown mapping: %s", button)
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
ui.menuBuf = nil
|
||||
ui.menu = ""
|
||||
return draw
|
||||
}
|
||||
|
||||
@@ -1591,12 +1591,13 @@ func anyKey() {
|
||||
os.Stdin.Read(b)
|
||||
}
|
||||
|
||||
func listMatches(screen tcell.Screen, matches []string, selectedInd int) *bytes.Buffer {
|
||||
func listMatches(screen tcell.Screen, matches []string, selectedInd int) string {
|
||||
mlen := len(matches)
|
||||
if mlen < 2 {
|
||||
return nil
|
||||
return ""
|
||||
}
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
var b strings.Builder
|
||||
|
||||
wtot, _ := screen.Size()
|
||||
wcol := 0
|
||||
@@ -1613,13 +1614,13 @@ func listMatches(screen tcell.Screen, matches []string, selectedInd int) *bytes.
|
||||
target := matches[i]
|
||||
|
||||
if selectedInd == i {
|
||||
fmt.Fprintf(b, "\033[7m%s\033[0m%*s", target, wcol-len(target), "")
|
||||
fmt.Fprintf(&b, "\033[7m%s\033[0m%*s", target, wcol-len(target), "")
|
||||
} else {
|
||||
fmt.Fprintf(b, "%s%*s", target, wcol-len(target), "")
|
||||
fmt.Fprintf(&b, "%s%*s", target, wcol-len(target), "")
|
||||
}
|
||||
}
|
||||
b.WriteByte('\n')
|
||||
}
|
||||
|
||||
return b
|
||||
return b.String()
|
||||
}
|
||||
Reference in new issue
Block a user