Customizable statusline, df (#1168)

* opts statusline, df

* renamed infostat -> ruler; removed os_lin, os_bsd

* removed vscode

---------

Co-authored-by: rr <rr@arveex.eu>
This commit is contained in:
rrveexandrr authored and GitHub committed 2023-04-09 14:50:34 +03:00
1 parent 821b2fcd51
commit eb84772032
8 files changed
+79 -1

No files matched your search

+6
View File
@@ -140,6 +140,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)
@@ -750,6 +751,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.
+6
View File
@@ -143,6 +143,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)
@@ -794,6 +795,11 @@ 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
+15
View File
@@ -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":
+7
View File
@@ -159,6 +159,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)
@@ -909,6 +910,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
+2
View File
@@ -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
@@ -132,6 +133,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 = "'"
+11
View File
@@ -230,3 +230,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
View File
@@ -184,3 +184,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))
}
+16 -1
View File
@@ -859,7 +859,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)
}