Implemented line numbers (#133)

This commit is contained in:
Tomáš Martiček 2019-01-27 15:31:29 +01:00 committed by gokcehan
parent e0e5977008
commit 90f0339fa9
7 changed files with 173 additions and 120 deletions

View File

@ -106,6 +106,12 @@ var (
"wrapscan", "wrapscan",
"nowrapscan", "nowrapscan",
"wrapscan!", "wrapscan!",
"number",
"nonumber",
"number!",
"relativenumber",
"norelativenumber",
"relativenumber!",
"findlen", "findlen",
"period", "period",
"scrolloff", "scrolloff",

60
doc.go
View File

@ -94,35 +94,37 @@ keybindings:
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
anchorfind boolean (default on) anchorfind boolean (default on)
color256 boolean (default off) color256 boolean (default off)
dircounts boolean (default off) dircounts boolean (default off)
dirfirst boolean (default on) dirfirst boolean (default on)
drawbox boolean (default off) drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
incsearch boolean (default off) incsearch boolean (default off)
preview boolean (default on) preview boolean (default on)
reverse boolean (default off) reverse boolean (default off)
smartcase boolean (default on) smartcase boolean (default on)
smartdia boolean (default off) smartdia boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
findlen integer (default 1) (zero to prompt until single match) number boolean (default off)
period integer (default 0) (zero to disable periodic loading) relativenumber boolean (default off)
scrolloff integer (default 0) findlen integer (default 1) (zero to prompt until single match)
tabstop integer (default 8) period integer (default 0) (zero to disable periodic loading)
filesep string (default "\n") scrolloff integer (default 0)
ifs string (default '') (not exported if empty) tabstop integer (default 8)
previewer string (default '') (not filtered if empty) filesep string (default "\n")
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m") ifs string (default '') (not exported if empty)
shell string (default 'sh') previewer string (default '') (not filtered if empty)
sortby string (default 'natural') promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
timefmt string (default 'Mon Jan _2 15:04:05 2006') shell string (default 'sh')
ratios string (default '1:2:3') sortby string (default 'natural')
info string (default '') timefmt string (default 'Mon Jan _2 15:04:05 2006')
shellopts string (default '') ratios string (default '1:2:3')
info string (default '')
shellopts string (default '')
The following variables are exported for shell commands: The following variables are exported for shell commands:

View File

@ -97,35 +97,37 @@ keybindings:
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
anchorfind boolean (default on) anchorfind boolean (default on)
color256 boolean (default off) color256 boolean (default off)
dircounts boolean (default off) dircounts boolean (default off)
dirfirst boolean (default on) dirfirst boolean (default on)
drawbox boolean (default off) drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
incsearch boolean (default off) incsearch boolean (default off)
preview boolean (default on) preview boolean (default on)
reverse boolean (default off) reverse boolean (default off)
smartcase boolean (default on) smartcase boolean (default on)
smartdia boolean (default off) smartdia boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
findlen integer (default 1) (zero to prompt until single match) number boolean (default off)
period integer (default 0) (zero to disable periodic loading) relativenumber boolean (default off)
scrolloff integer (default 0) findlen integer (default 1) (zero to prompt until single match)
tabstop integer (default 8) period integer (default 0) (zero to disable periodic loading)
filesep string (default "\n") scrolloff integer (default 0)
ifs string (default '') (not exported if empty) tabstop integer (default 8)
previewer string (default '') (not filtered if empty) filesep string (default "\n")
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m") ifs string (default '') (not exported if empty)
shell string (default 'sh') previewer string (default '') (not filtered if empty)
sortby string (default 'natural') promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
timefmt string (default 'Mon Jan _2 15:04:05 2006') shell string (default 'sh')
ratios string (default '1:2:3') sortby string (default 'natural')
info string (default '') timefmt string (default 'Mon Jan _2 15:04:05 2006')
shellopts string (default '') ratios string (default '1:2:3')
info string (default '')
shellopts string (default '')
The following variables are exported for shell commands: The following variables are exported for shell commands:

12
eval.go
View File

@ -143,6 +143,18 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.wrapscan = false gOpts.wrapscan = false
case "wrapscan!": case "wrapscan!":
gOpts.wrapscan = !gOpts.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": case "findlen":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {

60
lf.1
View File

@ -109,35 +109,37 @@ The following command line commands are provided by lf with default keybindings:
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
.PP .PP
.EX .EX
anchorfind boolean (default on) anchorfind boolean (default on)
color256 boolean (default off) color256 boolean (default off)
dircounts boolean (default off) dircounts boolean (default off)
dirfirst boolean (default on) dirfirst boolean (default on)
drawbox boolean (default off) drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
incsearch boolean (default off) incsearch boolean (default off)
preview boolean (default on) preview boolean (default on)
reverse boolean (default off) reverse boolean (default off)
smartcase boolean (default on) smartcase boolean (default on)
smartdia boolean (default off) smartdia boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
findlen integer (default 1) (zero to prompt until single match) number boolean (default off)
period integer (default 0) (zero to disable periodic loading) relativenumber boolean (default off)
scrolloff integer (default 0) findlen integer (default 1) (zero to prompt until single match)
tabstop integer (default 8) period integer (default 0) (zero to disable periodic loading)
filesep string (default "\en") scrolloff integer (default 0)
ifs string (default '') (not exported if empty) tabstop integer (default 8)
previewer string (default '') (not filtered if empty) filesep string (default "\en")
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m") ifs string (default '') (not exported if empty)
shell string (default 'sh') previewer string (default '') (not filtered if empty)
sortby string (default 'natural') promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
timefmt string (default 'Mon Jan _2 15:04:05 2006') shell string (default 'sh')
ratios string (default '1:2:3') sortby string (default 'natural')
info string (default '') timefmt string (default 'Mon Jan _2 15:04:05 2006')
shellopts string (default '') ratios string (default '1:2:3')
info string (default '')
shellopts string (default '')
.EE .EE
.PP .PP
The following variables are exported for shell commands: The following variables are exported for shell commands:

60
opts.go
View File

@ -25,35 +25,37 @@ type sortType struct {
} }
var gOpts struct { var gOpts struct {
anchorfind bool anchorfind bool
color256 bool color256 bool
dircounts bool dircounts bool
drawbox bool drawbox bool
globsearch bool globsearch bool
ignorecase bool ignorecase bool
incsearch bool incsearch bool
preview bool preview bool
smartcase bool smartcase bool
ignoredia bool ignoredia bool
smartdia bool smartdia bool
wrapscan bool wrapscan bool
findlen int number bool
period int relativenumber bool
scrolloff int findlen int
tabstop int period int
filesep string scrolloff int
ifs string tabstop int
previewer string filesep string
promptfmt string ifs string
shell string previewer string
timefmt string promptfmt string
ratios []int shell string
info []string timefmt string
shellopts []string ratios []int
keys map[string]expr info []string
cmdkeys map[string]expr shellopts []string
cmds map[string]expr keys map[string]expr
sortType sortType cmdkeys map[string]expr
cmds map[string]expr
sortType sortType
} }
func init() { func init() {

35
ui.go
View File

@ -267,18 +267,45 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
return 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] { for i, f := range dir.files[beg:end] {
fg, bg = colors.get(f) 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()) path := filepath.Join(dir.path, f.Name())
if _, ok := selections[path]; ok { 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 { } else if cp, ok := saves[path]; ok {
if cp { if cp {
win.print(0, i, fg, termbox.ColorYellow, " ") win.print(lnwidth, i, fg, termbox.ColorYellow, " ")
} else { } 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, ' ') s = append(s, ' ')
win.print(1, i, fg, bg, string(s)) win.print(lnwidth+1, i, fg, bg, string(s))
} }
} }