feat: add mode, user and group info parameters (#1799)

* feat: add mode, user and group info parameters

* fix: correct function names

* fix: change mode to perm
This commit is contained in:
Oscar Wallberg authored and GitHub committed 2024-09-14 00:25:26 +10:00
1 parent e9cb31f2eb
commit 1c56620f57
5 files changed
+55 -11

No files matched your search

+1 -1
View File
@@ -811,7 +811,7 @@ Apply filter pattern after each keystroke during filtering.
## info ([]string) (default ``) ## info ([]string) (default ``)
A list of information that is shown for directory items at the right side of the pane. A list of information that is shown for directory items at the right side of the pane.
Currently supported information types are `size`, `time`, `atime`, and `ctime`. Currently supported information types are `size`, `time`, `atime`, `ctime`, `perm`, `user` and `group`.
Information is only shown when the pane width is more than twice the width of information. Information is only shown when the pane width is more than twice the width of information.
## infotimefmtnew (string) (default `Jan _2 15:04`) ## infotimefmtnew (string) (default `Jan _2 15:04`)
+2 -2
View File
@@ -864,8 +864,8 @@ info ([]string) (default ``)
A list of information that is shown for directory items at the right A list of information that is shown for directory items at the right
side of the pane. Currently supported information types are size, time, side of the pane. Currently supported information types are size, time,
atime, and ctime. Information is only shown when the pane width is more atime, ctime, perm, user and group. Information is only shown when the
than twice the width of information. pane width is more than twice the width of information.
infotimefmtnew (string) (default Jan _2 15:04) infotimefmtnew (string) (default Jan _2 15:04)
+4 -4
View File
@@ -260,9 +260,9 @@ func (e *setExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":") toks := strings.Split(e.val, ":")
for _, s := range toks { for _, s := range toks {
switch s { switch s {
case "size", "time", "atime", "ctime": case "size", "time", "atime", "ctime", "perm", "user", "group":
default: default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon") app.ui.echoerr("info: should consist of 'size', 'time', 'atime', 'ctime', 'perm', 'user' or 'group' separated with colon")
return return
} }
} }
@@ -482,9 +482,9 @@ func (e *setLocalExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":") toks := strings.Split(e.val, ":")
for _, s := range toks { for _, s := range toks {
switch s { switch s {
case "size", "time", "atime", "ctime": case "size", "time", "atime", "ctime", "perm", "user", "group":
default: default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon") app.ui.echoerr("info: should consist of 'size', 'time', 'atime', 'ctime', 'perm', 'user' or 'group' separated with colon")
return return
} }
} }
+3 -2
View File
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 2.11.4 .\" Automatically generated by Pandoc 2.11.4
.\" .\"
.TH "LF" "1" "2024-07-01" "" "DOCUMENTATION" .TH "LF" "1" "2024-09-13" "" "DOCUMENTATION"
.hy .hy
.SH NAME .SH NAME
.PP .PP
@@ -882,7 +882,8 @@ Apply filter pattern after each keystroke during filtering.
A list of information that is shown for directory items at the right A list of information that is shown for directory items at the right
side of the pane. side of the pane.
Currently supported information types are \f[C]size\f[R], Currently supported information types are \f[C]size\f[R],
\f[C]time\f[R], \f[C]atime\f[R], and \f[C]ctime\f[R]. \f[C]time\f[R], \f[C]atime\f[R], \f[C]ctime\f[R], \f[C]perm\f[R],
\f[C]user\f[R] and \f[C]group\f[R].
Information is only shown when the pane width is more than twice the Information is only shown when the pane width is more than twice the
width of information. width of information.
.SS infotimefmtnew (string) (default \f[C]Jan _2 15:04\f[R]) .SS infotimefmtnew (string) (default \f[C]Jan _2 15:04\f[R])
+45 -2
View File
@@ -287,7 +287,7 @@ func infotimefmt(t time.Time) string {
return t.Format(gOpts.infotimefmtold) return t.Format(gOpts.infotimefmtold)
} }
func fileInfo(f *file, d *dir) string { func fileInfo(f *file, d *dir, userWidth int, groupWidth int) string {
var info string var info string
for _, s := range getInfo(d.path) { for _, s := range getInfo(d.path) {
@@ -320,6 +320,12 @@ func fileInfo(f *file, d *dir) string {
info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime)) info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime))
case "ctime": case "ctime":
info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime)) info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))
case "perm":
info = fmt.Sprintf("%s %s", info, f.FileInfo.Mode().String())
case "user":
info = fmt.Sprintf("%s %-*s", info, userWidth, userName(f.FileInfo))
case "group":
info = fmt.Sprintf("%s %-*s", info, groupWidth, groupName(f.FileInfo))
default: default:
log.Printf("unknown info type: %s", s) log.Printf("unknown info type: %s", s)
} }
@@ -402,6 +408,23 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
} }
} }
var userWidth int
var groupWidth int
// Only fetch user/group widths if configured to display them
for _, s := range getInfo(dir.path) {
switch s {
case "user":
userWidth = getUserWidth(dir, beg, end)
case "group":
groupWidth = getGroupWidth(dir, beg, end)
}
if userWidth > 0 && groupWidth > 0 {
break
}
}
for i, f := range dir.files[beg:end] { for i, f := range dir.files[beg:end] {
st := dirStyle.colors.get(f) st := dirStyle.colors.get(f)
@@ -461,7 +484,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
// subtract space for tag and icon // subtract space for tag and icon
maxFilenameWidth := maxWidth - 1 - runeSliceWidth(icon) maxFilenameWidth := maxWidth - 1 - runeSliceWidth(icon)
info := fileInfo(f, dir) info := fileInfo(f, dir, userWidth, groupWidth)
showInfo := len(info) > 0 && 2*len(info) < maxWidth showInfo := len(info) > 0 && 2*len(info) < maxWidth
if showInfo { if showInfo {
maxFilenameWidth -= len(info) maxFilenameWidth -= len(info)
@@ -519,6 +542,26 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
} }
} }
func getUserWidth(dir *dir, beg int, end int) int {
maxw := 0
for _, f := range dir.files[beg:end] {
maxw = max(len(userName(f.FileInfo)), maxw)
}
return maxw
}
func getGroupWidth(dir *dir, beg int, end int) int {
maxw := 0
for _, f := range dir.files[beg:end] {
maxw = max(len(groupName(f.FileInfo)), maxw)
}
return maxw
}
func getWidths(wtot int) []int { func getWidths(wtot int) []int {
rsum := 0 rsum := 0
for _, r := range gOpts.ratios { for _, r := range gOpts.ratios {