From e7ea6c6d0df79c055839870c7abdda51d5f1640a Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Mon, 12 May 2025 14:28:26 +1000 Subject: [PATCH] Add scroll percentage to `rulerfmt` option (#1985) --- doc.md | 2 +- doc.txt | 16 ++++++++-------- lf.1 | 7 ++++--- misc.go | 2 +- ui.go | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/doc.md b/doc.md index f3ebc8bc..4fb46999 100644 --- a/doc.md +++ b/doc.md @@ -910,7 +910,7 @@ Draw rounded outer corners when the `drawbox` option is enabled. ## 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;34m %f \033[0m| %i/%t`) Format string of the ruler shown in the bottom right corner. -Special expansions are provided, `%a` as the pressed keys, `%p` as the progress of file operations, `%m` as the number of files to be cut (moved), `%c` as the number of files to be copied, `%s` as the number of selected files, `%f` as the filter, `%i` as the position of the cursor, `%t` as the number of files shown in the current directory, `%h` as the number of files hidden in the current directory, and `%d` as the amount of free disk space remaining. +Special expansions are provided, `%a` as the pressed keys, `%p` as the progress of file operations, `%m` as the number of files to be cut (moved), `%c` as the number of files to be copied, `%s` as the number of selected files, `%f` as the filter, `%i` as the position of the cursor, `%t` as the number of files shown in the current directory, `%h` as the number of files hidden in the current directory, `%P` as the scroll percentage, and `%d` as the amount of free disk space remaining. Additional expansions are provided for environment variables exported by lf, in the form `%{lf_}` (e.g. `%{lf_selmode}`). This is useful for displaying the current settings. Expansions are also provided for user-defined options, in the form `%{lf_user_}` (e.g. `%{lf_user_foo}`). The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown. diff --git a/doc.txt b/doc.txt index 1f4298ce..9fa8af02 100644 --- a/doc.txt +++ b/doc.txt @@ -989,14 +989,14 @@ file operations, %m as the number of files to be cut (moved), %c as the number of files to be copied, %s as the number of selected files, %f as the filter, %i as the position of the cursor, %t as the number of files shown in the current directory, %h as the number of files hidden in the -current directory, and %d as the amount of free disk space remaining. -Additional expansions are provided for environment variables exported by -lf, in the form %{lf_} (e.g. %{lf_selmode}). This is useful for -displaying the current settings. Expansions are also provided for -user-defined options, in the form %{lf_user_} (e.g. -%{lf_user_foo}). The | character splits the format string into sections. -Any section containing a failed expansion (result is a blank string) is -discarded and not shown. +current directory, %P as the scroll percentage, and %d as the amount of +free disk space remaining. Additional expansions are provided for +environment variables exported by lf, in the form %{lf_} (e.g. +%{lf_selmode}). This is useful for displaying the current settings. +Expansions are also provided for user-defined options, in the form +%{lf_user_} (e.g. %{lf_user_foo}). The | character splits the +format string into sections. Any section containing a failed expansion +(result is a blank string) is discarded and not shown. selectfmt (string) (default \033[7;35m) diff --git a/lf.1 b/lf.1 index 26351300..fa8e1341 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 2.11.4 .\" -.TH "LF" "1" "2025-04-25" "" "DOCUMENTATION" +.TH "LF" "1" "2025-05-12" "" "DOCUMENTATION" .hy .SH NAME .PP @@ -1008,8 +1008,9 @@ number of files to be cut (moved), \f[C]%c\f[R] as the number of files to be copied, \f[C]%s\f[R] as the number of selected files, \f[C]%f\f[R] as the filter, \f[C]%i\f[R] as the position of the cursor, \f[C]%t\f[R] as the number of files shown in the current directory, \f[C]%h\f[R] as -the number of files hidden in the current directory, and \f[C]%d\f[R] as -the amount of free disk space remaining. +the number of files hidden in the current directory, \f[C]%P\f[R] as the +scroll percentage, and \f[C]%d\f[R] as the amount of free disk space +remaining. Additional expansions are provided for environment variables exported by lf, in the form \f[C]%{lf_}\f[R] (e.g. \f[C]%{lf_selmode}\f[R]). diff --git a/misc.go b/misc.go index d08bfb75..04fd32bd 100644 --- a/misc.go +++ b/misc.go @@ -326,7 +326,7 @@ func getFileExtension(file fs.FileInfo) string { var ( reModKey = regexp.MustCompile(`<(c|s|a)-(.+)>`) - reRulerSub = regexp.MustCompile(`%[apmcsfithd]|%\{[^}]+\}`) + reRulerSub = regexp.MustCompile(`%[apmcsfithPd]|%\{[^}]+\}`) reSixelSize = regexp.MustCompile(`"1;1;(\d+);(\d+)`) ) diff --git a/ui.go b/ui.go index 9165935c..00975967 100644 --- a/ui.go +++ b/ui.go @@ -892,6 +892,19 @@ func (ui *ui) drawRuler(nav *nav) { hid := len(dir.allFiles) - tot acc := string(ui.keyCount) + string(ui.keyAcc) + var percentage string + beg := max(dir.ind-dir.pos, 0) + switch { + case tot <= nav.height: + percentage = "All" + case beg == 0: + percentage = "Top" + case beg == tot-nav.height: + percentage = "Bot" + default: + percentage = fmt.Sprintf("%2d%%", beg*100/(tot-nav.height)) + } + copy := 0 move := 0 for _, cp := range nav.saves { @@ -943,6 +956,8 @@ func (ui *ui) drawRuler(nav *nav) { result = strconv.Itoa(tot) case "%h": result = strconv.Itoa(hid) + case "%P": + result = percentage case "%d": result = diskFree(dir.path) default: