Add ruler file for customizing the ruler (#2186)

* Add ruler file for customizing the ruler

* Update `CHANGELOG.md`

* Show ruler errors instead of logging them

* Allow multiple sections

* Show syntax errors for ruler file

* Add line percentage

* Add lower/upper functions

* Add back truncation

* Use fmt options

---------

Co-authored-by: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com>
This commit is contained in:
Joe LimandCatsDeservePets authored and GitHub committed 2025-10-21 20:04:05 +11:00
1 parent 5d93764c79
commit 7b6b6da100
11 files changed
+497 -2

No files matched your search

+61
View File
@@ -299,6 +299,7 @@ The following options can be used to customize the behavior of lf:
relativenumber bool (default false)
reverse bool (default false)
roundbox bool (default false)
rulerfile bool (default false)
rulerfmt string (default " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;36m %v \033[0m| \033[7;34m %f \033[0m| %i/%t")
scrolloff int (default 0)
searchmethod string (default 'text')
@@ -447,6 +448,12 @@ The icons file should be located at:
Unix /etc/lf/icons ~/.config/lf/icons
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Roaming\lf\icons
The ruler file should be located at:
OS system-wide user-specific
Unix /etc/lf/ruler ~/.config/lf/ruler
Windows C:\ProgramData\lf\ruler C:\Users\<user>\AppData\Roaming\lf\ruler
The selection file should be located at:
Unix ~/.local/share/lf/files
@@ -1089,6 +1096,11 @@ Reverse the direction of sort.
Draw rounded outer corners when the `drawbox` option is enabled.
## rulerfile (bool) (default false)
Use the ruler file instead of the `rulerfmt` and `statfmt` options when drawing the ruler at the bottom.
Refer to the [RULER section](https://github.com/gokcehan/lf/blob/master/doc.md#ruler) for more information about how the ruler file works.
## rulerfmt (string) (default ` %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;36m %v \033[0m| \033[7;34m %f \033[0m| %i/%t`)
Format string of the ruler shown in the bottom right corner.
@@ -2187,3 +2199,52 @@ https://github.com/gokcehan/lf/blob/master/etc/icons.example
A sample colored icons file can be found at
https://github.com/gokcehan/lf/blob/master/etc/icons_colored.example
# RULER
The ruler can be configured using a ruler file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)).
The contents of the ruler file should be a Go template which is then rendered to create the actual output (refer to https://pkg.go.dev/text/template for more details on the syntax).
This feature is currently experimental and must be enabled via the `rulerfile` option.
The following data fields are exported:
.Message string Includes internal messages, errors, and messages generated by the `echo`/`echomsg`/`echoerr` commands
.Keys string Keys pressed by the user
.Progress []string Progress indicators for copied, moved and deleted files
.Copy []string List of files in the clipboard to be copied
.Cut []string List of files in the clipboard to be moved
.Select []string Selection list
.Visual []string Visual selection
.Index int Index of the cursor
.Total int Number of visible files in the current directory
.Hidden int Number of hidden files in the current directory
.LinePercentage string Line percentage (analagous to `%p` for the `statusline` option in Vim)
.ScrollPercentage string Scroll percentage (analagous to `%P` for the `statusline` option in Vim)
.Filter []string Filter currently being applied
.Mode string Current mode ("NORMAL" for Normal mode, and "VISUAL" for Visual mode)
.Options map[string]string The value of options (e.g. `{{.Options.hidden}}`)
.UserOptions map[string]string The value of user-defined options (e.g. `{{.UserOptions.foo}}`)
.Stat.Path string Path of the current file
.Stat.Name string Name of the current file
.Stat.Size uint64 Size of the current file
.Stat.Permissions string Permissions of the current file
.Stat.ModTime string Last modified time of the current file (formatted based on the `timefmt` option)
.Stat.LinkCount string Number of hard links for the current file
.Stat.User string User of the current file
.Stat.Group string Group of the current file
.Stat.Target string Target if the current file is a symbolic link, otherwise a blank string
The following functions are exported:
df func() string Get an indicator representing the amount of free disk space available
env func(string) string Get the value of an environment variable
humanize func(uint64) string Express a file size in a human-readable format
join func([]string, string) string Join a string array by a separator
lower func(string) string Convert a string to lowercase
substr func(string, int, int) string Get a substring based on starting index and length
upper func(string) string Convert a string to uppercase
The special identifier `{{.SPACER}}` can be used to divide the ruler into sections that are spaced evenly from each other.
The default ruler file can be found at
https://github.com/gokcehan/lf/blob/master/etc/ruler.default