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

Permission numbers for Unix, align ui.Span, position of selection marker #2386

Closed
2 of 3 tasks
csswright opened this issue Feb 23, 2025 · 4 comments · Fixed by #2394
Closed
2 of 3 tasks

Permission numbers for Unix, align ui.Span, position of selection marker #2386

csswright opened this issue Feb 23, 2025 · 4 comments · Fixed by #2394
Labels
feature New feature request needs info

Comments

@csswright
Copy link

csswright commented Feb 23, 2025

yazi --debug output

N/A

Please describe the problem you're trying to solve

Feature requests (I don't want to spam as separate small feature requests and they are all related, not sure what the dev prefers). Picture is worth a thousand words, compares the line mode between above (the desired line mode in nnn file manager) and below, my modified line mode attempt in Yazi:

  • Support for permission numbers for Unix. (perm() is much wordy and IMO less readable than e.g. 755.

  • Allow allowing ui.Span--I have line mode left-aligned but its uiSpan component for size is variable width so aligning improves readability.

  • Move selection marker position to area between line mode and filename. IMO, line mode only makes sense to the left since its length is much more predictable than the filename (having it on the right affects readability if you have e.g. a short filename and a long filename both in view. With line mode on the left in between filenames and where the selection marker is currently, it's hard to track whether whether the currently hovered file is part of selection compared to if selection marker can be positioned to the left of the filename column. I've tried extending the cursor highlight to the line mode so that it reaches the selection marker, but it's ugly and effects readability of the subdued line mode.

  • Unrelated: provide yazi --config <path> as a quick way to switch to yazi defaults (something done often when debugging, thinking about workflows, and determining feature requests).

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

See above.

Additional context

My line mode:

function Linemode:my_metadata()
  local time = math.floor(self._file.cha.mtime or 0)
  local modified_time

  if time ~= 0 and ya.time() - time <= 300 then
    modified_time = ui.Span(os.date("%Y-%m-%d %H:%M", time)):reverse()
  else
    modified_time = ui.Span(os.date("%Y-%m-%d %H:%M", time))
  end

  local line = ui.Line({
    modified_time,
    "  ",
    self._file.cha:perm(),
    "  ",
    ui.Span(tostring(ya.readable_size(self._file.cha.len))),
  })

  return line:style(ui.Style():fg("#B4B4B4")) -- less white
end

local current_render = Current.redraw
function Current:redraw()
  local t = current_render(self)
  if #t < 2 then
    return t
  end

  local area, width = t[1]:area(), t[2]:max_width()
  t[1] = t[1]:area(ui.Rect({ x = area.x + width, y = area.y, w = math.max(0, area.w - width), h = area.h }))
  t[2] = t[2]:align(ui.Text.LEFT)
  return t
end

One thing I've noticed with showing recently modified files as stylized is that if I copy over a file (overwrite), it doesn't get stylized whereas in nnn it does. I prefer the latter but not sure how to achieve it.

Checklist

  • I have searched the existing issues/discussions
  • The latest nightly build doesn't already have this feature
@csswright csswright added the feature New feature request label Feb 23, 2025
Copy link

Hey @csswright, I noticed that you did not correctly follow the issue template. Please ensure that:

  • The requested feature does not exist in the newest nightly build.
  • The debug information (yazi --debug) is updated for the newest nightly.
  • All required fields in the checklist have been checked.

Issues with needs info will be marked ready once edited with the proper content, or closed after 2 days of inactivity.

@sxyazi
Copy link
Owner

sxyazi commented Feb 24, 2025

Support for permission numbers for Unix

I can add a new mode field in Cha to expose it.

Allow aligning ui.Span

No, you can't do that on the Span. The smallest element is a Line that you can do so. Yazi's UI component is just a Lua binding for ratatui, and ratatui itself doesn't provide aligning support for Span either.

Move selection marker position to area between line mode and filename

You can place the Marker anywhere you want, as long as you pass the corresponding area as a construction parameter, which it is a ui.Rect.

function Marker:new(area, folder)

Unrelated: provide yazi --config <path> as a quick way to switch to yazi defaults

YAZI_CONFIG_HOME=/tmp yazi, see https://yazi-rs.github.io/docs/configuration/overview#custom-directory

@sxyazi
Copy link
Owner

sxyazi commented Feb 24, 2025

I can add a new mode field in Cha to expose it.

Done in #2394

@csswright
Copy link
Author

csswright commented Feb 25, 2025

I can add a new mode field in Cha to expose it.

Done in #2394

mode() just reports the raw st_mode bits which is not user friendly--should be converted to octal as in the example and then the last 3 digits yield the familiar permissions used by common Unix tools.

No, you can't do that on the Span. The smallest element is a Line that you can do so. Yazi's UI component is just a Lua binding for ratatui, and ratatui itself doesn't provide aligning support for Span either.

To be clear, do you mean it's not possible to right-align linemode on the left so that variable-width size column lines up customize Yazi on the bottom looks like the top? I tweaked that linemode from the one you posted here then tried appending :align(ui.Line.RIGHT) to ui.Line({...}) but it has no effect on right-aligning the linemode. Or do you mean it's still possible to right-align the size column somehow and I just don't need to use ui.Span? I'm thinking the area part is relevant but I'm not a programmer and don't understand how to work with t (just know that involves the area is defined).

Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request needs info
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants