1 parent
a80900f41e
commit
0d0f7451ac
8 files changed
+72
No files matched your search
@@ -45,6 +45,8 @@ var (
|
||||
"search-back",
|
||||
"search-next",
|
||||
"search-prev",
|
||||
"mark-save",
|
||||
"mark-load",
|
||||
"sync",
|
||||
"echo",
|
||||
"cd",
|
||||
|
||||
@@ -45,6 +45,8 @@ The following commands are provided by lf with default keybindings:
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ The following commands are provided by lf with default keybindings:
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
|
||||
@@ -436,6 +436,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "mark-save":
|
||||
app.ui.cmdPrefix = "mark-save: "
|
||||
case "mark-load":
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-load: "
|
||||
case "sync":
|
||||
if err := app.nav.sync(); err != nil {
|
||||
app.ui.printf("sync: %s", err)
|
||||
@@ -483,6 +488,41 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if len(e.args) == 0 {
|
||||
return
|
||||
}
|
||||
switch app.ui.cmdPrefix {
|
||||
case "mark-save: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.marks[e.args[0]] = wd
|
||||
|
||||
return
|
||||
case "mark-load: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
|
||||
path, ok := app.nav.marks[e.args[0]]
|
||||
if !ok {
|
||||
app.ui.print("mark-load: no such mark")
|
||||
return
|
||||
}
|
||||
if err := app.nav.cd(path); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
||||
case "cmd-escape":
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
|
||||
@@ -55,6 +55,8 @@ The following commands are provided by lf with default keybindings:
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
.EE
|
||||
.PP
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
@@ -194,6 +194,7 @@ type nav struct {
|
||||
dirCache map[string]*dir
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
marks map[string]string
|
||||
selections map[string]int
|
||||
selectionInd int
|
||||
height int
|
||||
@@ -270,6 +271,7 @@ func newNav(height int) *nav {
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]string),
|
||||
selections: make(map[string]int),
|
||||
selectionInd: 0,
|
||||
height: height,
|
||||
|
||||
@@ -109,6 +109,8 @@ func init() {
|
||||
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
||||
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
|
||||
|
||||
@@ -700,6 +700,26 @@ func listBinds(binds map[string]expr) *bytes.Buffer {
|
||||
return b
|
||||
}
|
||||
|
||||
func listMarks(marks map[string]string) *bytes.Buffer {
|
||||
t := new(tabwriter.Writer)
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
var keys []string
|
||||
for k := range marks {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
|
||||
fmt.Fprintln(t, "mark\tpath")
|
||||
for _, k := range keys {
|
||||
fmt.Fprintf(t, "%s\t%s\n", k, marks[k])
|
||||
}
|
||||
t.Flush()
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
func (ui *ui) pollEvent() termbox.Event {
|
||||
select {
|
||||
case key := <-ui.keyChan:
|
||||
|
||||
Reference in new issue
Block a user