Skip to content
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

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

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ Apply filter pattern after each keystroke during filtering.
## info ([]string) (default ``)

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`, `mode`, `user` and `group`.
Copy link
Collaborator

@joelim-work joelim-work Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, do you think instead of using mode, something like perm or permissions is more intuitive as the name here? Might be a good idea to check what other file managers are using.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, I will change it to perm.

Information is only shown when the pane width is more than twice the width of information.

## infotimefmtnew (string) (default `Jan _2 15:04`)
Expand Down
4 changes: 2 additions & 2 deletions doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ info ([]string) (default ``)

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. Information is only shown when the pane width is more
than twice the width of information.
atime, ctime, mode, user and group. Information is only shown when the
pane width is more than twice the width of information.

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

Expand Down
8 changes: 4 additions & 4 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ func (e *setExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "size", "time", "atime", "ctime":
case "size", "time", "atime", "ctime", "mode", "user", "group":
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', 'mode', 'user' or 'group' separated with colon")
return
}
}
Expand Down Expand Up @@ -482,9 +482,9 @@ func (e *setLocalExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "size", "time", "atime", "ctime":
case "size", "time", "atime", "ctime", "mode", "user", "group":
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', 'mode', 'user' or 'group' separated with colon")
return
}
}
Expand Down
5 changes: 3 additions & 2 deletions lf.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 2.11.4
.\"
.TH "LF" "1" "2024-07-01" "" "DOCUMENTATION"
.TH "LF" "1" "2024-09-13" "" "DOCUMENTATION"
.hy
.SH NAME
.PP
Expand Down Expand Up @@ -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
side of the pane.
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]mode\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
width of information.
.SS infotimefmtnew (string) (default \f[C]Jan _2 15:04\f[R])
Expand Down
47 changes: 45 additions & 2 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func infotimefmt(t time.Time) string {
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

for _, s := range getInfo(d.path) {
Expand Down Expand Up @@ -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))
case "ctime":
info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))
case "mode":
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:
log.Printf("unknown info type: %s", s)
}
Expand Down Expand Up @@ -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] {
st := dirStyle.colors.get(f)

Expand Down Expand Up @@ -461,7 +484,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
// subtract space for tag and icon
maxFilenameWidth := maxWidth - 1 - runeSliceWidth(icon)

info := fileInfo(f, dir)
info := fileInfo(f, dir, userWidth, groupWidth)
showInfo := len(info) > 0 && 2*len(info) < maxWidth
if showInfo {
maxFilenameWidth -= len(info)
Expand Down Expand Up @@ -519,6 +542,26 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
}
}

func getGroupWidth(dir *dir, beg int, end int) int {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mixed up the function names:

Suggested change
func getGroupWidth(dir *dir, beg int, end int) int {
func getUserWidth(dir *dir, beg int, end int) int {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Nice catch.

maxw := 0

for _, f := range dir.files[beg:end] {
maxw = max(len(userName(f.FileInfo)), maxw)
}

return maxw
}

func getUserWidth(dir *dir, beg int, end int) int {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

Suggested change
func getUserWidth(dir *dir, beg int, end int) int {
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 {
rsum := 0
for _, r := range gOpts.ratios {
Expand Down