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>
This commit is contained in:
1 parent
c1b979371a
commit
165c25b743
7 files changed
+67
-22
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user