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
|
||||
}
|
||||
|
||||
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("fs", envFiles)
|
||||
|
||||
if len(marks) == 0 {
|
||||
if len(selections) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
|
@ -27,7 +27,7 @@ var (
|
||||
"bottom",
|
||||
"toggle",
|
||||
"invert",
|
||||
"unmark",
|
||||
"unselect",
|
||||
"copy",
|
||||
"cut",
|
||||
"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>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unmark (default 'u')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
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:
|
||||
|
||||
$f current file
|
||||
$fs marked file(s) separated with 'filesep'
|
||||
$fx current file or marked file(s) if any
|
||||
$fs selected file(s) separated with 'filesep'
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
|
||||
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
|
||||
}}
|
||||
|
||||
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'
|
||||
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>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unmark (default 'u')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
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:
|
||||
|
||||
$f current file
|
||||
$fs marked file(s) separated with 'filesep'
|
||||
$fx current file or marked file(s) if any
|
||||
$fs selected file(s) separated with 'filesep'
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
|
||||
The following default values are set to the environmental variables on unix
|
||||
@ -352,7 +352,7 @@ this:
|
||||
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
|
||||
'$fx' variable is provided. We can use this variable to get rid of the
|
||||
conditional:
|
||||
|
14
eval.go
14
eval.go
@ -314,9 +314,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
defer out.Close()
|
||||
|
||||
var path string
|
||||
if len(app.nav.marks) != 0 {
|
||||
marks := app.nav.currMarks()
|
||||
path = strings.Join(marks, "\n")
|
||||
if len(app.nav.selections) != 0 {
|
||||
selections := app.nav.currSelections()
|
||||
path = strings.Join(selections, "\n")
|
||||
} else if curr, err := app.nav.currFile(); err == nil {
|
||||
path = curr.path
|
||||
} else {
|
||||
@ -354,14 +354,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "invert":
|
||||
app.nav.invert()
|
||||
case "unmark":
|
||||
app.nav.unmark()
|
||||
case "unselect":
|
||||
app.nav.unselect()
|
||||
case "copy":
|
||||
if err := app.nav.save(true); err != nil {
|
||||
app.ui.printf("copy: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.unmark()
|
||||
app.nav.unselect()
|
||||
if err := sendRemote("send sync"); err != nil {
|
||||
app.ui.printf("copy: %s", err)
|
||||
}
|
||||
@ -370,7 +370,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.printf("cut: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.unmark()
|
||||
app.nav.unselect()
|
||||
if err := sendRemote("send sync"); err != nil {
|
||||
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>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unmark (default 'u')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
@ -131,8 +131,8 @@ The following variables are exported for shell commands:
|
||||
.PP
|
||||
.EX
|
||||
$f current file
|
||||
$fs marked file(s) separated with 'filesep'
|
||||
$fx current file or marked file(s) if any
|
||||
$fs selected file(s) separated with 'filesep'
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
.EE
|
||||
.PP
|
||||
@ -371,7 +371,7 @@ Regular shell commands are the most basic command type that is useful for many p
|
||||
}}
|
||||
.EE
|
||||
.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
|
||||
.EX
|
||||
cmd trash ${{
|
||||
|
94
nav.go
94
nav.go
@ -188,16 +188,16 @@ func (dir *dir) find(name string, height int) {
|
||||
}
|
||||
|
||||
type nav struct {
|
||||
dirs []*dir
|
||||
dirChan chan *dir
|
||||
regChan chan *reg
|
||||
dirCache map[string]*dir
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
marks map[string]int
|
||||
markInd int
|
||||
height int
|
||||
search string
|
||||
dirs []*dir
|
||||
dirChan chan *dir
|
||||
regChan chan *reg
|
||||
dirCache map[string]*dir
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
selections map[string]int
|
||||
selectionInd int
|
||||
height int
|
||||
search string
|
||||
}
|
||||
|
||||
func (nav *nav) loadDir(path string) *dir {
|
||||
@ -265,14 +265,14 @@ func newNav(height int) *nav {
|
||||
}
|
||||
|
||||
nav := &nav{
|
||||
dirChan: make(chan *dir),
|
||||
regChan: make(chan *reg),
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]int),
|
||||
markInd: 0,
|
||||
height: height,
|
||||
dirChan: make(chan *dir),
|
||||
regChan: make(chan *reg),
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
selections: make(map[string]int),
|
||||
selectionInd: 0,
|
||||
height: height,
|
||||
}
|
||||
|
||||
nav.getDirs(wd)
|
||||
@ -297,13 +297,13 @@ func (nav *nav) renew() {
|
||||
}(d)
|
||||
}
|
||||
|
||||
for m := range nav.marks {
|
||||
for m := range nav.selections {
|
||||
if _, err := os.Stat(m); os.IsNotExist(err) {
|
||||
delete(nav.marks, m)
|
||||
delete(nav.selections, m)
|
||||
}
|
||||
}
|
||||
if len(nav.marks) == 0 {
|
||||
nav.markInd = 0
|
||||
if len(nav.selections) == 0 {
|
||||
nav.selectionInd = 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -504,15 +504,15 @@ func (nav *nav) bottom() {
|
||||
dir.pos = min(dir.ind, nav.height-1)
|
||||
}
|
||||
|
||||
func (nav *nav) toggleMark(path string) {
|
||||
if _, ok := nav.marks[path]; ok {
|
||||
delete(nav.marks, path)
|
||||
if len(nav.marks) == 0 {
|
||||
nav.markInd = 0
|
||||
func (nav *nav) toggleSelection(path string) {
|
||||
if _, ok := nav.selections[path]; ok {
|
||||
delete(nav.selections, path)
|
||||
if len(nav.selections) == 0 {
|
||||
nav.selectionInd = 0
|
||||
}
|
||||
} else {
|
||||
nav.marks[path] = nav.markInd
|
||||
nav.markInd = nav.markInd + 1
|
||||
nav.selections[path] = nav.selectionInd
|
||||
nav.selectionInd++
|
||||
}
|
||||
}
|
||||
|
||||
@ -522,7 +522,7 @@ func (nav *nav) toggle() {
|
||||
return
|
||||
}
|
||||
|
||||
nav.toggleMark(curr.path)
|
||||
nav.toggleSelection(curr.path)
|
||||
|
||||
nav.down(1)
|
||||
}
|
||||
@ -531,17 +531,17 @@ func (nav *nav) invert() {
|
||||
last := nav.currDir()
|
||||
for _, f := range last.files {
|
||||
path := filepath.Join(last.path, f.Name())
|
||||
nav.toggleMark(path)
|
||||
nav.toggleSelection(path)
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) unmark() {
|
||||
nav.marks = make(map[string]int)
|
||||
nav.markInd = 0
|
||||
func (nav *nav) unselect() {
|
||||
nav.selections = make(map[string]int)
|
||||
nav.selectionInd = 0
|
||||
}
|
||||
|
||||
func (nav *nav) save(cp bool) error {
|
||||
if len(nav.marks) == 0 {
|
||||
if len(nav.selections) == 0 {
|
||||
curr, err := nav.currFile()
|
||||
if err != nil {
|
||||
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[curr.path] = cp
|
||||
} else {
|
||||
marks := nav.currMarks()
|
||||
selections := nav.currSelections()
|
||||
|
||||
if err := saveFiles(marks, cp); err != nil {
|
||||
if err := saveFiles(selections, cp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nav.saves = make(map[string]bool)
|
||||
for f := range nav.marks {
|
||||
for f := range nav.selections {
|
||||
nav.saves[f] = cp
|
||||
}
|
||||
}
|
||||
@ -730,27 +730,27 @@ func (nav *nav) currFile() (*file, error) {
|
||||
return last.files[last.ind], nil
|
||||
}
|
||||
|
||||
type indexedMarks struct {
|
||||
type indexedSelections struct {
|
||||
paths []string
|
||||
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.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 {
|
||||
paths := make([]string, 0, len(nav.marks))
|
||||
indices := make([]int, 0, len(nav.marks))
|
||||
for path, index := range nav.marks {
|
||||
func (nav *nav) currSelections() []string {
|
||||
paths := make([]string, 0, len(nav.selections))
|
||||
indices := make([]int, 0, len(nav.selections))
|
||||
for path, index := range nav.selections {
|
||||
paths = append(paths, path)
|
||||
indices = append(indices, index)
|
||||
}
|
||||
sort.Sort(indexedMarks{paths: paths, indices: indices})
|
||||
sort.Sort(indexedSelections{paths: paths, indices: indices})
|
||||
return paths
|
||||
}
|
||||
|
2
opts.go
2
opts.go
@ -93,7 +93,7 @@ func init() {
|
||||
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
||||
gOpts.keys["<space>"] = &callExpr{"toggle", 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["d"] = &callExpr{"cut", 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
|
||||
}
|
||||
|
||||
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 {
|
||||
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())
|
||||
|
||||
if _, ok := marks[path]; ok {
|
||||
if _, ok := selections[path]; ok {
|
||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||
} else if cp, ok := saves[path]; ok {
|
||||
if cp {
|
||||
@ -602,7 +602,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
|
||||
doff := len(nav.dirs) - length
|
||||
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 {
|
||||
@ -628,7 +628,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
preview := ui.wins[len(ui.wins)-1]
|
||||
|
||||
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() {
|
||||
preview.printReg(ui.regPrev)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user