8000 Customizable statusline, df by rrveex · Pull Request #1168 · gokcehan/lf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Customizable statusline, df #1168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ The following options can be used to customize the behavior of lf:
incfilter bool (default false)
incsearch bool (default false)
info []string (default '')
ruler []string (default '')
infotimefmtnew string (default 'Jan _2 15:04')
infotimefmtold string (default 'Jan _2 2006')
mouse bool (default false)
Expand Down Expand Up @@ -744,6 +745,11 @@ List of information shown for directory items at the right side of pane.
Currently supported information types are 'size', 'time', 'atime', and 'ctime'.
Information is only shown when the pane width is more than twice the width of information.

ruler []string (default 'acc:progress:selection:ind')

List of information shown in status line ruler.
Currently supported information types are 'acc', 'progress', 'selection', 'ind' and 'df'.

infotimefmtnew string (default 'Jan _2 15:04')

Format string of the file time shown in the info column when it matches this year.
Expand Down
6 changes: 6 additions & 0 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,21 @@ func (e *setExpr) eval(app *app, args []string) {
}
}
gOpts.info = toks
case "ruler":
if e.val == "" {
gOpts.ruler = nil
return
}
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "df", "acc", "progress", "selection", "ind", "tot":
default:
app.ui.echoerr("ruler: should consist of 'df', 'acc', 'progress', 'selection', or 'ind' separated with colon")
return
}
}
gOpts.ruler = toks
case "infotimefmtnew":
gOpts.infotimefmtnew = e.val
case "infotimefmtold":
Expand Down
7 changes: 7 additions & 0 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ The following options can be used to customize the behavior of lf:
incfilter bool (default false)
incsearch bool (default false)
info []string (default '')
ruler []string (default '')
infotimefmtnew string (default 'Jan _2 15:04')
infotimefmtold string (default 'Jan _2 2006')
mouse bool (default false)
Expand Down Expand Up @@ -904,6 +905,12 @@ Apply filter pattern after each keystroke during filtering.
.PP
List of information shown for directory items at the right side of pane. Currently supported information types are 'size', 'time', 'atime', and 'ctime'. Information is only shown when the pane width is more than twice the width of information.
.PP
.EX
ruler []string (default 'acc:progress:selection:ind')
.EE
.PP
List of information shown in status line ruler. Currently supported information types are 'acc', 'progress', 'selection', 'ind' and 'df'.
.PP
.EX
infotimefmtnew string (default 'Jan _2 15:04')
.EE
Expand Down
2 changes: 2 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var gOpts struct {
hiddenfiles []string
history bool
info []string
ruler []string
shellopts []string
keys map[string]expr
cmdkeys map[string]expr
Expand Down Expand Up @@ -131,6 +132,7 @@ func init() {
gOpts.hiddenfiles = []string{".*"}
gOpts.history = true
gOpts.info = nil
gOpts.ruler = []string{"acc", "progress", "selection", "ind"}
gOpts.shellopts = nil
gOpts.sortType = sortType{naturalSort, dirfirstSort}
gOpts.tempmarks = "'"
Expand Down
11 changes: 11 additions & 0 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,14 @@ 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 changes: 16 additions & 0 deletions os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,19 @@ 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))
}
17 changes: 16 additions & 1 deletion ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,22 @@ func (ui *ui) drawStatLine(nav *nav) {
progress += fmt.Sprintf(" [%d/%d]", nav.deleteCount, nav.deleteTotal)
}

ruler := fmt.Sprintf("%s%s%s %d/%d", acc, progress, selection, ind, tot)
ruler := ""
for _, s := range gOpts.ruler {
switch s {
case "df":
ruler = fmt.Sprintf("%s%s", ruler, diskFree(dir.path))
case "acc":
ruler = fmt.Sprintf("%s%s", ruler, acc)
case "progress":
ruler = fmt.Sprintf("%s%s", ruler, progress)
case "selection":
ruler = fmt.Sprintf("%s%s", ruler, selection)
case "ind":
ruler = fmt.Sprintf("%s %d/%d", ruler, ind, tot)
}

}

ui.msgWin.printRight(ui.screen, 0, st, ruler)
}
Expand Down
0