From 165c25b743b4ee2a5460bcb7ed2dd23ef9c43e96 Mon Sep 17 00:00:00 2001 From: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com> Date: Wed, 31 Dec 2025 07:36:31 +0100 Subject: [PATCH] feat: add `mergeindicators` option (#2330) * feat: add `mergeindicators` option * docs: update `CHANGELOG.md` * docs: add documentation * style: fix typo Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com> --------- Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com> --- CHANGELOG.md | 1 + doc.md | 6 ++++++ doc.txt | 8 +++++++ eval.go | 2 ++ lf.1 | 9 +++++++- opts.go | 2 ++ ui.go | 61 ++++++++++++++++++++++++++++++++++------------------ 7 files changed, 67 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48bba051..3647866f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A new server command `list` is added to print the IDs of all currently connected clients (#2314). - The `previewer` and `cleaner` scripts now have their `stderr` output logged (#2316). +- A new option `mergeindicators` is added to reduce the gap before filenames, by merging tag and selection indicators into a single column (#2330). ### Fixed diff --git a/doc.md b/doc.md index 291f3eb2..0e89048f 100644 --- a/doc.md +++ b/doc.md @@ -287,6 +287,7 @@ The following options can be used to customize the behavior of lf: menufmt string (default "\033[0m") menuheaderfmt string (default "\033[1m") menuselectfmt string (default "\033[7m") + mergeindicators bool (default false) mouse bool (default false) number bool (default false) numberfmt string (default "\033[33m") @@ -1018,6 +1019,11 @@ Format string of the header row in the menu. Format string of the currently selected item in the menu. +## mergeindicators (bool) (default false) + +When `mergeindicators` is enabled, tag and selection indicators are drawn in a single column to reduce the gap before filenames. +If a file is both tagged and selected, the tag uses the selection format (e.g. `copyfmt`) instead of `tagfmt`. + ## mouse (bool) (default false) Send mouse events as input. diff --git a/doc.txt b/doc.txt index cb7a2088..234c5344 100644 --- a/doc.txt +++ b/doc.txt @@ -299,6 +299,7 @@ The following options can be used to customize the behavior of lf: menufmt string (default "\033[0m") menuheaderfmt string (default "\033[1m") menuselectfmt string (default "\033[7m") + mergeindicators bool (default false) mouse bool (default false) number bool (default false) numberfmt string (default "\033[33m") @@ -1098,6 +1099,13 @@ menuselectfmt (string) (default \033[7m) Format string of the currently selected item in the menu. +mergeindicators (bool) (default false) + +When mergeindicators is enabled, tag and selection indicators are drawn +in a single column to reduce the gap before filenames. If a file is both +tagged and selected, the tag uses the selection format (e.g. copyfmt) +instead of tagfmt. + mouse (bool) (default false) Send mouse events as input. diff --git a/eval.go b/eval.go index b89def17..6108296f 100644 --- a/eval.go +++ b/eval.go @@ -120,6 +120,8 @@ func (e *setExpr) eval(app *app, _ []string) { err = applyBoolOpt(&gOpts.incfilter, e) case "incsearch", "noincsearch", "incsearch!": err = applyBoolOpt(&gOpts.incsearch, e) + case "mergeindicators", "nomergeindicators", "mergeindicators!": + err = applyBoolOpt(&gOpts.mergeindicators, e) case "mouse", "nomouse", "mouse!": err = applyBoolOpt(&gOpts.mouse, e) if err == nil { diff --git a/lf.1 b/lf.1 index b25510e9..6e93293c 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.7.0.2 .\" -.TH "LF" "1" "2025\-12\-21" "r41" "DOCUMENTATION" +.TH "LF" "1" "2025\-12\-31" "r41" "DOCUMENTATION" .SH NAME lf \- terminal file manager .SH SYNOPSIS @@ -311,6 +311,7 @@ infotimefmtold string (default \(aqJan _2 2006\(aq) menufmt string (default \(dq\(rs033[0m\(dq) menuheaderfmt string (default \(dq\(rs033[1m\(dq) menuselectfmt string (default \(dq\(rs033[7m\(dq) +mergeindicators bool (default false) mouse bool (default false) number bool (default false) numberfmt string (default \(dq\(rs033[33m\(dq) @@ -972,6 +973,12 @@ Format string of the menu. Format string of the header row in the menu. .SS menuselectfmt (string) (default \f[CR]\(rs033[7m\f[R]) Format string of the currently selected item in the menu. +.SS mergeindicators (bool) (default false) +When \f[CR]mergeindicators\f[R] is enabled, tag and selection indicators +are drawn in a single column to reduce the gap before filenames. +If a file is both tagged and selected, the tag uses the selection format +(e.g. +\f[CR]copyfmt\f[R]) instead of \f[CR]tagfmt\f[R]. .SS mouse (bool) (default false) Send mouse events as input. .SS number (bool) (default false) diff --git a/opts.go b/opts.go index d6c8f878..f9df1de8 100644 --- a/opts.go +++ b/opts.go @@ -78,6 +78,7 @@ var gOpts struct { menufmt string menuheaderfmt string menuselectfmt string + mergeindicators bool mouse bool number bool numberfmt string @@ -240,6 +241,7 @@ func init() { gOpts.menufmt = "\033[0m" gOpts.menuheaderfmt = "\033[1m" gOpts.menuselectfmt = "\033[7m" + gOpts.mergeindicators = false gOpts.mouse = false gOpts.number = false gOpts.numberfmt = "\033[33m" diff --git a/ui.go b/ui.go index c4989490..b302fe43 100644 --- a/ui.go +++ b/ui.go @@ -419,6 +419,12 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty } } + indOff, tagOff, nameOff := lnwidth, lnwidth, lnwidth+1 + if !gOpts.mergeindicators { + tagOff++ + nameOff++ + } + visualSelections := dir.visualSelections() for i, f := range dir.files[beg:end] { st := dirStyle.colors.get(f) @@ -458,8 +464,18 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty fmtStr = gOpts.cutfmt } } + + tag := " " + if val, ok := context.tags[path]; ok && len(val) > 0 { + tag = val + } + if fmtStr != "" { - win.print(ui.screen, lnwidth, i, parseEscapeSequence(fmtStr), " ") + ind := " " + if gOpts.mergeindicators { + ind = tag + } + win.print(ui.screen, indOff, i, parseEscapeSequence(fmtStr), ind) } // make space for select marker, and leave another space at the end @@ -469,11 +485,6 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty maxWidth-- } - tag := " " - if val, ok := context.tags[path]; ok && len(val) > 0 { - tag = val - } - var icon []rune var iconDef iconDef if gOpts.icons { @@ -481,10 +492,14 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty icon = slices.Concat([]rune(iconDef.icon), []rune{' '}) } - // subtract space for tag and icon - maxFilenameWidth := maxWidth - 1 - runeSliceWidth(icon) + // subtract space for icon + maxFilenameWidth := maxWidth - runeSliceWidth(icon) + // subtract space for tag if not merged with selection marker + if !gOpts.mergeindicators { + maxFilenameWidth-- + } - info, custom, off := fileInfo(f, dir, userWidth, groupWidth, customWidth) + info, custom, customOff := fileInfo(f, dir, userWidth, groupWidth, customWidth) infolen := len(info) showInfo := infolen > 0 && 2*infolen < maxWidth if showInfo { @@ -498,7 +513,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty if showInfo { filename = append(filename, []rune(info)...) - off += lnwidth + 2 + runeSliceWidth(icon) + maxFilenameWidth + customOff += nameOff + runeSliceWidth(icon) + maxFilenameWidth } if i == dir.pos { @@ -513,21 +528,25 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty } // print tag separately as it can contain color escape sequences - win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorFmt, tag)) + if !gOpts.mergeindicators || fmtStr == "" { + win.print(ui.screen, tagOff, i, st, fmt.Sprintf(cursorFmt, tag)) + } line := slices.Concat(icon, filename, []rune{' '}) - win.print(ui.screen, lnwidth+2, i, st, fmt.Sprintf(cursorFmt, string(line))) + win.print(ui.screen, nameOff, i, st, fmt.Sprintf(cursorFmt, string(line))) // print over the empty space we reserved for the custom info if showInfo && custom != "" { - win.print(ui.screen, off, i, st, fmt.Sprintf(cursorFmt, stripTermSequence(custom))) + win.print(ui.screen, customOff, i, st, fmt.Sprintf(cursorFmt, stripTermSequence(custom))) } } else { - if tag == " " { - win.print(ui.screen, lnwidth+1, i, st, " ") - } else { - tagStr := fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag) - win.print(ui.screen, lnwidth+1, i, tcell.StyleDefault, tagStr) + if !gOpts.mergeindicators || fmtStr == "" { + if tag == " " { + win.print(ui.screen, tagOff, i, st, " ") + } else { + tagStr := fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag) + win.print(ui.screen, tagOff, i, tcell.StyleDefault, tagStr) + } } if len(icon) > 0 { @@ -535,15 +554,15 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty if iconDef.hasStyle { iconStyle = iconDef.style } - win.print(ui.screen, lnwidth+2, i, iconStyle, string(icon)) + win.print(ui.screen, nameOff, i, iconStyle, string(icon)) } line := slices.Concat(filename, []rune{' '}) - win.print(ui.screen, lnwidth+2+runeSliceWidth(icon), i, st, string(line)) + win.print(ui.screen, nameOff+runeSliceWidth(icon), i, st, string(line)) // print over the empty space we reserved for the custom info if showInfo && custom != "" { - win.print(ui.screen, off, i, st, custom) + win.print(ui.screen, customOff, i, st, custom) } } }