diff --git a/CHANGELOG.md b/CHANGELOG.md index cc41553e..e13c700e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A new field `.All` is added to the `ruler` file to display the number of all files (i.e. visible + hidden) in the current working directory (#2376). - A new option `numbercursorfmt` is added to further customize the appearance of line numbers (#2395). - A new option `terminalcursor` is added to customize the appearance of the terminal cursor (#2441). +- A new option `borderstyle` is added to control whether `drawbox` draws an outline, separators, or both (#2445). - The `loading...` message delay of 100 milliseconds for file previews is now applied to directories as well (#2410). - `lf` will now automatically change to the parent directory if the current directory no longer exists and the `watch` option is enabled (#2424). diff --git a/complete.go b/complete.go index a3a6a43f..dd404362 100644 --- a/complete.go +++ b/complete.go @@ -395,6 +395,8 @@ func completeCmd(s string) (matches []compMatch, longest string) { switch f[1] { case "cleaner", "previewer", "rulerfile": matches, longest = matchCmdFile(f[2], false) + case "borderstyle": + matches, longest = matchWord(f[2], []string{"box", "roundbox", "outline", "roundoutline", "separators"}) case "filtermethod", "searchmethod": matches, longest = matchWord(f[2], []string{"glob", "regex", "text"}) case "info": diff --git a/doc.md b/doc.md index 3e8eab72..72f30b05 100644 --- a/doc.md +++ b/doc.md @@ -256,6 +256,7 @@ The following options can be used to customize the behavior of lf: anchorfind bool (default true) autoquit bool (default true) borderfmt string (default "\033[0m") + borderstyle string (default 'box') cleaner string (default '') copyfmt string (default "\033[7;33m") cursoractivefmt string (default "\033[7m") @@ -301,7 +302,6 @@ The following options can be used to customize the behavior of lf: ratios []int (default '1:2:3') relativenumber bool (default false) reverse bool (default false) - roundbox bool (default false) rulerfile string (default "") rulerfmt string (default "") scrolloff int (default 0) @@ -853,7 +853,19 @@ Automatically quit the server when there are no clients left connected. ## borderfmt (string) (default `\033[0m`) -Format string of the box drawing characters enabled by the `drawbox` option. +Format string of border characters. + +## borderstyle (string) (default `box`) + +Border style used by `drawbox`. + +The following styles are supported: + + box outline around all panes and separators between them + roundbox like `box`, but with rounded outer corners + outline outline around all panes + roundoutline like `outline`, but with rounded outer corners + separators separators between panes ## cleaner (string) (default ``) (not called if empty) @@ -908,7 +920,7 @@ If enabled, directories will also be passed to the previewer script. This allows ## drawbox (bool) (default false) -Draw boxes around panes with box drawing characters. +Draw borders around panes using box drawing characters. ## dupfilefmt (string) (default `%f.~%n~`) @@ -1109,10 +1121,6 @@ When `number` is enabled, the current line shows the absolute position, otherwis Reverse the direction of sort. -## roundbox (bool) (default false) - -Draw rounded outer corners when the `drawbox` option is enabled. - ## rulerfile (string) (default ``) Set the path of the ruler file. diff --git a/doc.txt b/doc.txt index 55fba4fe..48fc1b48 100644 --- a/doc.txt +++ b/doc.txt @@ -268,6 +268,7 @@ The following options can be used to customize the behavior of lf: anchorfind bool (default true) autoquit bool (default true) borderfmt string (default "\033[0m") + borderstyle string (default 'box') cleaner string (default '') copyfmt string (default "\033[7;33m") cursoractivefmt string (default "\033[7m") @@ -313,7 +314,6 @@ The following options can be used to customize the behavior of lf: ratios []int (default '1:2:3') relativenumber bool (default false) reverse bool (default false) - roundbox bool (default false) rulerfile string (default "") rulerfmt string (default "") scrolloff int (default 0) @@ -910,8 +910,19 @@ Automatically quit the server when there are no clients left connected. borderfmt (string) (default \033[0m) -Format string of the box drawing characters enabled by the drawbox -option. +Format string of border characters. + +borderstyle (string) (default box) + +Border style used by drawbox. + +The following styles are supported: + + box outline around all panes and separators between them + roundbox like `box`, but with rounded outer corners + outline outline around all panes + roundoutline like `outline`, but with rounded outer corners + separators separators between panes cleaner (string) (default ``) (not called if empty) @@ -979,7 +990,7 @@ This allows custom previews for directories. drawbox (bool) (default false) -Draw boxes around panes with box drawing characters. +Draw borders around panes using box drawing characters. dupfilefmt (string) (default %f.~%n~) @@ -1208,10 +1219,6 @@ reverse (bool) (default false) Reverse the direction of sort. -roundbox (bool) (default false) - -Draw rounded outer corners when the drawbox option is enabled. - rulerfile (string) (default ``) Set the path of the ruler file. If not set, then a default template will diff --git a/eval.go b/eval.go index f2681063..da4bf9a1 100644 --- a/eval.go +++ b/eval.go @@ -154,8 +154,9 @@ func (e *setExpr) eval(app *app, _ []string) { if err == nil { app.nav.sort() } + // DEPRECATED: remove after r42 is released case "roundbox", "noroundbox", "roundbox!": - err = applyBoolOpt(&gOpts.roundbox, e) + app.ui.echoerr("option 'roundbox' is deprecated, use 'borderstyle' instead") case "showbinds", "noshowbinds", "showbinds!": err = applyBoolOpt(&gOpts.showbinds, e) case "smartcase", "nosmartcase", "smartcase!": @@ -202,6 +203,25 @@ func (e *setExpr) eval(app *app, _ []string) { gOpts.cursorpreviewfmt = e.val case "cutfmt": gOpts.cutfmt = e.val + case "borderstyle": + switch e.val { + case "box": + gOpts.borderstyle = borderBox + case "roundbox": + gOpts.borderstyle = borderRoundBox + case "outline": + gOpts.borderstyle = borderOutline + case "roundoutline": + gOpts.borderstyle = borderRoundOutline + case "separators": + gOpts.borderstyle = borderSeparators + default: + app.ui.echoerr("borderstyle: value should either be 'box', 'roundbox', 'outline', 'roundoutline' or 'separators'") + return + } + app.ui.renew() + app.nav.resize(app.ui) + app.ui.loadFile(app, true) case "dupfilefmt": gOpts.dupfilefmt = e.val case "errorfmt": diff --git a/lf.1 b/lf.1 index 10112b34..9e84bb9d 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.7.0.2 .\" -.TH "LF" "1" "2026\-03\-19" "r42" "DOCUMENTATION" +.TH "LF" "1" "2026\-03\-21" "r42" "DOCUMENTATION" .SH NAME lf \- terminal file manager .SH SYNOPSIS @@ -280,6 +280,7 @@ The following options can be used to customize the behavior of lf: anchorfind bool (default true) autoquit bool (default true) borderfmt string (default \(dq\(rs033[0m\(dq) +borderstyle string (default \(aqbox\(aq) cleaner string (default \(aq\(aq) copyfmt string (default \(dq\(rs033[7;33m\(dq) cursoractivefmt string (default \(dq\(rs033[7m\(dq) @@ -325,7 +326,6 @@ promptfmt string (default \(dq\(rs033[32;1m%u\(at%h\(rs033[0m:\(rs033 ratios []int (default \(aq1:2:3\(aq) relativenumber bool (default false) reverse bool (default false) -roundbox bool (default false) rulerfile string (default \(dq\(dq) rulerfmt string (default \(dq\(dq) scrolloff int (default 0) @@ -814,8 +814,19 @@ position. .SS autoquit (bool) (default true) Automatically quit the server when there are no clients left connected. .SS borderfmt (string) (default \f[CR]\(rs033[0m\f[R]) -Format string of the box drawing characters enabled by the -\f[CR]drawbox\f[R] option. +Format string of border characters. +.SS borderstyle (string) (default \f[CR]box\f[R]) +Border style used by \f[CR]drawbox\f[R]. +.PP +The following styles are supported: +.IP +.EX +box outline around all panes and separators between them +roundbox like \(gabox\(ga, but with rounded outer corners +outline outline around all panes +roundoutline like \(gaoutline\(ga, but with rounded outer corners +separators separators between panes +.EE .SS cleaner (string) (default \(ga\(ga) (not called if empty) Set the path of a cleaner file. The file should be executable. @@ -873,7 +884,7 @@ Show only directories. If enabled, directories will also be passed to the previewer script. This allows custom previews for directories. .SS drawbox (bool) (default false) -Draw boxes around panes with box drawing characters. +Draw borders around panes using box drawing characters. .SS dupfilefmt (string) (default \f[CR]%f.\(ti%n\(ti\f[R]) Format string of filename when creating duplicate files. With the default format, copying a file \f[CR]abc.txt\f[R] to the same @@ -1070,9 +1081,6 @@ When \f[CR]number\f[R] is enabled, the current line shows the absolute position, otherwise nothing is shown. .SS reverse (bool) (default false) Reverse the direction of sort. -.SS roundbox (bool) (default false) -Draw rounded outer corners when the \f[CR]drawbox\f[R] option is -enabled. .SS rulerfile (string) (default \(ga\(ga) Set the path of the ruler file. If not set, then a default template will be used for the ruler. diff --git a/main.go b/main.go index 0a6d1998..e83d2475 100644 --- a/main.go +++ b/main.go @@ -101,10 +101,13 @@ func exportFlags() { // used by exportOpts below func fieldToString(field reflect.Value) string { - kind := field.Kind() - var value string + // prevent returning + if field.Type() == reflect.TypeFor[borderStyle]() { + return borderStyle(field.Uint()).String() + } - switch kind { + var value string + switch field.Kind() { case reflect.Int: value = strconv.Itoa(int(field.Int())) case reflect.Bool: diff --git a/misc.go b/misc.go index e112861c..dd684dad 100644 --- a/misc.go +++ b/misc.go @@ -530,12 +530,12 @@ func readLines(reader io.ByteReader, maxLines int) (lines []string, binary bool, // getWidths calculates the widths of windows as the result of applying the // `ratios` option to the screen width. One column is allocated for each divider -// between windows. The `drawbox` option requires an additional two columns to -// draw the left and right borders. -func getWidths(wtot int, ratios []int, drawbox bool) []int { +// between windows. When `drawbox` is enabled and `borderstyle` includes an outline, +// getWidths reserves two additional columns for the left and right borders. +func getWidths(wtot int, ratios []int, drawbox bool, borderstyle borderStyle) []int { rlen := len(ratios) wtot -= rlen - 1 - if drawbox { + if drawbox && borderstyle&borderOutline != 0 { wtot -= 2 } wtot = max(wtot, 0) diff --git a/misc_test.go b/misc_test.go index d8d2f37d..27628da6 100644 --- a/misc_test.go +++ b/misc_test.go @@ -558,27 +558,35 @@ func TestReadLines(t *testing.T) { func TestGetWidths(t *testing.T) { tests := []struct { - wtot int - ratios []int - drawbox bool - exp []int + wtot int + ratios []int + drawbox bool + borderstyle borderStyle + exp []int }{ - {0, []int{1}, false, []int{0}}, - {0, []int{1}, true, []int{0}}, - {0, []int{1, 3, 2}, false, []int{0, 0, 0}}, - {0, []int{1, 3, 2}, true, []int{0, 0, 0}}, - {14, []int{1, 3, 2}, false, []int{2, 6, 4}}, - {16, []int{1, 3, 2}, true, []int{2, 6, 4}}, - {23, []int{1, 3, 2, 4}, false, []int{2, 6, 4, 8}}, // windows end at 2.0, 8.0, 12.0, 20.0 respectively - {24, []int{1, 3, 2, 4}, false, []int{2, 6, 5, 8}}, // windows end at 2.1, 8.4, 12.6, 21.0 respectively - {25, []int{1, 3, 2, 4}, false, []int{2, 7, 4, 9}}, // windows end at 2.2, 8.8, 13.2, 22.0 respectively - {26, []int{1, 3, 2, 4}, false, []int{2, 7, 5, 9}}, // windows end at 2.3, 9.2, 13.8, 23.0 respectively + {0, []int{1}, false, borderBox, []int{0}}, + {0, []int{1}, true, borderBox, []int{0}}, + {0, []int{1, 3, 2}, false, borderBox, []int{0, 0, 0}}, + {0, []int{1, 3, 2}, true, borderBox, []int{0, 0, 0}}, + + {14, []int{1, 3, 2}, false, borderBox, []int{2, 6, 4}}, + {16, []int{1, 3, 2}, true, borderBox, []int{2, 6, 4}}, + + {16, []int{1, 3, 2}, true, borderSeparators, []int{2, 7, 5}}, + {16, []int{1, 3, 2}, true, borderOutline, []int{2, 6, 4}}, + {16, []int{1, 3, 2}, true, borderRoundOutline, []int{2, 6, 4}}, + {16, []int{1, 3, 2}, true, borderRoundBox, []int{2, 6, 4}}, + + {23, []int{1, 3, 2, 4}, false, borderBox, []int{2, 6, 4, 8}}, // windows end at 2.0, 8.0, 12.0, 20.0 respectively + {24, []int{1, 3, 2, 4}, false, borderBox, []int{2, 6, 5, 8}}, // windows end at 2.1, 8.4, 12.6, 21.0 respectively + {25, []int{1, 3, 2, 4}, false, borderBox, []int{2, 7, 4, 9}}, // windows end at 2.2, 8.8, 13.2, 22.0 respectively + {26, []int{1, 3, 2, 4}, false, borderBox, []int{2, 7, 5, 9}}, // windows end at 2.3, 9.2, 13.8, 23.0 respectively } for _, test := range tests { - widths := getWidths(test.wtot, test.ratios, test.drawbox) + widths := getWidths(test.wtot, test.ratios, test.drawbox, test.borderstyle) if !reflect.DeepEqual(widths, test.exp) { - t.Errorf("at input (%v, %v, %v) expected %v but got %v", test.wtot, test.ratios, test.drawbox, test.exp, widths) + t.Errorf("at input (%v, %v, %v, %v) expected %v but got %v", test.wtot, test.ratios, test.drawbox, test.borderstyle, test.exp, widths) } } } diff --git a/opts.go b/opts.go index a6255c54..3140253b 100644 --- a/opts.go +++ b/opts.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "maps" "time" ) @@ -50,10 +51,40 @@ const ( blinkBarCursor cursorStyle = "blinkbar" ) +type borderStyle byte + +const ( + borderOutline borderStyle = 1 << iota + borderSeparators + borderRound + + borderBox = borderOutline | borderSeparators + borderRoundOutline = borderOutline | borderRound + borderRoundBox = borderBox | borderRound +) + +func (s borderStyle) String() string { + switch s { + case borderBox: + return "box" + case borderRoundBox: + return "roundbox" + case borderOutline: + return "outline" + case borderRoundOutline: + return "roundoutline" + case borderSeparators: + return "separators" + default: + return fmt.Sprintf("borderStyle(%d)", s) + } +} + var gOpts struct { anchorfind bool autoquit bool borderfmt string + borderstyle borderStyle cleaner string copyfmt string cursoractivefmt string @@ -99,7 +130,6 @@ var gOpts struct { ratios []int relativenumber bool reverse bool - roundbox bool rulerfile string rulerfmt string scrolloff int @@ -197,6 +227,7 @@ func init() { gOpts.anchorfind = true gOpts.autoquit = true gOpts.borderfmt = "\033[0m" + gOpts.borderstyle = borderBox gOpts.cleaner = "" gOpts.copyfmt = "\033[7;33m" gOpts.cursoractivefmt = "\033[7m" @@ -242,7 +273,6 @@ func init() { gOpts.ratios = []int{1, 2, 3} gOpts.relativenumber = false gOpts.reverse = false - gOpts.roundbox = false gOpts.rulerfile = "" gOpts.rulerfmt = "" gOpts.scrolloff = 0 diff --git a/ui.go b/ui.go index 3d460c6e..c747dc82 100644 --- a/ui.go +++ b/ui.go @@ -480,15 +480,13 @@ func getWins(screen tcell.Screen) []*win { wtot, htot := screen.Size() h := max(htot-2, 0) - x := 0 - y := 1 - if gOpts.drawbox { + x, y := 0, 1 + if gOpts.drawbox && gOpts.borderstyle&borderOutline != 0 { h = max(htot-4, 0) - x = 1 - y = 2 + x, y = 1, 2 } - widths := getWidths(wtot, gOpts.ratios, gOpts.drawbox) + widths := getWidths(wtot, gOpts.ratios, gOpts.drawbox, gOpts.borderstyle) wins := make([]*win, 0, len(widths)) for _, w := range widths { wins = append(wins, newWin(w, h, x, y)) @@ -1020,37 +1018,52 @@ func (ui *ui) drawBox() { st := parseEscapeSequence(gOpts.borderfmt) w, h := ui.screen.Size() + style := gOpts.borderstyle - for i := 1; i < w-1; i++ { - ui.screen.PutStrStyled(i, 1, string(tcell.RuneHLine), st) - ui.screen.PutStrStyled(i, h-2, string(tcell.RuneHLine), st) - } - - for i := 2; i < h-2; i++ { - ui.screen.PutStrStyled(0, i, string(tcell.RuneVLine), st) - ui.screen.PutStrStyled(w-1, i, string(tcell.RuneVLine), st) - } - - if gOpts.roundbox { - ui.screen.PutStrStyled(0, 1, "╭", st) - ui.screen.PutStrStyled(w-1, 1, "╮", st) - ui.screen.PutStrStyled(0, h-2, "╰", st) - ui.screen.PutStrStyled(w-1, h-2, "╯", st) - } else { - ui.screen.PutStrStyled(0, 1, string(tcell.RuneULCorner), st) - ui.screen.PutStrStyled(w-1, 1, string(tcell.RuneURCorner), st) - ui.screen.PutStrStyled(0, h-2, string(tcell.RuneLLCorner), st) - ui.screen.PutStrStyled(w-1, h-2, string(tcell.RuneLRCorner), st) - } - - wacc := 0 - for wind := range len(ui.wins) - 1 { - wacc += ui.wins[wind].w + 1 - ui.screen.PutStrStyled(wacc, 1, string(tcell.RuneTTee), st) - for i := 2; i < h-2; i++ { - ui.screen.PutStrStyled(wacc, i, string(tcell.RuneVLine), st) + if style&borderOutline != 0 { + for i := 1; i < w-1; i++ { + ui.screen.PutStrStyled(i, 1, string(tcell.RuneHLine), st) + ui.screen.PutStrStyled(i, h-2, string(tcell.RuneHLine), st) + } + + for i := 2; i < h-2; i++ { + ui.screen.PutStrStyled(0, i, string(tcell.RuneVLine), st) + ui.screen.PutStrStyled(w-1, i, string(tcell.RuneVLine), st) + } + + if style&borderRound != 0 { + ui.screen.PutStrStyled(0, 1, "╭", st) + ui.screen.PutStrStyled(w-1, 1, "╮", st) + ui.screen.PutStrStyled(0, h-2, "╰", st) + ui.screen.PutStrStyled(w-1, h-2, "╯", st) + } else { + ui.screen.PutStrStyled(0, 1, string(tcell.RuneULCorner), st) + ui.screen.PutStrStyled(w-1, 1, string(tcell.RuneURCorner), st) + ui.screen.PutStrStyled(0, h-2, string(tcell.RuneLLCorner), st) + ui.screen.PutStrStyled(w-1, h-2, string(tcell.RuneLRCorner), st) + } + } + + if style&borderSeparators == 0 { + return + } + + top, bot := 1, h-1 + if style&borderOutline != 0 { + top, bot = 2, h-2 + } + + for wind := range len(ui.wins) - 1 { + x := ui.wins[wind].x + ui.wins[wind].w + if style&borderOutline != 0 { + ui.screen.PutStrStyled(x, 1, string(tcell.RuneTTee), st) + } + for y := top; y < bot; y++ { + ui.screen.PutStrStyled(x, y, string(tcell.RuneVLine), st) + } + if style&borderOutline != 0 { + ui.screen.PutStrStyled(x, h-2, string(tcell.RuneBTee), st) } - ui.screen.PutStrStyled(wacc, h-2, string(tcell.RuneBTee), st) } }