Skip to content

Commit 909d81c

Browse files
Merge branch 'master' into log
2 parents 99fa699 + 2563e6b commit 909d81c

File tree

15 files changed

+529
-22
lines changed

15 files changed

+529
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1717
- The `cmd-history-next` and `cmd-history-prev` commands will now select only matching entries if part of the command is typed beforehand (#2161). Consecutive duplicate entries will also be skipped for convenience.
1818
- The string representation of commands shown when displaying keybindings is simplified (e.g. `cd ~` instead of `cd -- [~]`) (#2165).
1919
- `yes-no-prompts` now use the same design everywhere (#2212).
20+
- Logs generated by `-log <path>` now get appended to `<path>` instead of overwriting it (#2215).
2021

2122
### Added
2223

2324
- A new command `cmd-menu-discard` is added to allow exiting the completion menu with completions discarded (#2146).
2425
- The `lf_mode` environment variable will now be set to `compmenu` if the completion menu is active (#2146).
26+
- A `ruler` config file is added as an alternate method for customizing the ruler (#2186). This is intended to eventually replace the existing `rulerfmt`/`statfmt` options and must be enabled using the new `rulerfile` option. **This feature is currently experimental.**
2527

2628
### Fixed
2729

@@ -31,6 +33,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
3133
- A bug where the `source` command does not show an error message upon failure is now fixed (#2189).
3234
- The `addcustominfo` command as well as the `cleaner` and `previewer` options now support file completions (#2198) (#2211).
3335
- A bug where an empty `custom` info property would still take up space is now fixed (#2208).
36+
- A bug where setting `drawbox` could lead to scrolling outside the view is now fixed (#2210) (#2218).
37+
- The preview cache is now not cleared when setting `ratios` to its current value (#2218).
3438

3539
## [r38](https://github.com/gokcehan/lf/releases/tag/r38)
3640

app.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func loadFiles() (clipboard clipboard, err error) {
149149
return
150150
}
151151

152-
infof("loading files: %v", clipboard.paths)
152+
infof("loading clipboard: %v", clipboard.paths)
153153

154154
return
155155
}
@@ -165,7 +165,7 @@ func saveFiles(clipboard clipboard) error {
165165
}
166166
defer files.Close()
167167

168-
infof("saving files: %v", clipboard.paths)
168+
infof("saving clipboard: %v", clipboard.paths)
169169

170170
if clipboard.mode == clipboardCopy {
171171
fmt.Fprintln(files, "copy")
@@ -329,8 +329,7 @@ func (app *app) loop() {
329329

330330
app.nav.previewChan <- ""
331331

332-
pid := os.Getpid()
333-
infof("*************** closing client, PID: %d ***************", pid)
332+
infof("*************** closing client, PID: %d ***************", os.Getpid())
334333

335334
return
336335
case n := <-app.nav.copyJobsChan:

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func init() {
2727

2828
func run() {
2929
if gLogPath != "" {
30-
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
30+
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
3131
if err != nil {
3232
log.Fatalf("failed to open log file: %s", err)
3333
}
@@ -53,7 +53,7 @@ func run() {
5353
screen.EnablePaste()
5454

5555
ui := newUI(screen)
56-
nav := newNav(ui.wins[0].h)
56+
nav := newNav(ui)
5757
app := newApp(ui, nav)
5858

5959
if err := nav.sync(); err != nil {

doc.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ The following options can be used to customize the behavior of lf:
299299
relativenumber bool (default false)
300300
reverse bool (default false)
301301
roundbox bool (default false)
302+
rulerfile bool (default false)
302303
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")
303304
scrolloff int (default 0)
304305
searchmethod string (default 'text')
@@ -447,6 +448,12 @@ The icons file should be located at:
447448
Unix /etc/lf/icons ~/.config/lf/icons
448449
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Roaming\lf\icons
449450

451+
The ruler file should be located at:
452+
453+
OS system-wide user-specific
454+
Unix /etc/lf/ruler ~/.config/lf/ruler
455+
Windows C:\ProgramData\lf\ruler C:\Users\<user>\AppData\Roaming\lf\ruler
456+
450457
The selection file should be located at:
451458

452459
Unix ~/.local/share/lf/files
@@ -1089,6 +1096,11 @@ Reverse the direction of sort.
10891096

10901097
Draw rounded outer corners when the `drawbox` option is enabled.
10911098

1099+
## rulerfile (bool) (default false)
1100+
1101+
Use the ruler file instead of the `rulerfmt` and `statfmt` options when drawing the ruler at the bottom.
1102+
Refer to the [RULER section](https://github.com/gokcehan/lf/blob/master/doc.md#ruler) for more information about how the ruler file works.
1103+
10921104
## 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`)
10931105

10941106
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
21872199

21882200
A sample colored icons file can be found at
21892201
https://github.com/gokcehan/lf/blob/master/etc/icons_colored.example
2202+
2203+
# RULER
2204+
2205+
The ruler can be configured using a ruler file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)).
2206+
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).
2207+
This feature is currently experimental and must be enabled via the `rulerfile` option.
2208+
2209+
The following data fields are exported:
2210+
2211+
.Message string Includes internal messages, errors, and messages generated by the `echo`/`echomsg`/`echoerr` commands
2212+
.Keys string Keys pressed by the user
2213+
.Progress []string Progress indicators for copied, moved and deleted files
2214+
.Copy []string List of files in the clipboard to be copied
2215+
.Cut []string List of files in the clipboard to be moved
2216+
.Select []string Selection list
2217+
.Visual []string Visual selection
2218+
.Index int Index of the cursor
2219+
.Total int Number of visible files in the current directory
2220+
.Hidden int Number of hidden files in the current directory
2221+
.LinePercentage string Line percentage (analagous to `%p` for the `statusline` option in Vim)
2222+
.ScrollPercentage string Scroll percentage (analagous to `%P` for the `statusline` option in Vim)
2223+
.Filter []string Filter currently being applied
2224+
.Mode string Current mode ("NORMAL" for Normal mode, and "VISUAL" for Visual mode)
2225+
.Options map[string]string The value of options (e.g. `{{.Options.hidden}}`)
2226+
.UserOptions map[string]string The value of user-defined options (e.g. `{{.UserOptions.foo}}`)
2227+
.Stat.Path string Path of the current file
2228+
.Stat.Name string Name of the current file
2229+
.Stat.Size uint64 Size of the current file
2230+
.Stat.Permissions string Permissions of the current file
2231+
.Stat.ModTime string Last modified time of the current file (formatted based on the `timefmt` option)
2232+
.Stat.LinkCount string Number of hard links for the current file
2233+
.Stat.User string User of the current file
2234+
.Stat.Group string Group of the current file
2235+
.Stat.Target string Target if the current file is a symbolic link, otherwise a blank string
2236+
2237+
The following functions are exported:
2238+
2239+
df func() string Get an indicator representing the amount of free disk space available
2240+
env func(string) string Get the value of an environment variable
2241+
humanize func(uint64) string Express a file size in a human-readable format
2242+
join func([]string, string) string Join a string array by a separator
2243+
lower func(string) string Convert a string to lowercase
2244+
substr func(string, int, int) string Get a substring based on starting index and length
2245+
upper func(string) string Convert a string to uppercase
2246+
2247+
The special identifier `{{.SPACER}}` can be used to divide the ruler into sections that are spaced evenly from each other.
2248+
2249+
The default ruler file can be found at
2250+
https://github.com/gokcehan/lf/blob/master/etc/ruler.default

doc.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ The following options can be used to customize the behavior of lf:
311311
relativenumber bool (default false)
312312
reverse bool (default false)
313313
roundbox bool (default false)
314+
rulerfile bool (default false)
314315
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")
315316
scrolloff int (default 0)
316317
searchmethod string (default 'text')
@@ -461,6 +462,12 @@ The icons file should be located at:
461462
Unix /etc/lf/icons ~/.config/lf/icons
462463
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Roaming\lf\icons
463464

465+
The ruler file should be located at:
466+
467+
OS system-wide user-specific
468+
Unix /etc/lf/ruler ~/.config/lf/ruler
469+
Windows C:\ProgramData\lf\ruler C:\Users\<user>\AppData\Roaming\lf\ruler
470+
464471
The selection file should be located at:
465472

466473
Unix ~/.local/share/lf/files
@@ -1181,6 +1188,12 @@ roundbox (bool) (default false)
11811188

11821189
Draw rounded outer corners when the drawbox option is enabled.
11831190

1191+
rulerfile (bool) (default false)
1192+
1193+
Use the ruler file instead of the rulerfmt and statfmt options when
1194+
drawing the ruler at the bottom. Refer to the RULER section for more
1195+
information about how the ruler file works.
1196+
11841197
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)
11851198

11861199
Format string of the ruler shown in the bottom right corner.
@@ -2451,3 +2464,56 @@ https://github.com/gokcehan/lf/blob/master/etc/icons.example
24512464

24522465
A sample colored icons file can be found at
24532466
https://github.com/gokcehan/lf/blob/master/etc/icons_colored.example
2467+
2468+
RULER
2469+
2470+
The ruler can be configured using a ruler file (refer to the
2471+
CONFIGURATION section). The contents of the ruler file should be a Go
2472+
template which is then rendered to create the actual output (refer to
2473+
https://pkg.go.dev/text/template for more details on the syntax). This
2474+
feature is currently experimental and must be enabled via the rulerfile
2475+
option.
2476+
2477+
The following data fields are exported:
2478+
2479+
.Message string Includes internal messages, errors, and messages generated by the `echo`/`echomsg`/`echoerr` commands
2480+
.Keys string Keys pressed by the user
2481+
.Progress []string Progress indicators for copied, moved and deleted files
2482+
.Copy []string List of files in the clipboard to be copied
2483+
.Cut []string List of files in the clipboard to be moved
2484+
.Select []string Selection list
2485+
.Visual []string Visual selection
2486+
.Index int Index of the cursor
2487+
.Total int Number of visible files in the current directory
2488+
.Hidden int Number of hidden files in the current directory
2489+
.LinePercentage string Line percentage (analagous to `%p` for the `statusline` option in Vim)
2490+
.ScrollPercentage string Scroll percentage (analagous to `%P` for the `statusline` option in Vim)
2491+
.Filter []string Filter currently being applied
2492+
.Mode string Current mode ("NORMAL" for Normal mode, and "VISUAL" for Visual mode)
2493+
.Options map[string]string The value of options (e.g. `{{.Options.hidden}}`)
2494+
.UserOptions map[string]string The value of user-defined options (e.g. `{{.UserOptions.foo}}`)
2495+
.Stat.Path string Path of the current file
2496+
.Stat.Name string Name of the current file
2497+
.Stat.Size uint64 Size of the current file
2498+
.Stat.Permissions string Permissions of the current file
2499+
.Stat.ModTime string Last modified time of the current file (formatted based on the `timefmt` option)
2500+
.Stat.LinkCount string Number of hard links for the current file
2501+
.Stat.User string User of the current file
2502+
.Stat.Group string Group of the current file
2503+
.Stat.Target string Target if the current file is a symbolic link, otherwise a blank string
2504+
2505+
The following functions are exported:
2506+
2507+
df func() string Get an indicator representing the amount of free disk space available
2508+
env func(string) string Get the value of an environment variable
2509+
humanize func(uint64) string Express a file size in a human-readable format
2510+
join func([]string, string) string Join a string array by a separator
2511+
lower func(string) string Convert a string to lowercase
2512+
substr func(string, int, int) string Get a substring based on starting index and length
2513+
upper func(string) string Convert a string to uppercase
2514+
2515+
The special identifier {{.SPACER}} can be used to divide the ruler into
2516+
sections that are spaced evenly from each other.
2517+
2518+
The default ruler file can be found at
2519+
https://github.com/gokcehan/lf/blob/master/etc/ruler.default

etc/ruler.default

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{with .Message -}}
2+
{{. -}}
3+
{{else with .Stat -}}
4+
{{.Permissions | printf "\033[36m%s\033[0m" -}}
5+
{{with .LinkCount}} {{.}}{{end -}}
6+
{{with .User}} {{.}}{{end -}}
7+
{{with .Group}} {{.}}{{end -}}
8+
{{.Size | humanize | printf " %5s" -}}
9+
{{.ModTime | printf " %s" -}}
10+
{{with .Target}} -> {{.}}{{end -}}
11+
{{end -}}
12+
{{.SPACER -}}
13+
{{with .Keys}} {{.}}{{end -}}
14+
{{with .Progress}} {{join . " "}}{{end -}}
15+
{{with .Copy}} {{len . | printf "%s %d \033[0m" $.Options.copyfmt}}{{end -}}
16+
{{with .Cut}} {{len . | printf "%s %d \033[0m" $.Options.cutfmt}}{{end -}}
17+
{{with .Select}} {{len . | printf "%s %d \033[0m" $.Options.selectfmt}}{{end -}}
18+
{{with .Visual}} {{len . | printf "%s %d \033[0m" $.Options.visualfmt}}{{end -}}
19+
{{with .Filter}} {{join . " " | printf "\033[7;34m %s \033[0m"}}{{end -}}
20+
{{printf " %d/%d" .Index .Total}}

eval.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (e *setExpr) eval(app *app, args []string) {
8989
err = applyBoolOpt(&gOpts.drawbox, e)
9090
if err == nil {
9191
app.ui.renew()
92-
clear(app.nav.regCache)
92+
app.nav.resize(app.ui)
9393
app.ui.loadFile(app, true)
9494
}
9595
case "hidden", "nohidden", "hidden!":
@@ -156,6 +156,8 @@ func (e *setExpr) eval(app *app, args []string) {
156156
}
157157
case "roundbox", "noroundbox", "roundbox!":
158158
err = applyBoolOpt(&gOpts.roundbox, e)
159+
case "rulerfile", "norulerfile", "rulerfile!":
160+
err = applyBoolOpt(&gOpts.rulerfile, e)
159161
case "showbinds", "noshowbinds", "showbinds!":
160162
err = applyBoolOpt(&gOpts.showbinds, e)
161163
// DEPRECATED: remove after r38 is released
@@ -340,7 +342,7 @@ func (e *setExpr) eval(app *app, args []string) {
340342
}
341343
gOpts.ratios = rats
342344
app.ui.wins = getWins(app.ui.screen)
343-
clear(app.nav.regCache)
345+
app.nav.resize(app.ui)
344346
app.ui.loadFile(app, true)
345347
case "rulerfmt":
346348
gOpts.rulerfmt = e.val
@@ -1279,15 +1281,9 @@ func (e *callExpr) eval(app *app, args []string) {
12791281
if !app.nav.init {
12801282
return
12811283
}
1282-
app.ui.renew()
12831284
app.ui.screen.Sync()
1284-
if app.nav.height != app.ui.wins[0].h {
1285-
app.nav.height = app.ui.wins[0].h
1286-
clear(app.nav.regCache)
1287-
}
1288-
for _, dir := range app.nav.dirs {
1289-
dir.boundPos(app.nav.height)
1290-
}
1285+
app.ui.renew()
1286+
app.nav.resize(app.ui)
12911287
app.ui.sxScreen.forceClear = true
12921288
app.ui.loadFile(app, true)
12931289
onRedraw(app)

0 commit comments

Comments
 (0)