Implemented line numbers (#133)
This commit is contained in:
parent
e0e5977008
commit
90f0339fa9
@ -106,6 +106,12 @@ var (
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"number",
|
||||
"nonumber",
|
||||
"number!",
|
||||
"relativenumber",
|
||||
"norelativenumber",
|
||||
"relativenumber!",
|
||||
"findlen",
|
||||
"period",
|
||||
"scrolloff",
|
||||
|
2
doc.go
2
doc.go
@ -109,6 +109,8 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
|
@ -112,6 +112,8 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
|
12
eval.go
12
eval.go
@ -143,6 +143,18 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.wrapscan = false
|
||||
case "wrapscan!":
|
||||
gOpts.wrapscan = !gOpts.wrapscan
|
||||
case "number":
|
||||
gOpts.number = true
|
||||
case "nonumber":
|
||||
gOpts.number = false
|
||||
case "number!":
|
||||
gOpts.number = !gOpts.number
|
||||
case "relativenumber":
|
||||
gOpts.relativenumber = true
|
||||
case "norelativenumber":
|
||||
gOpts.relativenumber = false
|
||||
case "relativenumber!":
|
||||
gOpts.relativenumber = !gOpts.relativenumber
|
||||
case "findlen":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
|
2
lf.1
2
lf.1
@ -124,6 +124,8 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
|
2
opts.go
2
opts.go
@ -37,6 +37,8 @@ var gOpts struct {
|
||||
ignoredia bool
|
||||
smartdia bool
|
||||
wrapscan bool
|
||||
number bool
|
||||
relativenumber bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
|
35
ui.go
35
ui.go
@ -267,18 +267,45 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
return
|
||||
}
|
||||
|
||||
var lnwidth int = 0;
|
||||
var lnformat string = "";
|
||||
|
||||
if (gOpts.number || gOpts.relativenumber) {
|
||||
lnwidth = 1;
|
||||
for j := 10; j < len(dir.files); j *= 10 {
|
||||
lnwidth++
|
||||
}
|
||||
lnformat = fmt.Sprintf("%%%d.d ", lnwidth)
|
||||
}
|
||||
|
||||
for i, f := range dir.files[beg:end] {
|
||||
fg, bg = colors.get(f)
|
||||
|
||||
if (lnwidth > 0) {
|
||||
var ln string
|
||||
|
||||
if (gOpts.number && (!gOpts.relativenumber || i == dir.pos)) {
|
||||
ln = fmt.Sprintf(lnformat, i + 1 + beg)
|
||||
} else if (gOpts.relativenumber) {
|
||||
if (i < dir.pos) {
|
||||
ln = fmt.Sprintf(lnformat, dir.pos - i)
|
||||
} else {
|
||||
ln = fmt.Sprintf(lnformat, i - dir.pos)
|
||||
}
|
||||
}
|
||||
|
||||
win.print(0, i, termbox.ColorYellow, bg, ln)
|
||||
}
|
||||
|
||||
path := filepath.Join(dir.path, f.Name())
|
||||
|
||||
if _, ok := selections[path]; ok {
|
||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||
win.print(lnwidth, i, fg, termbox.ColorMagenta, " ")
|
||||
} else if cp, ok := saves[path]; ok {
|
||||
if cp {
|
||||
win.print(0, i, fg, termbox.ColorYellow, " ")
|
||||
win.print(lnwidth, i, fg, termbox.ColorYellow, " ")
|
||||
} else {
|
||||
win.print(0, i, fg, termbox.ColorRed, " ")
|
||||
win.print(lnwidth, i, fg, termbox.ColorRed, " ")
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,7 +348,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
|
||||
s = append(s, ' ')
|
||||
|
||||
win.print(1, i, fg, bg, string(s))
|
||||
win.print(lnwidth+1, i, fg, bg, string(s))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user