Compare commits

8 Commits
Author SHA1 Message Date
Joe Lim 88b3c999af Fix count when parsing bottom command (#1240)
* Fix count when parsing `bottom` command

* Revert "Fix count when parsing `bottom` command"

This reverts commit a0b6bb5a13.

* Alternate implementation

* Add comment
2023-05-13 16:58:21 +03:00
Joe Lim 24e224ca65 Add jumps command for displaying the jump list (#1233)
* Add `jumps` command for displaying the jump list

* Mention jump count in documentation

* Reverse order
2023-05-13 16:43:08 +03:00
Joe Lim 2a5c54c81a Minor cleanup of reflect code (#1229) 2023-05-13 16:30:19 +03:00
dependabot[bot] db46fb2b37 Bump golang.org/x/term from 0.7.0 to 0.8.0 (#1225)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.7.0 to 0.8.0.
- [Commits](https://github.com/golang/term/compare/v0.7.0...v0.8.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-13 16:28:33 +03:00
dependabot[bot] f036e07a5c Bump golang.org/x/sys from 0.7.0 to 0.8.0 (#1224)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.7.0 to 0.8.0.
- [Commits](https://github.com/golang/sys/compare/v0.7.0...v0.8.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-13 16:18:31 +03:00
Joe Lim 8f630e0cab Separate filter from selections in the ui ruler (#1223) 2023-05-13 14:19:50 +03:00
Joe Lim 35990bed12 Prevent scrolling to bottom when selecting files (#1222)
* Prevent scrolling to bottom when selecting files

* Use nav.currDir()
2023-05-13 13:58:03 +03:00
Gokcehan f04401ba4d build diskfree on all platforms
cc #1168
2023-04-30 22:10:15 +03:00
17 changed files with 195 additions and 64 deletions

No files matched your search

+1
View File
@@ -29,6 +29,7 @@ var (
"open",
"jump-next",
"jump-prev",
"jumps",
"top",
"bottom",
"high",
+19
View File
@@ -0,0 +1,19 @@
package main
import (
"log"
"golang.org/x/sys/unix"
)
func diskFree(wd string) string {
var stat unix.Statfs_t
if err := unix.Statfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
return ""
}
// Available blocks * size per block = available space in bytes
return "df: " + humanize(int64(uint64(stat.F_bavail)*uint64(stat.F_bsize)))
}
+21
View File
@@ -0,0 +1,21 @@
//go:build darwin || dragonfly || freebsd || linux
package main
import (
"log"
"golang.org/x/sys/unix"
)
func diskFree(wd string) string {
var stat unix.Statfs_t
if err := unix.Statfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
return ""
}
// Available blocks * size per block = available space in bytes
return "df: " + humanize(int64(uint64(stat.Bavail)*uint64(stat.Bsize)))
}
+21
View File
@@ -0,0 +1,21 @@
//go:build illumos || netbsd || solaris
package main
import (
"log"
"golang.org/x/sys/unix"
)
func diskFree(wd string) string {
var stat unix.Statvfs_t
if err := unix.Statvfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
return ""
}
// Available blocks * size per block = available space in bytes
return "df: " + humanize(int64(uint64(stat.Bavail)*uint64(stat.Bsize)))
}
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"log"
"golang.org/x/sys/windows"
)
func diskFree(wd string) string {
var free uint64
pathPtr, err := windows.UTF16PtrFromString(wd)
if err != nil {
log.Printf("diskfree: %s", err)
return ""
}
err = windows.GetDiskFreeSpaceEx(pathPtr, &free, nil, nil) // cwd, free, total, available
if err != nil {
log.Printf("diskfree: %s", err)
return ""
}
return "df: " + humanize(int64(free))
}
+15 -2
View File
@@ -81,6 +81,7 @@ The following commands are provided by lf:
tag-toggle (default 't')
maps
cmaps
jumps
The following command line commands are provided by lf:
@@ -152,7 +153,7 @@ The following options can be used to customize the behavior of lf:
ratios []int (default '1:2:3')
relativenumber bool (default false)
reverse bool (default false)
ruler []string (default 'acc:progress:selection:ind')
ruler []string (default 'acc:progress:selection:filter:ind')
scrolloff int (default 0)
selmode string (default 'all')
shell string (default 'sh' for Unix and 'cmd' for Windows)
@@ -613,6 +614,12 @@ Capitalize/uppercase/lowercase the current word and jump to the next word.
List all key mappings in normal mode or command-line editing mode.
jumps
List the contents of the jump list, in order of the most recently visited locations.
Each location is marked with the count that can be used with the `jump-prev` and `jump-next` commands (e.g. use `3[` to move three spaces backwards in the jump list).
A '>' is used to mark the current location in the jump list.
# Options
This section shows information about options to customize the behavior.
@@ -819,10 +826,16 @@ When 'number' is enabled, current line shows the absolute position, otherwise no
Reverse the direction of sort.
ruler []string (default 'acc:progress:selection:ind')
ruler []string (default 'acc:progress:selection:filter:ind')
List of information shown in status line ruler.
Currently supported information types are 'acc', 'progress', 'selection', 'ind' and 'df'.
`acc` shows the pressed keys (e.g. for bindings with multiple key presses or counts given to bindings).
`progress` shows the progress of file operations (e.g. copying a large directory).
`selection` shows the number of files that are selected, or designated for being cut/copied.
`filter` shows 'F' if a filter is currently being applied.
`ind` shows the current position of the cursor as well as the number of files in the current directory.
`df` shows the amount of free disk space remaining.
selmode string (default 'all')
+19 -3
View File
@@ -84,6 +84,7 @@ The following commands are provided by lf:
tag-toggle (default 't')
maps
cmaps
jumps
The following command line commands are provided by lf:
@@ -155,7 +156,7 @@ The following options can be used to customize the behavior of lf:
ratios []int (default '1:2:3')
relativenumber bool (default false)
reverse bool (default false)
ruler []string (default 'acc:progress:selection:ind')
ruler []string (default 'acc:progress:selection:filter:ind')
scrolloff int (default 0)
selmode string (default 'all')
shell string (default 'sh' for Unix and 'cmd' for Windows)
@@ -641,6 +642,14 @@ Capitalize/uppercase/lowercase the current word and jump to the next word.
List all key mappings in normal mode or command-line editing mode.
jumps
List the contents of the jump list, in order of the most recently visited
locations. Each location is marked with the count that can be used with the
'jump-prev' and 'jump-next' commands (e.g. use '3[' to move three spaces
backwards in the jump list). A '>' is used to mark the current location in the
jump list.
# Options
This section shows information about options to customize the behavior.
@@ -874,10 +883,17 @@ current line shows the absolute position, otherwise nothing is shown.
Reverse the direction of sort.
ruler []string (default 'acc:progress:selection:ind')
ruler []string (default 'acc:progress:selection:filter:ind')
List of information shown in status line ruler. Currently supported information
types are 'acc', 'progress', 'selection', 'ind' and 'df'.
types are 'acc', 'progress', 'selection', 'ind' and 'df'. 'acc' shows the
pressed keys (e.g. for bindings with multiple key presses or counts given to
bindings). 'progress' shows the progress of file operations (e.g. copying a
large directory). 'selection' shows the number of files that are selected,
or designated for being cut/copied. 'filter' shows 'F' if a filter is currently
being applied. 'ind' shows the current position of the cursor as well as the
number of files in the current directory. 'df' shows the amount of free disk
space remaining.
selmode string (default 'all')
+11 -4
View File
@@ -490,9 +490,9 @@ func (e *setExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "df", "acc", "progress", "selection", "ind":
case "df", "acc", "progress", "selection", "filter", "ind":
default:
app.ui.echoerr("ruler: should consist of 'df', 'acc', 'progress', 'selection', or 'ind' separated with colon")
app.ui.echoerr("ruler: should consist of 'df', 'acc', 'progress', 'selection', 'filter' or 'ind' separated with colon")
return
}
}
@@ -1447,7 +1447,7 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
var moved bool
if e.count == 0 {
if e.count == 1 {
moved = app.nav.top()
} else {
moved = app.nav.move(e.count - 1)
@@ -1461,7 +1461,9 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
var moved bool
if e.count == 0 {
if e.count == 1 {
// Different from Vim, which would treat a count of 1 as meaning to
// move to the first line (i.e. the top)
moved = app.nav.bottom()
} else {
moved = app.nav.move(e.count - 1)
@@ -2509,6 +2511,11 @@ func (e *callExpr) eval(app *app, args []string) {
io.Copy(app.cmdIn, listBinds(gOpts.cmdkeys))
app.cmdIn.Close()
cleanUp()
case "jumps":
cleanUp := app.runShell(envPager, nil, "$|")
io.Copy(app.cmdIn, listJumps(app.nav.jumpList, app.nav.jumpListInd))
app.cmdIn.Close()
cleanUp()
default:
cmd, ok := gOpts.cmds[e.name]
if !ok {
+2 -2
View File
@@ -6,8 +6,8 @@ require (
github.com/djherbis/times v1.5.0
github.com/gdamore/tcell/v2 v2.6.0
github.com/mattn/go-runewidth v0.0.14
golang.org/x/sys v0.7.0
golang.org/x/term v0.7.0
golang.org/x/sys v0.8.0
golang.org/x/term v0.8.0
)
require (
+4 -4
View File
@@ -26,13 +26,13 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+10 -3
View File
@@ -96,6 +96,7 @@ The following commands are provided by lf:
tag-toggle (default 't')
maps
cmaps
jumps
.EE
.PP
The following command line commands are provided by lf:
@@ -171,7 +172,7 @@ The following options can be used to customize the behavior of lf:
ratios []int (default '1:2:3')
relativenumber bool (default false)
reverse bool (default false)
ruler []string (default 'acc:progress:selection:ind')
ruler []string (default 'acc:progress:selection:filter:ind')
scrolloff int (default 0)
selmode string (default 'all')
shell string (default 'sh' for Unix and 'cmd' for Windows)
@@ -754,6 +755,12 @@ Capitalize/uppercase/lowercase the current word and jump to the next word.
.EE
.PP
List all key mappings in normal mode or command-line editing mode.
.PP
.EX
jumps
.EE
.PP
List the contents of the jump list, in order of the most recently visited locations. Each location is marked with the count that can be used with the `jump-prev` and `jump-next` commands (e.g. use `3[` to move three spaces backwards in the jump list). A '>' is used to mark the current location in the jump list.
.SH OPTIONS
This section shows information about options to customize the behavior. Character ':' is used as the separator for list options '[]int' and '[]string'.
.PP
@@ -984,10 +991,10 @@ Show the position number relative to the current line. When 'number' is enabled,
Reverse the direction of sort.
.PP
.EX
ruler []string (default 'acc:progress:selection:ind')
ruler []string (default 'acc:progress:selection:filter:ind')
.EE
.PP
List of information shown in status line ruler. Currently supported information types are 'acc', 'progress', 'selection', 'ind' and 'df'.
List of information shown in status line ruler. Currently supported information types are 'acc', 'progress', 'selection', 'ind' and 'df'. `acc` shows the pressed keys (e.g. for bindings with multiple key presses or counts given to bindings). `progress` shows the progress of file operations (e.g. copying a large directory). `selection` shows the number of files that are selected, or designated for being cut/copied. `filter` shows 'F' if a filter is currently being applied. `ind` shows the current position of the cursor as well as the number of files in the current directory. `df` shows the amount of free disk space remaining.
.PP
.EX
selmode string (default 'all')
+6 -7
View File
@@ -116,12 +116,12 @@ func fieldToString(field reflect.Value) string {
}
func exportOpts() {
e := reflect.ValueOf(&gOpts).Elem()
v := reflect.ValueOf(gOpts)
t := v.Type()
for i := 0; i < e.NumField(); i++ {
// Get name and prefix it with lf_
name := e.Type().Field(i).Name
name = fmt.Sprintf("lf_%s", name)
for i := 0; i < v.NumField(); i++ {
// Get field name and prefix it with lf_
name := "lf_" + t.Field(i).Name
// Skip maps
if name == "lf_keys" || name == "lf_cmdkeys" || name == "lf_cmds" {
@@ -165,9 +165,8 @@ func exportOpts() {
os.Setenv(name+"_"+key, value)
}
} else {
field := e.Field(i)
field := v.Field(i)
value := fieldToString(field)
os.Setenv(name, value)
}
}
+10 -3
View File
@@ -486,7 +486,9 @@ func (nav *nav) getDirs(wd string) {
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
dir := nav.loadDir(curr)
dir.sel(base, nav.height)
if base != "" {
dir.sel(base, nav.height)
}
dirs = append(dirs, dir)
}
@@ -1540,13 +1542,18 @@ func (nav *nav) sel(path string) error {
base := filepath.Base(path)
last := nav.dirs[len(nav.dirs)-1]
last := nav.currDir()
if last.loading {
last.files = append(last.files, &file{FileInfo: lstat})
}
last.sel(base, nav.height)
for i, f := range last.files {
if f.Name() == base {
nav.move(i)
break
}
}
return nil
}
+5 -5
View File
@@ -133,7 +133,7 @@ func init() {
gOpts.hiddenfiles = []string{".*"}
gOpts.history = true
gOpts.info = nil
gOpts.ruler = []string{"acc", "progress", "selection", "ind"}
gOpts.ruler = []string{"acc", "progress", "selection", "filter", "ind"}
gOpts.shellopts = nil
gOpts.sortType = sortType{naturalSort, dirfirstSort}
gOpts.tempmarks = "'"
@@ -163,10 +163,10 @@ func init() {
gOpts.keys["l"] = &callExpr{"open", nil, 1}
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
gOpts.keys["gg"] = &callExpr{"top", nil, 0}
gOpts.keys["<home>"] = &callExpr{"top", nil, 0}
gOpts.keys["G"] = &callExpr{"bottom", nil, 0}
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 0}
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
gOpts.keys["H"] = &callExpr{"high", nil, 1}
gOpts.keys["M"] = &callExpr{"middle", nil, 1}
gOpts.keys["L"] = &callExpr{"low", nil, 1}
-11
View File
@@ -230,14 +230,3 @@ func exportFiles(f string, fs []string, pwd string) {
os.Setenv("fx", envFiles)
}
}
func diskFree(wd string) string {
var stat unix.Statfs_t
if err := unix.Statfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
return ""
}
// Available blocks * size per block = available space in bytes
return "df: " + humanize(int64(uint64(stat.Bavail)*uint64(stat.Bsize)))
}
-16
View File
@@ -184,19 +184,3 @@ func exportFiles(f string, fs []string, pwd string) {
os.Setenv("fx", envFiles)
}
}
func diskFree(wd string) string {
var free uint64
pathPtr, err := windows.UTF16PtrFromString(wd)
if err != nil {
log.Printf("diskfree: %s", err)
return ""
}
err = windows.GetDiskFreeSpaceEx(pathPtr, &free, nil, nil) // cwd, free, total, available
if err != nil {
log.Printf("diskfree: %s", err)
return ""
}
return "df: " + humanize(int64(free))
}
+28 -4
View File
@@ -840,10 +840,6 @@ func (ui *ui) drawStatLine(nav *nav) {
selection = append(selection, fmt.Sprintf("\033[35;7m %d \033[0m", len(currSelections)))
}
if len(dir.filter) != 0 {
selection = append(selection, "\033[34;7m F \033[0m")
}
progress := []string{}
if nav.copyTotal > 0 {
@@ -873,6 +869,10 @@ func (ui *ui) drawStatLine(nav *nav) {
ruler = append(ruler, progress...)
case "selection":
ruler = append(ruler, selection...)
case "filter":
if len(dir.filter) != 0 {
ruler = append(ruler, "\033[34;7m F \033[0m")
}
case "ind":
ruler = append(ruler, fmt.Sprintf("%d/%d", ind, tot))
}
@@ -1056,6 +1056,30 @@ func listBinds(binds map[string]expr) *bytes.Buffer {
return b
}
func listJumps(jumps []string, ind int) *bytes.Buffer {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)
maxlength := len(strconv.Itoa(max(ind, len(jumps)-1-ind)))
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
fmt.Fprintln(t, " jump\tpath")
// print jumps in order of most recent, Vim uses the opposite order
for i := len(jumps) - 1; i >= 0; i-- {
switch {
case i < ind:
fmt.Fprintf(t, " %*d\t%s\n", maxlength, ind-i, jumps[i])
case i > ind:
fmt.Fprintf(t, " %*d\t%s\n", maxlength, i-ind, jumps[i])
default:
fmt.Fprintf(t, "> %*d\t%s\n", maxlength, 0, jumps[i])
}
}
t.Flush()
return b
}
func listMarks(marks map[string]string) *bytes.Buffer {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)