Compare commits

...
Author SHA1 Message Date
CatsDeservePets 8b8780299a feat: extend SGR support (#2749)
* feat: support `SGR` color resets and double underline

* test: add cases to TestApplySGR
2026-11-19 23:51:06 +01:00
CatsDeservePets d4b5b4647b docs: document ban on automated PRs in CONTRIBUTING.md (#2746) 2026-11-17 23:03:32 +01:00
valoq bdb4d901d1 fix: reject commands with parse errors (#2640) 2026-11-12 15:00:32 +01:00
valoq 901322f428 fix: skip invalid marks and tags entries (#2541) 2026-11-11 23:17:32 +01:00
dependabot[bot] 9b87b3f2c3 chore(deps): bump golang.org/x/sys from 0.49.0 to 0.50.0 (#2738)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.49.0 to 0.50.0.
- [Commits](https://github.com/golang/sys/compare/v0.49.0...v0.50.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-version: 0.50.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-11-10 23:09:14 +01:00
CatsDeservePets 826c5fc0aa fix: prevent panic in shell-wait (#2736) 2026-11-09 23:14:51 +01:00
CatsDeservePets 59cbc97b50 docs: add code comment explaining draw (#2735) 2026-11-08 23:25:19 +01:00
CatsDeservePets 1d8a32edef feat: improve completion for boolean options (#2733) 2026-11-05 22:52:40 +00:00
valoq a127f13d58 fix: preserve tabs in -remote query output 2026-11-05 22:28:29 +00:00
Yang Baiandybai08 91e269fe5c fix: limit octal escapes in double quotes to three digits (#2725)
The scanner consumed every digit following a backslash as part of an
octal escape. A digit right after an escape was therefore swallowed:
"\0337" (ESC 7) became the single byte 0o337 instead of ESC followed by
"7", and "\0338" (ESC 8) failed to parse and became a NUL byte.

Stop after three digits, as in C and other languages with octal string
escapes. Escapes of up to three digits are read as before.

Co-authored-by: ybai08 <271969568+ybai08@users.noreply.github.com>
2026-11-04 00:55:48 +01:00
CatsDeservePets 5298e8813b docs: update CHANGELOG.md for #2684 (#2731) 2026-11-02 21:44:19 +01:00
CatsDeservePets d816166427 docs: update CHANGELOG.md for #2687, #2701, #2714, #2722 (#2727) 2026-10-30 22:22:59 +01:00
dependabot[bot] fb04a127b0 chore(deps): bump golang.org/x/term from 0.46.0 to 0.47.0 (#2709)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.46.0 to 0.47.0.
- [Commits](https://github.com/golang/term/compare/v0.46.0...v0.47.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-version: 0.47.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-30 01:40:46 +01:00
dependabot[bot] a3aab4380b chore(deps): bump golang.org/x/sys from 0.48.0 to 0.49.0 (#2707)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.48.0 to 0.49.0.
- [Commits](https://github.com/golang/sys/compare/v0.48.0...v0.49.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-version: 0.49.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-30 01:36:04 +01:00
16 changed files with 143 additions and 29 deletions

No files matched your search

+8 -1
View File
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
## Unreleased
### Changed
- The `mark-save` command now displays a list of existing marks (#2722).
### Added
- The `cd` command now supports `-` to change to the previous directory (#2693).
@@ -22,7 +26,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- Readline markers in `promptfmt` are no longer rendered as visible characters (#2657).
- Selecting entries with the mouse no longer causes the file list to jump unexpectedly (#2664).
- A bug where executing the `quit` command multiple times in quick succession could cause `lf` to become unresponsive is now fixed (#2674).
- The home directory abbreviation `~` no longer matches partial directory names (#2679).
- The home directory abbreviation `~` (#2679) and its expansion (#2687) no longer match partial path components.
- A bug where quitting `lf` required an additional key press on some platforms is now fixed (#2684).
- The terminal state is now restored when `lf` receives `SIGHUP`, `SIGQUIT`, or `SIGTERM` (#2701).
- Natural sorting now correctly compares numbers regardless of their length (#2714).
## [r42](https://github.com/gokcehan/lf/releases/tag/r42)
+4
View File
@@ -12,6 +12,10 @@ If your feature can be implemented as a configuration option, **please add it to
For bug fixes, you can simply send a pull request.
## Automated contributions
Pull requests generated entirely by AI tools or submitted as part of mass-submission campaigns are not accepted. Such pull requests may be closed without review and labeled as spam.
## Code conventions
In addition to `gofmt` and friends (e.g. [go vet](https://pkg.go.dev/cmd/vet), [staticcheck](https://staticcheck.dev/), [golangci-lint](https://golangci-lint.run/)), we have a few conventions:
+1 -1
View File
@@ -553,7 +553,7 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pauseAfter bool) {
app.ui.echoerrf("running shell: %s", err)
}
if pauseAfter {
anyKey()
app.ui.anyKey()
}
app.ui.loadFile(app, true)
+2
View File
@@ -187,6 +187,8 @@ func readExpr() <-chan expr {
p := newParser(strings.NewReader(s.Text()))
if p.parse() {
ch <- p.expr
} else if p.err != nil {
ch <- &callExpr{"echoerr", []string{p.err.Error()}, 1}
}
}
}
+14 -2
View File
@@ -201,6 +201,18 @@ func matchWord(s string, words []string) (matches []compMatch, longest string) {
return
}
func matchOpt(s string, words []string) (matches []compMatch, longest string) {
matches, longest = matchWord(s, words)
if strings.HasPrefix(s, "no") {
// Show negated options without their prefix in the menu.
// TODO: Update if a future option ever starts with "no".
for i := range matches {
matches[i].name = matches[i].name[2:]
}
}
return
}
func matchList(s string, words []string) (matches []compMatch, longest string) {
toks := strings.Split(s, ":")
@@ -384,7 +396,7 @@ func completeCmd(s string) (matches []compMatch, longest string) {
switch f[0] {
case "set":
if len(f) == 2 {
matches, longest = matchWord(f[1], gOptWords)
matches, longest = matchOpt(f[1], gOptWords)
break
}
if len(f) != 3 {
@@ -420,7 +432,7 @@ func completeCmd(s string) (matches []compMatch, longest string) {
break
}
if len(f) == 3 {
matches, longest = matchWord(f[2], gLocalOptWords)
matches, longest = matchOpt(f[2], gLocalOptWords)
break
}
if len(f) != 4 {
+2
View File
@@ -1282,6 +1282,8 @@ func (e *callExpr) eval(app *app, _ []string) {
app.ui.echoerrf("sync: %s", err)
}
case "draw":
// Input handlers return this no-op instead of nil to
// trigger the screen update performed by [app.loop].
case "redraw":
app.ui.screen.Sync()
app.ui.renew()
+37
View File
@@ -84,6 +84,18 @@ var gEvalTests = []struct {
[]expr{&callExpr{"echo", []string{"hello\101world"}, 1}},
},
{
`echo "hello\1011world"`,
[]string{"echo", "hello\1011world", "\n"},
[]expr{&callExpr{"echo", []string{"hello\1011world"}, 1}},
},
{
`tty-write "\0337\0338"`,
[]string{"tty-write", "\0337\0338", "\n"},
[]expr{&callExpr{"tty-write", []string{"\0337\0338"}, 1}},
},
{
`echo hello\ world`,
[]string{"echo", "hello world", "\n"},
@@ -661,3 +673,28 @@ func TestApplyLocalBoolOpt(t *testing.T) {
}
}
}
func TestParseErrors(t *testing.T) {
for _, test := range []struct{ inp, err string }{
{`set dupfilefmt %f.~%n~`, `set dupfilefmt: value starting with "%" must be quoted`},
{`setlocal /tmp info $x`, `setlocal /tmp info: value starting with "$" must be quoted`},
{"set", "set: expected option"},
{"setlocal", "setlocal: expected directory"},
{"setlocal /tmp", "setlocal /tmp: expected option"},
{"map x :{{ set hidden }}", `set hidden: unexpected "}}"`},
{"map x ${{ echo", `missing "}}"`},
{"map x :{{\n echo", `missing "}}"`},
{"}}", `unexpected "}}"`},
} {
p := newParser(strings.NewReader(test.inp))
if p.parse() || p.err == nil || p.err.Error() != test.err {
t.Errorf("parse(%q) got error %v, want %q", test.inp, p.err, test.err)
}
}
for _, inp := range []string{`set dupfilefmt "%f.~%n~"`, `set hidden!`, "set hidden", "map x :{{ set hidden; }}", "map x ${{ echo hi }}"} {
p := newParser(strings.NewReader(inp))
if !p.parse() || p.err != nil {
t.Errorf("parse(%q) rejected: %v", inp, p.err)
}
}
}
+2 -2
View File
@@ -7,8 +7,8 @@ require (
github.com/djherbis/times v1.6.0
github.com/fsnotify/fsnotify v1.10.1
github.com/gdamore/tcell/v3 v3.6.0
golang.org/x/sys v0.48.0
golang.org/x/term v0.46.0
golang.org/x/sys v0.50.0
golang.org/x/term v0.47.0
)
require (
+4 -4
View File
@@ -31,13 +31,13 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/sys v0.50.0 h1:dkKZEFTEKaLr1sjhs0WiKqoi8Jj5nHbS3Njmx1UoMJs=
golang.org/x/sys v0.50.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE=
golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc=
golang.org/x/term v0.47.0 h1:cpyOwQkr2Nzxe2p6KnrTG7Ei2wtzjsuSjhpXXepZ/BM=
golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+2 -1
View File
@@ -350,7 +350,8 @@ Options:
if term.IsTerminal(int(os.Stdout.Fd())) {
lines := strings.Split(resp, "\n")
for i := range lines {
lines[i] = sanitizeName(lines[i])
// using sanitizePreview instead of sanitizeName here to preserve tabs for printed tables
lines[i] = sanitizePreview(lines[i])
}
resp = strings.Join(lines, "\n")
}
+6 -4
View File
@@ -1849,7 +1849,8 @@ func (nav *nav) readMarks() error {
for scanner.Scan() {
mark, path, found := strings.Cut(scanner.Text(), ":")
if !found {
return fmt.Errorf("invalid marks file entry: %s", scanner.Text())
err = fmt.Errorf("invalid marks file entry: %q", scanner.Text())
continue
}
if _, ok := nav.marks[mark]; !ok {
nav.marks[mark] = path
@@ -1860,7 +1861,7 @@ func (nav *nav) readMarks() error {
return fmt.Errorf("reading marks file: %w", err)
}
return nil
return err
}
func (nav *nav) writeMarks() error {
@@ -1908,7 +1909,8 @@ func (nav *nav) readTags() error {
ind := strings.LastIndex(text, ":")
if ind == -1 {
return fmt.Errorf("invalid tags file entry: %s", text)
err = fmt.Errorf("invalid tags file entry: %q", text)
continue
}
path := text[0:ind]
@@ -1922,7 +1924,7 @@ func (nav *nav) readTags() error {
return fmt.Errorf("reading tags file: %w", err)
}
return nil
return err
}
func (nav *nav) writeTags() error {
+35 -4
View File
@@ -231,12 +231,21 @@ func (p *parser) parseExpr() expr {
s.scan()
if s.typ != tokenIdent {
p.err = fmt.Errorf("expected identifier: %s", s.tok)
p.err = fmt.Errorf("set: expected option")
return nil
}
opt := s.tok
s.scan()
if s.typ != tokenSemicolon {
if s.typ == tokenPrefix || s.typ == tokenColon {
p.err = fmt.Errorf("set %s: value starting with %q must be quoted", opt, s.tok)
return nil
}
if s.typ != tokenIdent {
p.err = fmt.Errorf("set %s: unexpected %q", opt, s.tok)
return nil
}
val = s.tok
s.scan()
}
@@ -249,18 +258,28 @@ func (p *parser) parseExpr() expr {
s.scan()
if s.typ != tokenIdent {
p.err = fmt.Errorf("expected directory: %s", s.tok)
p.err = fmt.Errorf("setlocal: expected directory")
return nil
}
dir := s.tok
s.scan()
if s.typ != tokenIdent {
p.err = fmt.Errorf("expected identifier: %s", s.tok)
p.err = fmt.Errorf("setlocal %s: expected option", dir)
return nil
}
opt := s.tok
s.scan()
if s.typ != tokenSemicolon {
if s.typ == tokenPrefix || s.typ == tokenColon {
p.err = fmt.Errorf("setlocal %s %s: value starting with %q must be quoted", dir, opt, s.tok)
return nil
}
if s.typ != tokenIdent {
p.err = fmt.Errorf("setlocal %s %s: unexpected %q", dir, opt, s.tok)
return nil
}
val = s.tok
s.scan()
}
@@ -359,6 +378,9 @@ func (p *parser) parseExpr() expr {
for {
e := p.parseExpr()
if e == nil {
if p.err == nil {
p.err = fmt.Errorf(`missing "}}"`)
}
return nil
}
exprs = append(exprs, e)
@@ -391,6 +413,10 @@ func (p *parser) parseExpr() expr {
s.scan()
if s.typ == tokenLBraces {
s.scan()
if s.typ != tokenCommand {
p.err = fmt.Errorf(`missing "}}"`)
return nil
}
expr = s.tok
s.scan()
} else {
@@ -402,7 +428,7 @@ func (p *parser) parseExpr() expr {
result = &execExpr{prefix, expr}
default:
p.err = fmt.Errorf("unexpected token: %s", s.tok)
p.err = fmt.Errorf("unexpected %q", s.tok)
}
return result
@@ -410,5 +436,10 @@ func (p *parser) parseExpr() expr {
func (p *parser) parse() bool {
p.expr = p.parseExpr()
if p.err != nil {
// never evaluate an expression that produced a parse error
p.expr = nil
return false
}
return p.expr != nil
}
+3 -1
View File
@@ -237,8 +237,10 @@ scan:
case s.chr == 'v':
buf = append(buf, '\v')
case isDigit(s.chr):
// like C, an octal escape is at most three digits long
// so that "\0337" is read as "\033" followed by "7"
var oct []byte
for isDigit(s.chr) {
for len(oct) < 3 && isDigit(s.chr) {
oct = append(oct, s.chr)
s.next()
}
+7 -1
View File
@@ -162,7 +162,7 @@ loop:
st = st.Underline(false)
case "4", "4:1":
st = st.Underline(true)
case "4:2":
case "4:2", "21":
st = st.Underline(tcell.UnderlineStyleDouble)
case "4:3":
st = st.Underline(tcell.UnderlineStyleCurly)
@@ -205,6 +205,8 @@ loop:
}
st = st.Foreground(color)
i += offset
case "39":
st = st.Foreground(tcell.ColorDefault)
case "40", "41", "42", "43", "44", "45", "46", "47":
n, _ := strconv.Atoi(toks[i])
st = st.Background(tcell.PaletteColor(n - 40))
@@ -219,6 +221,8 @@ loop:
}
st = st.Background(color)
i += offset
case "49":
st = st.Background(tcell.ColorDefault)
case "58":
color, offset, err := parseColor(toks[i+1:])
if err != nil {
@@ -227,6 +231,8 @@ loop:
}
st = st.Underline(color)
i += offset
case "59":
st = st.Underline(tcell.ColorDefault)
default:
log.Printf("unknown ANSI code: %s", toks[i])
}
+4
View File
@@ -230,6 +230,7 @@ func TestApplySGR(t *testing.T) {
{"4:0", none.Underline(true), none},
{"4:1", none, none.Underline(true)},
{"4:2", none, none.Underline(tcell.UnderlineStyleDouble)},
{"21", none, none.Underline(tcell.UnderlineStyleDouble)},
{"4:3", none, none.Underline(tcell.UnderlineStyleCurly)},
{"4:4", none, none.Underline(tcell.UnderlineStyleDotted)},
{"4:5", none, none.Underline(tcell.UnderlineStyleDashed)},
@@ -244,9 +245,11 @@ func TestApplySGR(t *testing.T) {
{"31", none, none.Foreground(color.Maroon)},
{"31", none.Foreground(color.Green), none.Foreground(color.Maroon)},
{"31", none.Foreground(color.Green).Bold(true), none.Foreground(color.Maroon).Bold(true)},
{"39", none.Foreground(color.Maroon).Bold(true), none.Bold(true)},
{"41", none, none.Background(color.Maroon)},
{"41", none.Background(color.Green), none.Background(color.Maroon)},
{"49", none.Background(color.Maroon).Bold(true), none.Bold(true)},
{"1;31", none, none.Foreground(color.Maroon).Bold(true)},
{"1;31", none.Foreground(color.Green), none.Foreground(color.Maroon).Bold(true)},
@@ -276,6 +279,7 @@ func TestApplySGR(t *testing.T) {
{"38;2;5;102;8", none, none.Foreground(tcell.NewRGBColor(5, 102, 8))},
{"48;2;0;48;143", none, none.Background(tcell.NewRGBColor(0, 48, 143))},
{"59", none.Underline(true, color.Maroon), none.Underline(true)},
// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446
{"38;5;34;1", none, none.Foreground(color.XTerm34).Bold(true)},
+12 -8
View File
@@ -1605,22 +1605,26 @@ func (ui *ui) exportSizes() {
os.Setenv("lf_height", strconv.Itoa(h))
}
func anyKey() {
fmt.Fprint(os.Stderr, gOpts.waitmsg)
defer fmt.Fprintln(os.Stderr)
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
func (ui *ui) anyKey() {
fd := int(os.Stdin.Fd())
oldState, err := term.MakeRaw(fd)
if err != nil {
panic(err)
ui.echoerrf("enabling raw mode: %s", err)
return
}
defer fmt.Fprintln(os.Stderr)
defer func() {
if err := term.Restore(int(os.Stdin.Fd()), oldState); err != nil {
panic(err)
if err := term.Restore(fd, oldState); err != nil {
ui.echoerrf("restoring terminal state: %s", err)
}
}()
fmt.Fprint(os.Stderr, gOpts.waitmsg)
b := make([]byte, 8)
if _, err := os.Stdin.Read(b); err != nil {
log.Printf("reading key press: %s", err)
ui.echoerrf("reading key press: %s", err)
}
}