rename mark to selection
This commit is contained in:
parent
552182958a
commit
a80900f41e
6
app.go
6
app.go
@ -149,14 +149,14 @@ func (app *app) exportVars() {
|
|||||||
envFile = f.path
|
envFile = f.path
|
||||||
}
|
}
|
||||||
|
|
||||||
marks := app.nav.currMarks()
|
selections := app.nav.currSelections()
|
||||||
|
|
||||||
envFiles := strings.Join(marks, gOpts.filesep)
|
envFiles := strings.Join(selections, gOpts.filesep)
|
||||||
|
|
||||||
os.Setenv("f", envFile)
|
os.Setenv("f", envFile)
|
||||||
os.Setenv("fs", envFiles)
|
os.Setenv("fs", envFiles)
|
||||||
|
|
||||||
if len(marks) == 0 {
|
if len(selections) == 0 {
|
||||||
os.Setenv("fx", envFile)
|
os.Setenv("fx", envFile)
|
||||||
} else {
|
} else {
|
||||||
os.Setenv("fx", envFiles)
|
os.Setenv("fx", envFiles)
|
||||||
|
@ -27,7 +27,7 @@ var (
|
|||||||
"bottom",
|
"bottom",
|
||||||
"toggle",
|
"toggle",
|
||||||
"invert",
|
"invert",
|
||||||
"unmark",
|
"unselect",
|
||||||
"copy",
|
"copy",
|
||||||
"cut",
|
"cut",
|
||||||
"paste",
|
"paste",
|
||||||
|
8
doc.go
8
doc.go
@ -29,7 +29,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
bottom (default 'G' and '<end>')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unselect (default 'u')
|
||||||
copy (default 'y')
|
copy (default 'y')
|
||||||
cut (default 'd')
|
cut (default 'd')
|
||||||
paste (default 'p')
|
paste (default 'p')
|
||||||
@ -114,8 +114,8 @@ The following options can be used to customize the behavior of lf:
|
|||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
$f current file
|
$f current file
|
||||||
$fs marked file(s) separated with 'filesep'
|
$fs selected file(s) separated with 'filesep'
|
||||||
$fx current file or marked file(s) if any
|
$fx current file or selected file(s) if any
|
||||||
$id id number of the client
|
$id id number of the client
|
||||||
|
|
||||||
The following default values are set to the environmental variables on unix
|
The following default values are set to the environmental variables on unix
|
||||||
@ -340,7 +340,7 @@ trash. A first attempt to write such a command may look like this:
|
|||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
We check '$fs' to see if there are any marked files. Otherwise we just delete
|
We check '$fs' to see if there are any selected files. Otherwise we just delete
|
||||||
the current file. Since this is such a common pattern, a separate '$fx'
|
the current file. Since this is such a common pattern, a separate '$fx'
|
||||||
variable is provided. We can use this variable to get rid of the conditional:
|
variable is provided. We can use this variable to get rid of the conditional:
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
bottom (default 'G' and '<end>')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unselect (default 'u')
|
||||||
copy (default 'y')
|
copy (default 'y')
|
||||||
cut (default 'd')
|
cut (default 'd')
|
||||||
paste (default 'p')
|
paste (default 'p')
|
||||||
@ -117,8 +117,8 @@ The following options can be used to customize the behavior of lf:
|
|||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
$f current file
|
$f current file
|
||||||
$fs marked file(s) separated with 'filesep'
|
$fs selected file(s) separated with 'filesep'
|
||||||
$fx current file or marked file(s) if any
|
$fx current file or selected file(s) if any
|
||||||
$id id number of the client
|
$id id number of the client
|
||||||
|
|
||||||
The following default values are set to the environmental variables on unix
|
The following default values are set to the environmental variables on unix
|
||||||
@ -352,7 +352,7 @@ this:
|
|||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
We check '$fs' to see if there are any marked files. Otherwise we just
|
We check '$fs' to see if there are any selected files. Otherwise we just
|
||||||
delete the current file. Since this is such a common pattern, a separate
|
delete the current file. Since this is such a common pattern, a separate
|
||||||
'$fx' variable is provided. We can use this variable to get rid of the
|
'$fx' variable is provided. We can use this variable to get rid of the
|
||||||
conditional:
|
conditional:
|
||||||
|
14
eval.go
14
eval.go
@ -314,9 +314,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
var path string
|
var path string
|
||||||
if len(app.nav.marks) != 0 {
|
if len(app.nav.selections) != 0 {
|
||||||
marks := app.nav.currMarks()
|
selections := app.nav.currSelections()
|
||||||
path = strings.Join(marks, "\n")
|
path = strings.Join(selections, "\n")
|
||||||
} else if curr, err := app.nav.currFile(); err == nil {
|
} else if curr, err := app.nav.currFile(); err == nil {
|
||||||
path = curr.path
|
path = curr.path
|
||||||
} else {
|
} else {
|
||||||
@ -354,14 +354,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "invert":
|
case "invert":
|
||||||
app.nav.invert()
|
app.nav.invert()
|
||||||
case "unmark":
|
case "unselect":
|
||||||
app.nav.unmark()
|
app.nav.unselect()
|
||||||
case "copy":
|
case "copy":
|
||||||
if err := app.nav.save(true); err != nil {
|
if err := app.nav.save(true); err != nil {
|
||||||
app.ui.printf("copy: %s", err)
|
app.ui.printf("copy: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unmark()
|
app.nav.unselect()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("copy: %s", err)
|
app.ui.printf("copy: %s", err)
|
||||||
}
|
}
|
||||||
@ -370,7 +370,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.printf("cut: %s", err)
|
app.ui.printf("cut: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unmark()
|
app.nav.unselect()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("cut: %s", err)
|
app.ui.printf("cut: %s", err)
|
||||||
}
|
}
|
||||||
|
8
lf.1
8
lf.1
@ -39,7 +39,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
bottom (default 'G' and '<end>')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unselect (default 'u')
|
||||||
copy (default 'y')
|
copy (default 'y')
|
||||||
cut (default 'd')
|
cut (default 'd')
|
||||||
paste (default 'p')
|
paste (default 'p')
|
||||||
@ -131,8 +131,8 @@ The following variables are exported for shell commands:
|
|||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
$f current file
|
$f current file
|
||||||
$fs marked file(s) separated with 'filesep'
|
$fs selected file(s) separated with 'filesep'
|
||||||
$fx current file or marked file(s) if any
|
$fx current file or selected file(s) if any
|
||||||
$id id number of the client
|
$id id number of the client
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
@ -371,7 +371,7 @@ Regular shell commands are the most basic command type that is useful for many p
|
|||||||
}}
|
}}
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
We check '$fs' to see if there are any marked files. Otherwise we just delete the current file. Since this is such a common pattern, a separate '$fx' variable is provided. We can use this variable to get rid of the conditional:
|
We check '$fs' to see if there are any selected files. Otherwise we just delete the current file. Since this is such a common pattern, a separate '$fx' variable is provided. We can use this variable to get rid of the conditional:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
cmd trash ${{
|
cmd trash ${{
|
||||||
|
66
nav.go
66
nav.go
@ -194,8 +194,8 @@ type nav struct {
|
|||||||
dirCache map[string]*dir
|
dirCache map[string]*dir
|
||||||
regCache map[string]*reg
|
regCache map[string]*reg
|
||||||
saves map[string]bool
|
saves map[string]bool
|
||||||
marks map[string]int
|
selections map[string]int
|
||||||
markInd int
|
selectionInd int
|
||||||
height int
|
height int
|
||||||
search string
|
search string
|
||||||
}
|
}
|
||||||
@ -270,8 +270,8 @@ func newNav(height int) *nav {
|
|||||||
dirCache: make(map[string]*dir),
|
dirCache: make(map[string]*dir),
|
||||||
regCache: make(map[string]*reg),
|
regCache: make(map[string]*reg),
|
||||||
saves: make(map[string]bool),
|
saves: make(map[string]bool),
|
||||||
marks: make(map[string]int),
|
selections: make(map[string]int),
|
||||||
markInd: 0,
|
selectionInd: 0,
|
||||||
height: height,
|
height: height,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,13 +297,13 @@ func (nav *nav) renew() {
|
|||||||
}(d)
|
}(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
for m := range nav.marks {
|
for m := range nav.selections {
|
||||||
if _, err := os.Stat(m); os.IsNotExist(err) {
|
if _, err := os.Stat(m); os.IsNotExist(err) {
|
||||||
delete(nav.marks, m)
|
delete(nav.selections, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(nav.marks) == 0 {
|
if len(nav.selections) == 0 {
|
||||||
nav.markInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,15 +504,15 @@ func (nav *nav) bottom() {
|
|||||||
dir.pos = min(dir.ind, nav.height-1)
|
dir.pos = min(dir.ind, nav.height-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) toggleMark(path string) {
|
func (nav *nav) toggleSelection(path string) {
|
||||||
if _, ok := nav.marks[path]; ok {
|
if _, ok := nav.selections[path]; ok {
|
||||||
delete(nav.marks, path)
|
delete(nav.selections, path)
|
||||||
if len(nav.marks) == 0 {
|
if len(nav.selections) == 0 {
|
||||||
nav.markInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nav.marks[path] = nav.markInd
|
nav.selections[path] = nav.selectionInd
|
||||||
nav.markInd = nav.markInd + 1
|
nav.selectionInd++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +522,7 @@ func (nav *nav) toggle() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.toggleMark(curr.path)
|
nav.toggleSelection(curr.path)
|
||||||
|
|
||||||
nav.down(1)
|
nav.down(1)
|
||||||
}
|
}
|
||||||
@ -531,17 +531,17 @@ func (nav *nav) invert() {
|
|||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for _, f := range last.files {
|
for _, f := range last.files {
|
||||||
path := filepath.Join(last.path, f.Name())
|
path := filepath.Join(last.path, f.Name())
|
||||||
nav.toggleMark(path)
|
nav.toggleSelection(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) unmark() {
|
func (nav *nav) unselect() {
|
||||||
nav.marks = make(map[string]int)
|
nav.selections = make(map[string]int)
|
||||||
nav.markInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) save(cp bool) error {
|
func (nav *nav) save(cp bool) error {
|
||||||
if len(nav.marks) == 0 {
|
if len(nav.selections) == 0 {
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("no file selected")
|
return errors.New("no file selected")
|
||||||
@ -554,14 +554,14 @@ func (nav *nav) save(cp bool) error {
|
|||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
nav.saves[curr.path] = cp
|
nav.saves[curr.path] = cp
|
||||||
} else {
|
} else {
|
||||||
marks := nav.currMarks()
|
selections := nav.currSelections()
|
||||||
|
|
||||||
if err := saveFiles(marks, cp); err != nil {
|
if err := saveFiles(selections, cp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
for f := range nav.marks {
|
for f := range nav.selections {
|
||||||
nav.saves[f] = cp
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -730,27 +730,27 @@ func (nav *nav) currFile() (*file, error) {
|
|||||||
return last.files[last.ind], nil
|
return last.files[last.ind], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type indexedMarks struct {
|
type indexedSelections struct {
|
||||||
paths []string
|
paths []string
|
||||||
indices []int
|
indices []int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m indexedMarks) Len() int { return len(m.paths) }
|
func (m indexedSelections) Len() int { return len(m.paths) }
|
||||||
|
|
||||||
func (m indexedMarks) Swap(i, j int) {
|
func (m indexedSelections) Swap(i, j int) {
|
||||||
m.paths[i], m.paths[j] = m.paths[j], m.paths[i]
|
m.paths[i], m.paths[j] = m.paths[j], m.paths[i]
|
||||||
m.indices[i], m.indices[j] = m.indices[j], m.indices[i]
|
m.indices[i], m.indices[j] = m.indices[j], m.indices[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m indexedMarks) Less(i, j int) bool { return m.indices[i] < m.indices[j] }
|
func (m indexedSelections) Less(i, j int) bool { return m.indices[i] < m.indices[j] }
|
||||||
|
|
||||||
func (nav *nav) currMarks() []string {
|
func (nav *nav) currSelections() []string {
|
||||||
paths := make([]string, 0, len(nav.marks))
|
paths := make([]string, 0, len(nav.selections))
|
||||||
indices := make([]int, 0, len(nav.marks))
|
indices := make([]int, 0, len(nav.selections))
|
||||||
for path, index := range nav.marks {
|
for path, index := range nav.selections {
|
||||||
paths = append(paths, path)
|
paths = append(paths, path)
|
||||||
indices = append(indices, index)
|
indices = append(indices, index)
|
||||||
}
|
}
|
||||||
sort.Sort(indexedMarks{paths: paths, indices: indices})
|
sort.Sort(indexedSelections{paths: paths, indices: indices})
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
2
opts.go
2
opts.go
@ -93,7 +93,7 @@ func init() {
|
|||||||
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
||||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
||||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||||
gOpts.keys["u"] = &callExpr{"unmark", nil, 1}
|
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
||||||
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
||||||
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
|
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
|
||||||
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
||||||
|
8
ui.go
8
ui.go
@ -241,7 +241,7 @@ func fileInfo(f *file, d *dir) string {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool, colors colorMap) {
|
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap) {
|
||||||
if win.w < 5 || dir == nil {
|
if win.w < 5 || dir == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool,
|
|||||||
|
|
||||||
path := filepath.Join(dir.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
if _, ok := marks[path]; ok {
|
if _, ok := selections[path]; ok {
|
||||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||||
} else if cp, ok := saves[path]; ok {
|
} else if cp, ok := saves[path]; ok {
|
||||||
if cp {
|
if cp {
|
||||||
@ -602,7 +602,7 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
|
|
||||||
doff := len(nav.dirs) - length
|
doff := len(nav.dirs) - length
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.marks, nav.saves, ui.colors)
|
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ui.cmdPrefix {
|
switch ui.cmdPrefix {
|
||||||
@ -628,7 +628,7 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
preview := ui.wins[len(ui.wins)-1]
|
preview := ui.wins[len(ui.wins)-1]
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
preview.printDir(ui.dirPrev, nav.marks, nav.saves, ui.colors)
|
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors)
|
||||||
} else if f.Mode().IsRegular() {
|
} else if f.Mode().IsRegular() {
|
||||||
preview.printReg(ui.regPrev)
|
preview.printReg(ui.regPrev)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user