Compare commits

27 Commits
Author SHA1 Message Date
Joe Lim 3d205f05e3 Prepare for r35 release (#1967) 2025-04-25 11:23:45 +10:00
Joe Lim 1cb9e9d14a Add tty-write command (#1961)
This command offers a synchronized way to write to /dev/tty.
2025-04-13 11:14:00 +10:00
Joe Lim 0df0c0f5ff Simpler implementation of dirpreviews (#1958) 2025-04-10 15:34:13 +10:00
Joe Lim 3d5a418c6c Use Screen.Clear for clearing the screen (#1957) 2025-04-09 21:51:05 +10:00
Joe Lim 841cc3da06 Handle arrow keys when waiting for key press (#1956) 2025-04-09 19:03:19 +10:00
MahouShoujoMivutilde 1878faa942 Implement files query to export files in the current directory as (#1949)
presented in lf (including filter/sorting)

`lf -remote "query $id files"`

This version updates `files` list only before running shell commands.
2025-04-09 16:37:55 +10:00
dependabot[bot] 3fdd991040 Bump github.com/fsnotify/fsnotify from 1.8.0 to 1.9.0 (#1953)
Bumps [github.com/fsnotify/fsnotify](https://github.com/fsnotify/fsnotify) from 1.8.0 to 1.9.0.
- [Release notes](https://github.com/fsnotify/fsnotify/releases)
- [Changelog](https://github.com/fsnotify/fsnotify/blob/main/CHANGELOG.md)
- [Commits](https://github.com/fsnotify/fsnotify/compare/v1.8.0...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/fsnotify/fsnotify
  dependency-version: 1.9.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>
2025-04-07 14:38:00 +10:00
dependabot[bot] 9cad75867d Bump golang.org/x/term from 0.30.0 to 0.31.0 (#1952)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.30.0 to 0.31.0.
- [Commits](https://github.com/golang/term/compare/v0.30.0...v0.31.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-version: 0.31.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>
2025-04-07 14:37:48 +10:00
dependabot[bot] 970b31852d Bump golang.org/x/text from 0.23.0 to 0.24.0 (#1951)
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.23.0 to 0.24.0.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.23.0...v0.24.0)

---
updated-dependencies:
- dependency-name: golang.org/x/text
  dependency-version: 0.24.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>
2025-04-07 14:32:19 +10:00
Joe Lim ffe4c97560 Change menu contents to be a string (#1954) 2025-04-07 14:23:25 +10:00
Joe Lim 6718a36334 Bump dependencies (#1941) 2025-03-30 16:37:32 +11:00
Joe Lim ad6fa3fa73 Fix crash if log file can't be opened (#1937) 2025-03-21 18:56:13 +11:00
Joe Lim 9b1f8386fa Add support for underline colors (#1933) 2025-03-15 13:01:17 +11:00
Joe Lim 26259f777f Add function for parsing SGR colors (#1932)
* Add function for parsing SGR colors

* Change error message

* Fix break out of loop

* Fix typo
2025-03-15 12:37:44 +11:00
Dusan Lesan 9dc4e6b431 Update screenshots (#1924)
cc #1919
2025-03-06 09:50:25 +11:00
Joe Lim 0e66d02746 Use clear for clearing maps (#1923) 2025-02-23 19:56:50 +11:00
Joe Lim 938e02e126 cleanup (#1922) 2025-02-23 17:14:19 +11:00
David Pedersen 2a3292560d Apply modernization fixes (#1921) 2025-02-23 17:05:20 +11:00
Joe Lim f9813744f7 Add dircounts to setlocal options (#1920)
* Remove plural from setlocal variable names

* Add `dircounts` for `setlocal`

* Update documentation

* Fix failing test
2025-02-19 10:43:15 +11:00
valoqandJoe Lim b087bf7d80 verify the Trash directory exists before moving files there (#1918)
* verify the Trash directory exists before moving files there

* Update etc/lfrc.example

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>

---------

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>
2025-02-19 10:38:33 +11:00
David Pedersen c42942d53e Remove redundant strconv in diacritics test (#1917) 2025-02-14 15:45:21 +11:00
Joe Lim 74b2954e6a Handle leading zeros in SGR escape sequences (#1912) 2025-02-10 17:13:34 +11:00
Penn Bauman 7797ad695f fix non-constant format string (#1910) 2025-02-10 12:04:49 +11:00
Joe Lim b3c652c4d4 Add support for underline styles (#1896) 2025-02-09 23:39:15 +11:00
dependabot[bot] 3b56a9fa64 Bump github.com/Xuanwo/go-locale from 1.1.2 to 1.1.3 (#1902)
Bumps [github.com/Xuanwo/go-locale](https://github.com/Xuanwo/go-locale) from 1.1.2 to 1.1.3.
- [Release notes](https://github.com/Xuanwo/go-locale/releases)
- [Changelog](https://github.com/Xuanwo/go-locale/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Xuanwo/go-locale/compare/v1.1.2...v1.1.3)

---
updated-dependencies:
- dependency-name: github.com/Xuanwo/go-locale
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-09 23:24:43 +11:00
dependabot[bot] 5b1ec5b6fc Bump golang.org/x/text from 0.21.0 to 0.22.0 (#1906)
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.21.0 to 0.22.0.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.21.0...v0.22.0)

---
updated-dependencies:
- dependency-name: golang.org/x/text
  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>
2025-02-09 23:17:03 +11:00
dependabot[bot] ec42237563 Bump golang.org/x/term from 0.28.0 to 0.29.0 (#1905)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.28.0 to 0.29.0.
- [Commits](https://github.com/golang/term/compare/v0.28.0...v0.29.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  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>
2025-02-09 23:09:23 +11:00
23 changed files with 399 additions and 356 deletions

No files matched your search

+2 -2
View File
@@ -12,8 +12,8 @@
`lf` (as in "list files") is a terminal file manager written in Go with a heavy inspiration from [`ranger`](https://github.com/ranger/ranger) file manager.
See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
![multicol-screenshot](http://i.imgur.com/DaTUenu.png)
![singlecol-screenshot](http://i.imgur.com/p95xzUj.png)
![icons-and-border](https://github.com/user-attachments/assets/d5623462-05ab-4921-aeb3-d377d4732f9e)
![image-preview](https://github.com/user-attachments/assets/9ff42a21-19dd-42fa-8407-5d055aa9d561)
## Features
+6 -8
View File
@@ -258,7 +258,6 @@ func (app *app) writeHistory() error {
// separate goroutines and sent here for update.
func (app *app) loop() {
go app.nav.previewLoop(app.ui)
go app.nav.dirPreviewLoop(app.ui)
var serverChan <-chan expr
if !gSingleMode {
@@ -336,7 +335,6 @@ func (app *app) loop() {
app.quit()
app.nav.previewChan <- ""
app.nav.dirPreviewChan <- nil
log.Print("bye!")
@@ -510,7 +508,6 @@ func (app *app) loop() {
func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
app.nav.previewChan <- ""
app.nav.dirPreviewChan <- nil
if err := app.ui.suspend(); err != nil {
log.Printf("suspend: %s", err)
@@ -547,11 +544,12 @@ func (app *app) runShell(s string, args []string, prefix string) {
exportOpts()
gState.mutex.Lock()
gState.data["maps"] = listBinds(gOpts.keys).String()
gState.data["cmaps"] = listBinds(gOpts.cmdkeys).String()
gState.data["cmds"] = listCmds().String()
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd).String()
gState.data["history"] = listHistory(app.cmdHistory).String()
gState.data["maps"] = listBinds(gOpts.keys)
gState.data["cmaps"] = listBinds(gOpts.cmdkeys)
gState.data["cmds"] = listCmds()
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)
gState.data["history"] = listHistory(app.cmdHistory)
gState.data["files"] = listFilesInCurrDir(app.nav)
gState.mutex.Unlock()
cmd := shellCommand(s, args)
+13 -13
View File
@@ -26,6 +26,19 @@ func init() {
}
func run() {
if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
log.Fatalf("failed to open log file: %s", err)
}
defer f.Close()
log.SetOutput(f)
} else {
log.SetOutput(io.Discard)
}
log.Print("hi!")
var screen tcell.Screen
var err error
if screen, err = tcell.NewScreen(); err != nil {
@@ -37,19 +50,6 @@ func run() {
screen.EnableMouse()
}
if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
panic(err)
}
defer f.Close()
log.SetOutput(f)
} else {
log.SetOutput(io.Discard)
}
log.Print("hi!")
ui := newUI(screen)
nav := newNav(ui.wins[0].h)
app := newApp(ui, nav)
+92 -56
View File
@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"os"
"path/filepath"
@@ -95,86 +96,121 @@ func parseEscapeSequence(s string) tcell.Style {
return applyAnsiCodes(s, tcell.StyleDefault)
}
func parseColor(toks []string) (tcell.Color, int, error) {
if len(toks) == 0 {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
if toks[0] == "5" && len(toks) >= 2 {
n, err := strconv.Atoi(toks[1])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
return tcell.PaletteColor(n), 2, nil
}
if toks[0] == "2" && len(toks) >= 4 {
r, err := strconv.Atoi(toks[1])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
g, err := strconv.Atoi(toks[2])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
b, err := strconv.Atoi(toks[3])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
return tcell.NewRGBColor(int32(r), int32(g), int32(b)), 4, nil
}
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
toks := strings.Split(s, ";")
nums := make([]int, 0, len(toks))
for _, tok := range toks {
if tok == "" {
nums = append(nums, 0)
continue
}
n, err := strconv.Atoi(tok)
if err != nil {
log.Printf("converting escape code: %s", err)
continue
}
nums = append(nums, n)
}
// ECMA-48 details the standard
// TODO: should we support turning off attributes?
// Probably because this is used for previewers too
numslen := len(nums)
for i := 0; i < numslen; i++ {
n := nums[i]
switch {
case n == 0:
tokslen := len(toks)
loop:
for i := 0; i < tokslen; i++ {
switch strings.TrimLeft(toks[i], "0") {
case "":
st = tcell.StyleDefault
case n == 1:
case "1":
st = st.Bold(true)
case n == 2:
case "2":
st = st.Dim(true)
case n == 3:
case "3":
st = st.Italic(true)
case n == 4:
case "4:0":
st = st.Underline(false)
case "4", "4:1":
st = st.Underline(true)
case n == 5 || n == 6:
case "4:2":
st = st.Underline(tcell.UnderlineStyleDouble)
case "4:3":
st = st.Underline(tcell.UnderlineStyleCurly)
case "4:4":
st = st.Underline(tcell.UnderlineStyleDotted)
case "4:5":
st = st.Underline(tcell.UnderlineStyleDashed)
case "5", "6":
st = st.Blink(true)
case n == 7:
case "7":
st = st.Reverse(true)
case n == 8:
case "8":
// TODO: tcell PR for proper conceal
_, bg, _ := st.Decompose()
st = st.Foreground(bg)
case n == 9:
case "9":
st = st.StrikeThrough(true)
case n >= 30 && n <= 37:
case "30", "31", "32", "33", "34", "35", "36", "37":
n, _ := strconv.Atoi(toks[i])
st = st.Foreground(tcell.PaletteColor(n - 30))
case n >= 90 && n <= 97:
case "90", "91", "92", "93", "94", "95", "96", "97":
n, _ := strconv.Atoi(toks[i])
st = st.Foreground(tcell.PaletteColor(n - 82))
case n == 38:
if i+3 <= numslen && nums[i+1] == 5 {
st = st.Foreground(tcell.PaletteColor(nums[i+2]))
i += 2
} else if i+5 <= numslen && nums[i+1] == 2 {
st = st.Foreground(tcell.NewRGBColor(
int32(nums[i+2]),
int32(nums[i+3]),
int32(nums[i+4])))
i += 4
} else {
log.Printf("unknown ansi code or incorrect form: %d", n)
case "38":
color, offset, err := parseColor(toks[i+1:])
if err != nil {
log.Printf("error processing ansi code 38: %s", err)
break loop
}
case n >= 40 && n <= 47:
st = st.Foreground(color)
i += offset
case "40", "41", "42", "43", "44", "45", "46", "47":
n, _ := strconv.Atoi(toks[i])
st = st.Background(tcell.PaletteColor(n - 40))
case n >= 100 && n <= 107:
case "100", "101", "102", "103", "104", "105", "106", "107":
n, _ := strconv.Atoi(toks[i])
st = st.Background(tcell.PaletteColor(n - 92))
case n == 48:
if i+3 <= numslen && nums[i+1] == 5 {
st = st.Background(tcell.PaletteColor(nums[i+2]))
i += 2
} else if i+5 <= numslen && nums[i+1] == 2 {
st = st.Background(tcell.NewRGBColor(
int32(nums[i+2]),
int32(nums[i+3]),
int32(nums[i+4])))
i += 4
} else {
log.Printf("unknown ansi code or incorrect form: %d", n)
case "48":
color, offset, err := parseColor(toks[i+1:])
if err != nil {
log.Printf("error processing ansi code 48: %s", err)
break loop
}
st = st.Background(color)
i += offset
case "58":
color, offset, err := parseColor(toks[i+1:])
if err != nil {
log.Printf("error processing ansi code 58: %s", err)
break loop
}
st = st.Underline(color)
i += offset
default:
log.Printf("unknown ansi code: %d", n)
log.Printf("unknown ansi code: %s", toks[i])
}
}
+40
View File
@@ -6,6 +6,35 @@ import (
"github.com/gdamore/tcell/v2"
)
func TestParseColor(t *testing.T) {
tests := []struct {
toks []string
color tcell.Color
offset int
success bool
}{
{[]string{}, tcell.ColorDefault, 0, false},
{[]string{"foo"}, tcell.ColorDefault, 0, false},
{[]string{"5"}, tcell.ColorDefault, 0, false},
{[]string{"5", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"5", "42"}, tcell.PaletteColor(42), 2, true},
{[]string{"2"}, tcell.ColorDefault, 0, false},
{[]string{"2", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"2", "42", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"2", "42", "43", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"2", "42", "43", "44"}, tcell.NewRGBColor(42, 43, 44), 4, true},
}
for _, test := range tests {
color, offset, err := parseColor(test.toks)
success := err == nil
if color != test.color || offset != test.offset || success != test.success {
t.Errorf("at input %v expected (%v, %v, %v) but got (%v, %v, %v)",
test.toks, test.color, test.offset, test.success, color, offset, success)
}
}
}
func TestApplyAnsiCodes(t *testing.T) {
none := tcell.StyleDefault
@@ -35,6 +64,14 @@ func TestApplyAnsiCodes(t *testing.T) {
{"4", none.Bold(true), none.Bold(true).Underline(true)},
{"4", none.Foreground(tcell.ColorMaroon).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true).Underline(true)},
{"4:0", none, none},
{"4:0", none.Underline(true), none},
{"4:1", none, none.Underline(true)},
{"4:2", 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)},
{"31", none, none.Foreground(tcell.ColorMaroon)},
{"31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
{"31", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
@@ -45,6 +82,9 @@ func TestApplyAnsiCodes(t *testing.T) {
{"1;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"1;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"01;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"01;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
{"38;5;8", none, none.Foreground(tcell.ColorGray)},
+4 -3
View File
@@ -80,6 +80,7 @@ var (
"mark-remove",
"tag",
"tag-toggle",
"tty-write",
"cmd-escape",
"cmd-complete",
"cmd-menu-complete",
@@ -116,7 +117,7 @@ var (
func getOptWords(opts any) (optWords []string) {
t := reflect.TypeOf(opts)
for i := 0; i < t.NumField(); i++ {
for i := range t.NumField() {
field := t.Field(i)
switch field.Type.Kind() {
case reflect.Map:
@@ -134,9 +135,9 @@ func getOptWords(opts any) (optWords []string) {
func getLocalOptWords(localOpts any) (localOptWords []string) {
t := reflect.TypeOf(localOpts)
for i := 0; i < t.NumField(); i++ {
for i := range t.NumField() {
field := t.Field(i)
name := strings.TrimSuffix(field.Name, "s")
name := field.Name
if field.Type.Kind() != reflect.Map {
continue
}
+4 -4
View File
@@ -79,10 +79,10 @@ func TestGetLocalOptWords(t *testing.T) {
localOpts any
exp []string
}{
{struct{ features map[string]bool }{}, []string{"feature", "feature!", "nofeature"}},
{struct{ features map[string]int }{}, []string{"feature"}},
{struct{ features map[string]string }{}, []string{"feature"}},
{struct{ features map[string][]string }{}, []string{"feature"}},
{struct{ feature map[string]bool }{}, []string{"feature", "feature!", "nofeature"}},
{struct{ feature map[string]int }{}, []string{"feature"}},
{struct{ feature map[string]string }{}, []string{"feature"}},
{struct{ feature map[string][]string }{}, []string{"feature"}},
}
for _, test := range tests {
+5 -6
View File
@@ -1,7 +1,6 @@
package main
import (
"strconv"
"testing"
)
@@ -63,10 +62,10 @@ func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacr
gOpts.smartdia = smartdiacritics
matched, _ := searchMatch(base, pattern, false)
if matched != expected {
t.Errorf("False search for" +
" ignorecase = " + strconv.FormatBool(gOpts.ignorecase) + ", " +
" smartcase = " + strconv.FormatBool(gOpts.smartcase) + ", " +
" ignoredia = " + strconv.FormatBool(gOpts.ignoredia) + ", " +
" smartdia = " + strconv.FormatBool(gOpts.smartdia) + ", ")
t.Errorf("False search for ignorecase = %t, smartcase = %t, ignoredia = %t, smartdia = %t",
gOpts.ignorecase,
gOpts.smartcase,
gOpts.ignoredia,
gOpts.smartdia)
}
}
+11 -3
View File
@@ -102,6 +102,7 @@ The following commands are provided by lf:
mark-remove (modal) (default '"')
tag
tag-toggle (default 't')
tty-write
The following command line commands are provided by lf:
@@ -569,6 +570,12 @@ You can define a new tag-clearing command by combining `tag` with `tag-toggle` (
Tag a file with `*` or a single width character given in the argument if the file is untagged, otherwise remove the tag.
## tty-write
Write the given string to the tty.
This is useful for sending escape sequences to the terminal to control its behavior (e.g. OSC 0 to set the window title).
Using `tty-write` is preferred over directly writing to `/dev/tty` because the latter is not synchronized and can interfere with drawing the UI.
# COMMAND LINE COMMANDS
The prompt character specifies which of the several command-line modes you are in.
@@ -1196,7 +1203,7 @@ Command `set` is used to set an option which can be a boolean, integer, or strin
set sortby "time" # string value with double quotes (backslash escapes)
Command `setlocal` is used to set a local option for a directory which can be a boolean or string.
Currently supported local options are `dirfirst`, `dironly`, `hidden`, `info`, `reverse`, `sortby` and `locale`.
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse`, `sortby` and `locale`.
Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets the option for the given directory along with its subdirectories:
setlocal /foo/bar hidden # boolean enable
@@ -1470,6 +1477,7 @@ The following types of information are supported:
cmds list of commands created by the 'cmd' command
jumps contents of the jump list, showing previously visited locations
history list of previously executed commands on the command line
files list of files in the currently open directory as displayed by lf, empty if dir is still loading
This is useful for scripting actions based on the internal state of lf.
For example, to select a previous command using fzf and execute it:
@@ -1680,11 +1688,11 @@ You can define it just as you would define any other command:
'
}}
If you want to print escape sequences, you may redirect `printf` output to `/dev/tty`.
If you want to send escape sequences to the terminal, you can use the `tty-write` command to do so.
The following xterm-specific escape sequence sets the terminal title to the working directory:
cmd on-cd &{{
printf "\033]0; $PWD\007" > /dev/tty
lf -remote "send $id tty-write \"\033]0;$PWD\007\""
}}
This command runs whenever you change the directory but not on startup.
+18 -8
View File
@@ -92,6 +92,7 @@ The following commands are provided by lf:
mark-remove (modal) (default '"')
tag
tag-toggle (default 't')
tty-write
The following command line commands are provided by lf:
@@ -588,6 +589,14 @@ tag-toggle (default t)
Tag a file with * or a single width character given in the argument if
the file is untagged, otherwise remove the tag.
tty-write
Write the given string to the tty. This is useful for sending escape
sequences to the terminal to control its behavior (e.g. OSC 0 to set the
window title). Using tty-write is preferred over directly writing to
/dev/tty because the latter is not synchronized and can interfere with
drawing the UI.
COMMAND LINE COMMANDS
The prompt character specifies which of the several command-line modes
@@ -1320,10 +1329,10 @@ string:
set sortby "time" # string value with double quotes (backslash escapes)
Command setlocal is used to set a local option for a directory which can
be a boolean or string. Currently supported local options are dirfirst,
dironly, hidden, info, reverse, sortby and locale. Adding a trailing
path separator (i.e. / for Unix and \ for Windows) sets the option for
the given directory along with its subdirectories:
be a boolean or string. Currently supported local options are dircounts,
dirfirst, dironly, hidden, info, reverse, sortby and locale. Adding a
trailing path separator (i.e. / for Unix and \ for Windows) sets the
option for the given directory along with its subdirectories:
setlocal /foo/bar hidden # boolean enable
setlocal /foo/bar hidden true # boolean enable
@@ -1634,6 +1643,7 @@ The following types of information are supported:
cmds list of commands created by the 'cmd' command
jumps contents of the jump list, showing previously visited locations
history list of previously executed commands on the command line
files list of files in the currently open directory as displayed by lf, empty if dir is still loading
This is useful for scripting actions based on the internal state of lf.
For example, to select a previous command using fzf and execute it:
@@ -1892,12 +1902,12 @@ would define any other command:
'
}}
If you want to print escape sequences, you may redirect printf output to
/dev/tty. The following xterm-specific escape sequence sets the terminal
title to the working directory:
If you want to send escape sequences to the terminal, you can use the
tty-write command to do so. The following xterm-specific escape sequence
sets the terminal title to the working directory:
cmd on-cd &{{
printf "\033]0; $PWD\007" > /dev/tty
lf -remote "send $id tty-write \"\033]0;$PWD\007\""
}}
This command runs whenever you change the directory but not on startup.
+1 -1
View File
@@ -60,7 +60,7 @@ map a :push %mkdir<space>
# move current file or selected files to trash folder
# (also see 'man mv' for backup/overwrite options)
cmd trash %set -f; mv $fx ~/.trash
cmd trash %set -f; mv -t ~/.trash $fx
# define a custom 'delete' command
# cmd delete ${{
+45 -30
View File
@@ -90,7 +90,7 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.renew()
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
clear(app.nav.regCache)
if gOpts.sixel {
app.ui.sxScreen.lastFile = ""
}
@@ -349,7 +349,7 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ratios = rats
app.ui.wins = getWins(app.ui.screen)
if gOpts.sixel {
app.nav.regCache = make(map[string]*reg)
clear(app.nav.regCache)
app.ui.sxScreen.lastFile = ""
}
app.ui.loadFile(app, true)
@@ -462,14 +462,16 @@ func (e *setLocalExpr) eval(app *app, args []string) {
var err error
switch e.opt {
case "dircounts", "nodircounts", "dircounts!":
err = applyLocalBoolOpt(gLocalOpts.dircounts, gOpts.dircounts, e)
case "dirfirst", "nodirfirst", "dirfirst!":
err = applyLocalBoolOpt(gLocalOpts.dirfirsts, gOpts.dirfirst, e)
err = applyLocalBoolOpt(gLocalOpts.dirfirst, gOpts.dirfirst, e)
if err == nil {
app.nav.sort()
app.ui.sort()
}
case "dironly", "nodironly", "dironly!":
err = applyLocalBoolOpt(gLocalOpts.dironlys, gOpts.dironly, e)
err = applyLocalBoolOpt(gLocalOpts.dironly, gOpts.dironly, e)
if err == nil {
app.nav.sort()
app.nav.position()
@@ -477,7 +479,7 @@ func (e *setLocalExpr) eval(app *app, args []string) {
app.ui.loadFile(app, true)
}
case "hidden", "nohidden", "hidden!":
err = applyLocalBoolOpt(gLocalOpts.hiddens, gOpts.hidden, e)
err = applyLocalBoolOpt(gLocalOpts.hidden, gOpts.hidden, e)
if err == nil {
app.nav.sort()
app.nav.position()
@@ -485,14 +487,14 @@ func (e *setLocalExpr) eval(app *app, args []string) {
app.ui.loadFile(app, true)
}
case "reverse", "noreverse", "reverse!":
err = applyLocalBoolOpt(gLocalOpts.reverses, gOpts.reverse, e)
err = applyLocalBoolOpt(gLocalOpts.reverse, gOpts.reverse, e)
if err == nil {
app.nav.sort()
app.ui.sort()
}
case "info":
if e.val == "" {
gLocalOpts.infos[e.path] = nil
gLocalOpts.info[e.path] = nil
return
}
toks := strings.Split(e.val, ":")
@@ -504,14 +506,14 @@ func (e *setLocalExpr) eval(app *app, args []string) {
return
}
}
gLocalOpts.infos[e.path] = toks
gLocalOpts.info[e.path] = toks
case "sortby":
method := sortMethod(e.val)
if !isValidSortMethod(method) {
app.ui.echoerr(invalidSortErrorMessage)
return
}
gLocalOpts.sortbys[e.path] = method
gLocalOpts.sortby[e.path] = method
app.nav.sort()
app.ui.sort()
case "locale":
@@ -522,7 +524,7 @@ func (e *setLocalExpr) eval(app *app, args []string) {
return
}
}
gLocalOpts.locales[e.path] = localeStr
gLocalOpts.locale[e.path] = localeStr
app.nav.sort()
app.ui.sort()
default:
@@ -689,11 +691,11 @@ func menuComplete(app *app, dir int) {
ind := len(app.ui.cmdTmp) - len([]rune(last))
app.ui.cmdAccLeft = append(app.ui.cmdTmp[:ind], []rune(comp)...)
}
app.ui.menuBuf = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)
app.ui.menu = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)
}
func update(app *app) {
app.ui.menuBuf = nil
app.ui.menu = ""
app.menuCompActive = false
switch {
@@ -784,7 +786,7 @@ func normal(app *app) {
app.cmdHistoryInd = 0
app.menuCompActive = false
app.ui.menuBuf = nil
app.ui.menu = ""
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
@@ -993,7 +995,7 @@ func insert(app *app, arg string) {
}
fallthrough
default:
app.ui.menuBuf = nil
app.ui.menu = ""
app.menuCompActive = false
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
}
@@ -1059,6 +1061,19 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
}
case "tty-write":
if len(e.args) != 1 {
app.ui.echoerr("tty-write: requires an argument")
return
}
tty, ok := app.ui.screen.Tty()
if !ok {
log.Printf("tty-write: failed to get tty")
return
}
tty.Write([]byte(e.args[0]))
case "scroll-down":
if !app.nav.init {
return
@@ -1073,7 +1088,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
resetIncCmd(app)
preChdir(app)
for i := 0; i < e.count; i++ {
for range e.count {
if err := app.nav.updir(); err != nil {
app.ui.echoerrf("%s", err)
return
@@ -1122,7 +1137,7 @@ func (e *callExpr) eval(app *app, args []string) {
case "jump-prev":
resetIncCmd(app)
preChdir(app)
for i := 0; i < e.count; i++ {
for range e.count {
app.nav.cdJumpListPrev()
}
app.ui.loadFile(app, true)
@@ -1132,7 +1147,7 @@ func (e *callExpr) eval(app *app, args []string) {
case "jump-next":
resetIncCmd(app)
preChdir(app)
for i := 0; i < e.count; i++ {
for range e.count {
app.nav.cdJumpListNext()
}
app.ui.loadFile(app, true)
@@ -1291,7 +1306,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.sort()
case "clearmaps":
// leave `:` and cmaps bound so the user can still exit using `:quit`
gOpts.keys = make(map[string]expr)
clear(gOpts.keys)
gOpts.keys[":"] = &callExpr{"read", nil, 1}
case "copy":
if !app.nav.init {
@@ -1414,10 +1429,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.screen.Sync()
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
clear(app.nav.regCache)
}
if gOpts.sixel {
app.nav.regCache = make(map[string]*reg)
clear(app.nav.regCache)
app.ui.sxScreen.lastFile = ""
}
for _, dir := range app.nav.dirs {
@@ -1497,7 +1512,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
dir := app.nav.currDir()
old := dir.ind
for i := 0; i < e.count; i++ {
for range e.count {
if app.nav.findBack {
app.nav.findPrev()
} else {
@@ -1514,7 +1529,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
dir := app.nav.currDir()
old := dir.ind
for i := 0; i < e.count; i++ {
for range e.count {
if app.nav.findBack {
app.nav.findNext()
} else {
@@ -1557,7 +1572,7 @@ func (e *callExpr) eval(app *app, args []string) {
if !app.nav.init {
return
}
for i := 0; i < e.count; i++ {
for range e.count {
if app.nav.searchBack {
if moved, err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
@@ -1578,7 +1593,7 @@ func (e *callExpr) eval(app *app, args []string) {
if !app.nav.init {
return
}
for i := 0; i < e.count; i++ {
for range e.count {
if app.nav.searchBack {
if moved, err := app.nav.searchNext(); err != nil {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
@@ -1633,14 +1648,14 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.menu = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: "
case "mark-remove":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.menu = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: "
case "rename":
if !app.nav.init {
@@ -1822,13 +1837,13 @@ func (e *callExpr) eval(app *app, args []string) {
normal(app)
case "cmd-complete":
matches := doComplete(app)
app.ui.menuBuf = listMatches(app.ui.screen, matches, -1)
app.ui.menu = listMatches(app.ui.screen, matches, -1)
case "cmd-menu-complete":
menuComplete(app, 1)
case "cmd-menu-complete-back":
menuComplete(app, -1)
case "cmd-menu-accept":
app.ui.menuBuf = nil
app.ui.menu = ""
app.menuCompActive = false
case "cmd-enter":
s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...))
@@ -1836,7 +1851,7 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.ui.menuBuf = nil
app.ui.menu = ""
app.menuCompActive = false
app.ui.cmdAccLeft = nil
@@ -2252,7 +2267,7 @@ func (e *execExpr) eval(app *app, args []string) {
}
func (e *listExpr) eval(app *app, args []string) {
for i := 0; i < e.count; i++ {
for range e.count {
for _, expr := range e.exprs {
expr.eval(app, nil)
}
+6 -6
View File
@@ -1,16 +1,16 @@
module github.com/gokcehan/lf
go 1.23
go 1.23.0
require (
github.com/Xuanwo/go-locale v1.1.2
github.com/Xuanwo/go-locale v1.1.3
github.com/djherbis/times v1.6.0
github.com/fsnotify/fsnotify v1.8.0
github.com/fsnotify/fsnotify v1.9.0
github.com/gdamore/tcell/v2 v2.8.1
github.com/mattn/go-runewidth v0.0.16
golang.org/x/sys v0.29.0
golang.org/x/term v0.28.0
golang.org/x/text v0.21.0
golang.org/x/sys v0.32.0
golang.org/x/term v0.31.0
golang.org/x/text v0.24.0
)
require (
+10 -7
View File
@@ -1,9 +1,9 @@
github.com/Xuanwo/go-locale v1.1.2 h1:6H+olvrQcyVOZ+GAC2rXu4armacTT4ZrFCA0mB24XVo=
github.com/Xuanwo/go-locale v1.1.2/go.mod h1:1JBER4QV7Ji39GJ4AvVlfvqmTUqopzxQxdg2mXYOw94=
github.com/Xuanwo/go-locale v1.1.3 h1:EWZZJJt5rqPHHbqPRH1zFCn5D7xHjjebODctA4aUO3A=
github.com/Xuanwo/go-locale v1.1.3/go.mod h1:REn+F/c+AtGSWYACBSYZgl23AP+0lfQC+SEFPN+hj30=
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
github.com/gdamore/tcell/v2 v2.8.1 h1:KPNxyqclpWpWQlPLx6Xui1pMk8S+7+R37h3g07997NU=
@@ -54,8 +54,9 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
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=
@@ -64,8 +65,9 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
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=
@@ -74,8 +76,9 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
+18 -7
View File
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 2.11.4
.\"
.TH "LF" "1" "2025-02-09" "" "DOCUMENTATION"
.TH "LF" "1" "2025-04-25" "" "DOCUMENTATION"
.hy
.SH NAME
.PP
@@ -102,6 +102,7 @@ mark-load (modal) (default \[dq]\[aq]\[dq])
mark-remove (modal) (default \[aq]\[dq]\[aq])
tag
tag-toggle (default \[aq]t\[aq])
tty-write
\f[R]
.fi
.PP
@@ -627,6 +628,15 @@ with \f[C]tag-toggle\f[R] (i.e.
.PP
Tag a file with \f[C]*\f[R] or a single width character given in the
argument if the file is untagged, otherwise remove the tag.
.SS tty-write
.PP
Write the given string to the tty.
This is useful for sending escape sequences to the terminal to control
its behavior (e.g.
OSC 0 to set the window title).
Using \f[C]tty-write\f[R] is preferred over directly writing to
\f[C]/dev/tty\f[R] because the latter is not synchronized and can
interfere with drawing the UI.
.SH COMMAND LINE COMMANDS
.PP
The prompt character specifies which of the several command-line modes
@@ -1329,9 +1339,9 @@ set sortby \[dq]time\[dq] # string value with double quotes (backslash escapes)
.PP
Command \f[C]setlocal\f[R] is used to set a local option for a directory
which can be a boolean or string.
Currently supported local options are \f[C]dirfirst\f[R],
\f[C]dironly\f[R], \f[C]hidden\f[R], \f[C]info\f[R], \f[C]reverse\f[R],
\f[C]sortby\f[R] and \f[C]locale\f[R].
Currently supported local options are \f[C]dircounts\f[R],
\f[C]dirfirst\f[R], \f[C]dironly\f[R], \f[C]hidden\f[R], \f[C]info\f[R],
\f[C]reverse\f[R], \f[C]sortby\f[R] and \f[C]locale\f[R].
Adding a trailing path separator (i.e.
\f[C]/\f[R] for Unix and \f[C]\[rs]\f[R] for Windows) sets the option
for the given directory along with its subdirectories:
@@ -1807,6 +1817,7 @@ cmaps list of mappings created by the \[aq]cmap\[aq] command
cmds list of commands created by the \[aq]cmd\[aq] command
jumps contents of the jump list, showing previously visited locations
history list of previously executed commands on the command line
files list of files in the currently open directory as displayed by lf, empty if dir is still loading
\f[R]
.fi
.PP
@@ -2153,15 +2164,15 @@ cmd on-cd &{{
\f[R]
.fi
.PP
If you want to print escape sequences, you may redirect \f[C]printf\f[R]
output to \f[C]/dev/tty\f[R].
If you want to send escape sequences to the terminal, you can use the
\f[C]tty-write\f[R] command to do so.
The following xterm-specific escape sequence sets the terminal title to
the working directory:
.IP
.nf
\f[C]
cmd on-cd &{{
printf \[dq]\[rs]033]0; $PWD\[rs]007\[dq] > /dev/tty
lf -remote \[dq]send $id tty-write \[rs]\[dq]\[rs]033]0;$PWD\[rs]007\[rs]\[dq]\[dq]
}}
\f[R]
.fi
+2 -2
View File
@@ -107,7 +107,7 @@ func fieldToString(field reflect.Value) string {
case reflect.Bool:
value = strconv.FormatBool(field.Bool())
case reflect.Slice:
for i := 0; i < field.Len(); i++ {
for i := range field.Len() {
element := field.Index(i)
if i == 0 {
@@ -128,7 +128,7 @@ func getOptsMap() map[string]string {
v := reflect.ValueOf(gOpts)
t := v.Type()
for i := 0; i < v.NumField(); i++ {
for i := range v.NumField() {
// Get field name and prefix it with lf_
name := "lf_" + t.Field(i).Name
+2 -2
View File
@@ -170,7 +170,7 @@ func readArrays(r io.Reader, min_cols, max_cols int) ([][]string, error) {
line := s.Text()
squote, dquote := false, false
for i := 0; i < len(line); i++ {
for i := range len(line) {
if line[i] == '\'' && !dquote {
squote = !squote
} else if line[i] == '"' && !squote {
@@ -206,7 +206,7 @@ func readArrays(r io.Reader, min_cols, max_cols int) ([][]string, error) {
return nil, fmt.Errorf("expected %d~%d columns but found: %s", min_cols, max_cols, s.Text())
}
for i := 0; i < arrlen; i++ {
for i := range arrlen {
squote, dquote = false, false
buf := make([]rune, 0, len(arr[i]))
for _, r := range arr[i] {
+16 -105
View File
@@ -10,6 +10,7 @@ import (
"os/exec"
"path/filepath"
"reflect"
"slices"
"sort"
"strconv"
"strings"
@@ -88,7 +89,7 @@ func newFile(path string) *file {
}
dirCount := -1
if lstat.IsDir() && gOpts.dircounts {
if lstat.IsDir() && getDirCounts(filepath.Dir(path)) {
d, err := os.Open(path)
if err != nil {
dirCount = -2
@@ -174,7 +175,6 @@ type dir struct {
ignoredia bool // ignoredia value from last sort
locale string // locale value from last sort
noPerm bool // whether lf has no permission to open the directory
lines []string // lines of text to display if directory previews are enabled
}
func newDir(path string) *dir {
@@ -186,7 +186,6 @@ func newDir(path string) *dir {
}
return &dir{
loading: gOpts.dirpreviews, // Directory is loaded after previewer function exits.
loadTime: time,
path: path,
files: files,
@@ -449,7 +448,6 @@ type nav struct {
deleteCountChan chan int
deleteTotalChan chan int
previewChan chan string
dirPreviewChan chan *dir
dirChan chan *dir
regChan chan *reg
fileChan chan *file
@@ -479,8 +477,6 @@ type nav struct {
}
func (nav *nav) loadDirInternal(path string) *dir {
nav.startPreview()
d := &dir{
loading: true,
loadTime: time.Now(),
@@ -499,9 +495,6 @@ func (nav *nav) loadDirInternal(path string) *dir {
d := newDir(path)
d.sort()
d.ind, d.pos = 0, 0
if gOpts.dirpreviews {
nav.dirPreviewChan <- d
}
nav.dirChan <- d
}()
return d
@@ -540,14 +533,10 @@ func (nav *nav) checkDir(dir *dir) {
return
}
nav.startPreview()
dir.loading = true
dir.loadTime = now
go func() {
nd := newDir(dir.path)
if gOpts.dirpreviews {
nav.dirPreviewChan <- nd
}
nav.dirChan <- nd
}()
case dir.sortby != getSortBy(dir.path) ||
@@ -598,7 +587,6 @@ func newNav(height int) *nav {
deleteCountChan: make(chan int, 1024),
deleteTotalChan: make(chan int, 1024),
previewChan: make(chan string, 1024),
dirPreviewChan: make(chan *dir, 1024),
dirChan: make(chan *dir),
regChan: make(chan *reg),
fileChan: make(chan *file),
@@ -665,8 +653,8 @@ func (nav *nav) renew() {
}
func (nav *nav) reload() error {
nav.dirCache = make(map[string]*dir)
nav.regCache = make(map[string]*reg)
clear(nav.dirCache)
clear(nav.regCache)
curr, err := nav.currFile()
nav.getDirs(nav.currDir().path)
@@ -717,23 +705,6 @@ func (nav *nav) exportFiles() {
}
}
func (nav *nav) dirPreviewLoop(ui *ui) {
var prevPath string
for dir := range nav.dirPreviewChan {
if dir == nil && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
cmd := exec.Command(gOpts.cleaner, prevPath)
if err := cmd.Run(); err != nil {
log.Printf("cleaning preview: %s", err)
}
nav.volatilePreview = false
} else if dir != nil {
win := ui.wins[len(ui.wins)-1]
nav.previewDir(dir, win)
prevPath = dir.path
}
}
}
func (nav *nav) previewLoop(ui *ui) {
var prev string
for path := range nav.previewChan {
@@ -782,64 +753,6 @@ func matchPattern(pattern, name, path string) bool {
return matched
}
func (nav *nav) previewDir(dir *dir, win *win) {
defer func() {
dir.loading = false
nav.dirChan <- dir
}()
var reader io.Reader
if len(gOpts.previewer) != 0 {
cmd := exec.Command(gOpts.previewer, dir.path,
strconv.Itoa(win.w),
strconv.Itoa(win.h),
strconv.Itoa(win.x),
strconv.Itoa(win.y))
out, err := cmd.StdoutPipe()
if err != nil {
log.Printf("previewing dir: %s", err)
return
}
if err := cmd.Start(); err != nil {
log.Printf("previewing dir: %s", err)
out.Close()
return
}
defer func() {
if err := cmd.Wait(); err != nil {
if e, ok := err.(*exec.ExitError); ok {
if e.ExitCode() != 0 {
nav.volatilePreview = true
}
} else {
log.Printf("loading dir: %s", err)
}
}
}()
defer out.Close()
reader = out
buf := bufio.NewScanner(reader)
for i := 0; i < win.h && buf.Scan(); i++ {
for _, r := range buf.Text() {
if r == 0 {
dir.lines = []string{"\033[7mbinary\033[0m"}
return
}
}
dir.lines = append(dir.lines, buf.Text())
}
if buf.Err() != nil {
log.Printf("loading dir: %s", buf.Err())
}
}
}
func (nav *nav) preview(path string, win *win) {
reg := &reg{loadTime: time.Now(), path: path}
defer func() { nav.regChan <- reg }()
@@ -915,11 +828,9 @@ func (nav *nav) preview(path string, win *win) {
break
}
for _, byte := range bytes {
if byte == 0 {
reg.lines = []string{"\033[7mbinary\033[0m"}
return
}
if slices.Contains(bytes, 0) {
reg.lines = []string{"\033[7mbinary\033[0m"}
return
}
line = append(line, bytes...)
@@ -1308,7 +1219,7 @@ func (nav *nav) invertBelow() {
}
func (nav *nav) unselect() {
nav.selections = make(map[string]int)
clear(nav.selections)
nav.selectionInd = 0
}
@@ -1322,7 +1233,7 @@ func (nav *nav) save(cp bool) error {
return err
}
nav.saves = make(map[string]bool)
clear(nav.saves)
for _, f := range list {
nav.saves[f] = cp
}
@@ -1600,7 +1511,7 @@ func (nav *nav) sync() error {
return err
}
nav.saves = make(map[string]bool)
clear(nav.saves)
for _, f := range list {
nav.saves[f] = cp
}
@@ -1674,7 +1585,7 @@ func (nav *nav) globSel(pattern string, invert bool) error {
dir := nav.currDir()
anyMatched := false
for i := 0; i < len(dir.files); i++ {
for i := range dir.files {
matched, err := filepath.Match(pattern, dir.files[i].Name())
if err != nil {
return fmt.Errorf("glob-select: %s", err)
@@ -1720,7 +1631,7 @@ func (nav *nav) findSingle() int {
count := 0
index := 0
dir := nav.currDir()
for i := 0; i < len(dir.files); i++ {
for i := range dir.files {
if findMatch(dir.files[i].Name(), nav.find) {
count++
if count > 1 {
@@ -1747,7 +1658,7 @@ func (nav *nav) findNext() (bool, bool) {
}
}
if gOpts.wrapscan {
for i := 0; i < dir.ind; i++ {
for i := range dir.ind {
if findMatch(dir.files[i].Name(), nav.find) {
return nav.up(dir.ind - i), true
}
@@ -1804,7 +1715,7 @@ func (nav *nav) searchNext() (bool, error) {
}
}
if gOpts.wrapscan {
for i := 0; i < dir.ind; i++ {
for i := range dir.ind {
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
return false, err
} else if matched {
@@ -1861,7 +1772,7 @@ func (nav *nav) removeMark(mark string) error {
}
func (nav *nav) readMarks() error {
nav.marks = make(map[string]string)
clear(nav.marks)
f, err := os.Open(gMarksPath)
if os.IsNotExist(err) {
return nil
@@ -1919,7 +1830,7 @@ func (nav *nav) writeMarks() error {
}
func (nav *nav) readTags() error {
nav.tags = make(map[string]string)
clear(nav.tags)
f, err := os.Open(gTagsPath)
if os.IsNotExist(err) {
return nil
+32 -21
View File
@@ -107,13 +107,14 @@ var gOpts struct {
}
var gLocalOpts struct {
sortbys map[string]sortMethod
dirfirsts map[string]bool
dironlys map[string]bool
hiddens map[string]bool
reverses map[string]bool
infos map[string][]string
locales map[string]string
sortby map[string]sortMethod
dircounts map[string]bool
dirfirst map[string]bool
dironly map[string]bool
hidden map[string]bool
reverse map[string]bool
info map[string][]string
locale map[string]string
}
func localOptPaths(path string) []string {
@@ -124,9 +125,18 @@ func localOptPaths(path string) []string {
return list
}
func getDirCounts(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.dircounts[key]; ok {
return val
}
}
return gOpts.dircounts
}
func getDirFirst(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.dirfirsts[key]; ok {
if val, ok := gLocalOpts.dirfirst[key]; ok {
return val
}
}
@@ -135,7 +145,7 @@ func getDirFirst(path string) bool {
func getDirOnly(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.dironlys[key]; ok {
if val, ok := gLocalOpts.dironly[key]; ok {
return val
}
}
@@ -144,7 +154,7 @@ func getDirOnly(path string) bool {
func getHidden(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.hiddens[key]; ok {
if val, ok := gLocalOpts.hidden[key]; ok {
return val
}
}
@@ -153,7 +163,7 @@ func getHidden(path string) bool {
func getInfo(path string) []string {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.infos[key]; ok {
if val, ok := gLocalOpts.info[key]; ok {
return val
}
}
@@ -162,7 +172,7 @@ func getInfo(path string) []string {
func getReverse(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.reverses[key]; ok {
if val, ok := gLocalOpts.reverse[key]; ok {
return val
}
}
@@ -171,7 +181,7 @@ func getReverse(path string) bool {
func getSortBy(path string) sortMethod {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.sortbys[key]; ok {
if val, ok := gLocalOpts.sortby[key]; ok {
return val
}
}
@@ -180,7 +190,7 @@ func getSortBy(path string) sortMethod {
func getLocale(path string) string {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.locales[key]; ok {
if val, ok := gLocalOpts.locale[key]; ok {
return val
}
}
@@ -376,13 +386,14 @@ func init() {
gOpts.cmds = make(map[string]expr)
gOpts.user = make(map[string]string)
gLocalOpts.sortbys = make(map[string]sortMethod)
gLocalOpts.dirfirsts = make(map[string]bool)
gLocalOpts.dironlys = make(map[string]bool)
gLocalOpts.hiddens = make(map[string]bool)
gLocalOpts.reverses = make(map[string]bool)
gLocalOpts.infos = make(map[string][]string)
gLocalOpts.locales = make(map[string]string)
gLocalOpts.sortby = make(map[string]sortMethod)
gLocalOpts.dircounts = make(map[string]bool)
gLocalOpts.dirfirst = make(map[string]bool)
gLocalOpts.dironly = make(map[string]bool)
gLocalOpts.hidden = make(map[string]bool)
gLocalOpts.reverse = make(map[string]bool)
gLocalOpts.info = make(map[string][]string)
gLocalOpts.locale = make(map[string]string)
setDefaults()
}
+2 -2
View File
@@ -19,7 +19,7 @@ func serve() {
if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
panic(err)
log.Fatalf("failed to open log file: %s", err)
}
defer f.Close()
log.SetOutput(f)
@@ -64,7 +64,7 @@ func echoerr(c net.Conn, msg string) {
log.Print(msg)
}
func echoerrf(c net.Conn, format string, a ...interface{}) {
func echoerrf(c net.Conn, format string, a ...any) {
echoerr(c, fmt.Sprintf(format, a...))
}
+1 -1
View File
@@ -60,7 +60,7 @@ func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) {
// HACK: fillers are used to control when tcell redraws the region where a sixel image is drawn.
// alternating between bold and regular is to clear the image before drawing a new one.
st := sxs.fillerStyle(reg.path)
for y := 0; y < win.h; y++ {
for y := range win.h {
st = win.print(screen, 0, y, st, strings.Repeat(string(gSixelFiller), win.w))
}
+67 -67
View File
@@ -242,7 +242,7 @@ func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) t
return st
}
func (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, format string, a ...interface{}) {
func (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, format string, a ...any) {
win.print(screen, x, y, st, fmt.Sprintf(format, a...))
}
@@ -295,7 +295,7 @@ func fileInfo(f *file, d *dir, userWidth int, groupWidth int) string {
for _, s := range getInfo(d.path) {
switch s {
case "size":
if f.IsDir() && gOpts.dircounts {
if f.IsDir() && getDirCounts(d.path) {
switch {
case f.dirCount < -1:
info.WriteString(" !")
@@ -356,7 +356,7 @@ type dirStyle struct {
role dirRole
}
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) {
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle) {
if win.w < 5 || dir == nil {
return
}
@@ -368,25 +368,11 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
return
}
fileslen := len(dir.files)
if (dir.loading && fileslen == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) {
if dirStyle.role != Preview || previewLoading {
win.print(ui.screen, 2, 0, messageStyle, "loading...")
}
if dir.loading && fileslen == 0 {
win.print(ui.screen, 2, 0, messageStyle, "loading...")
return
}
if dirStyle.role == Preview && gOpts.dirpreviews && len(gOpts.previewer) > 0 {
// Print previewer result instead of default directory print operation.
st := tcell.StyleDefault
for i, l := range dir.lines {
if i > win.h-1 {
break
}
st = win.print(ui.screen, 2, i, st, l)
}
return
}
if fileslen == 0 {
win.print(ui.screen, 2, 0, messageStyle, "empty")
return
@@ -583,7 +569,7 @@ func getWidths(wtot int) []int {
}
wsum := 0
for i := 0; i < wlen-1; i++ {
for i := range wlen - 1 {
widths[i] = gOpts.ratios[i] * wtot / rsum
wsum += widths[i]
}
@@ -600,7 +586,7 @@ func getWins(screen tcell.Screen) []*win {
wacc := 0
wlen := len(widths)
wins := make([]*win, 0, wlen)
for i := 0; i < wlen; i++ {
for i := range wlen {
if gOpts.drawbox {
wacc++
wins = append(wins, newWin(widths[i], htot-4, wacc, 2))
@@ -629,7 +615,7 @@ type ui struct {
keyChan chan string
tevChan chan tcell.Event
evChan chan tcell.Event
menuBuf *bytes.Buffer
menu string
cmdPrefix string
cmdAccLeft []rune
cmdAccRight []rune
@@ -731,10 +717,13 @@ func (ui *ui) echoerr(msg string) {
log.Printf("error: %s", msg)
}
func (ui *ui) echoerrf(format string, a ...interface{}) {
func (ui *ui) echoerrf(format string, a ...any) {
ui.echoerr(fmt.Sprintf(format, a...))
}
// This represents the preview for a regular file.
// This can also be used to represent the preview of a directory if
// `dirpreviews` is enabled.
type reg struct {
loading bool
volatile bool
@@ -767,10 +756,10 @@ func (ui *ui) loadFile(app *app, volatile bool) {
return
}
if curr.IsDir() {
ui.dirPrev = app.nav.loadDir(curr.path)
} else if curr.Mode().IsRegular() {
if curr.Mode().IsRegular() || (curr.IsDir() && gOpts.dirpreviews) {
ui.regPrev = app.nav.loadReg(curr.path, volatile)
} else if curr.IsDir() {
ui.dirPrev = app.nav.loadDir(curr.path)
}
}
@@ -1004,7 +993,7 @@ func (ui *ui) drawBox() {
}
wacc := 0
for wind := 0; wind < len(ui.wins)-1; wind++ {
for wind := range len(ui.wins) - 1 {
wacc += ui.wins[wind].w + 1
ui.screen.SetContent(wacc, 1, tcell.RuneTTee, nil, st)
for i := 2; i < h-2; i++ {
@@ -1030,13 +1019,7 @@ func (ui *ui) draw(nav *nav) {
st := tcell.StyleDefault
context := dirContext{selections: nav.selections, saves: nav.saves, tags: nav.tags}
// XXX: manual clean without flush to avoid flicker on Windows
wtot, htot := ui.screen.Size()
for i := 0; i < wtot; i++ {
for j := 0; j < htot; j++ {
ui.screen.SetContent(i, j, ' ', nil, st)
}
}
ui.screen.Clear()
ui.sxScreen.sixel = nil
ui.drawPromptLine(nav)
@@ -1045,15 +1028,14 @@ func (ui *ui) draw(nav *nav) {
if gOpts.preview {
wins--
}
for i := 0; i < wins; i++ {
for i := range wins {
role := Parent
if i == wins-1 {
role = Active
}
if dir := ui.dirOfWin(nav, i); dir != nil {
ui.wins[i].printDir(ui, dir, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, role: role},
nav.previewLoading)
&dirStyle{colors: ui.styles, icons: ui.icons, role: role})
}
}
@@ -1081,12 +1063,11 @@ func (ui *ui) draw(nav *nav) {
if err == nil {
preview := ui.wins[len(ui.wins)-1]
if curr.IsDir() {
preview.printDir(ui, ui.dirPrev, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, role: Preview},
nav.previewLoading)
} else if curr.Mode().IsRegular() {
if curr.Mode().IsRegular() || (curr.IsDir() && gOpts.dirpreviews) {
preview.printReg(ui.screen, ui.regPrev, nav.previewLoading, &ui.sxScreen)
} else if curr.IsDir() {
preview.printDir(ui, ui.dirPrev, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, role: Preview})
}
}
}
@@ -1095,8 +1076,8 @@ func (ui *ui) draw(nav *nav) {
ui.drawBox()
}
if ui.menuBuf != nil {
lines := strings.Split(ui.menuBuf.String(), "\n")
if ui.menu != "" {
lines := strings.Split(ui.menu, "\n")
lines = lines[:len(lines)-1]
@@ -1116,7 +1097,7 @@ func (ui *ui) draw(nav *nav) {
}
ui.screen.Show()
if ui.menuBuf == nil && ui.cmdPrefix == "" && ui.sxScreen.sixel != nil {
if ui.menu == "" && ui.cmdPrefix == "" && ui.sxScreen.sixel != nil {
ui.sxScreen.lastFile = ui.regPrev.path
ui.sxScreen.showSixels()
}
@@ -1136,7 +1117,7 @@ func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok b
return
}
func listExprMap(binds map[string]expr, title string) *bytes.Buffer {
func listExprMap(binds map[string]expr, title string) string {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)
@@ -1153,18 +1134,18 @@ func listExprMap(binds map[string]expr, title string) *bytes.Buffer {
}
t.Flush()
return b
return b.String()
}
func listBinds(binds map[string]expr) *bytes.Buffer {
func listBinds(binds map[string]expr) string {
return listExprMap(binds, "keys")
}
func listCmds() *bytes.Buffer {
func listCmds() string {
return listExprMap(gOpts.cmds, "name")
}
func listJumps(jumps []string, ind int) *bytes.Buffer {
func listJumps(jumps []string, ind int) string {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)
@@ -1185,10 +1166,10 @@ func listJumps(jumps []string, ind int) *bytes.Buffer {
}
t.Flush()
return b
return b.String()
}
func listHistory(history []cmdItem) *bytes.Buffer {
func listHistory(history []cmdItem) string {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)
@@ -1201,10 +1182,10 @@ func listHistory(history []cmdItem) *bytes.Buffer {
}
t.Flush()
return b
return b.String()
}
func listMarks(marks map[string]string) *bytes.Buffer {
func listMarks(marks map[string]string) string {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)
@@ -1221,7 +1202,25 @@ func listMarks(marks map[string]string) *bytes.Buffer {
}
t.Flush()
return b
return b.String()
}
func listFilesInCurrDir(nav *nav) string {
if !nav.init {
return ""
}
dir := nav.currDir()
if dir.loading {
log.Printf("listFilesInCurrDir(): %s is still loading, `files` isn't ready for remote query", dir.path)
return ""
}
b := new(strings.Builder)
for _, file := range dir.files {
fmt.Fprintln(b, file.path)
}
return b.String()
}
func (ui *ui) pollEvent() tcell.Event {
@@ -1320,7 +1319,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
if val == "<esc>" && len(ui.keyAcc) != 0 {
ui.keyAcc = nil
ui.keyCount = nil
ui.menuBuf = nil
ui.menu = ""
return draw
}
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
@@ -1337,7 +1336,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
ui.keyAcc = nil
ui.keyCount = nil
ui.menuBuf = nil
ui.menu = ""
return draw
default:
if ok {
@@ -1361,11 +1360,11 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
ui.keyAcc = nil
ui.keyCount = nil
ui.menuBuf = nil
ui.menu = ""
return expr
}
if gOpts.showbinds {
ui.menuBuf = listBinds(binds)
ui.menu = listBinds(binds)
}
return draw
}
@@ -1414,7 +1413,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
ui.echoerrf("unknown mapping: %s", button)
ui.keyAcc = nil
ui.keyCount = nil
ui.menuBuf = nil
ui.menu = ""
return draw
}
@@ -1587,16 +1586,17 @@ func anyKey() {
}
defer term.Restore(int(os.Stdin.Fd()), oldState)
b := make([]byte, 1)
b := make([]byte, 8)
os.Stdin.Read(b)
}
func listMatches(screen tcell.Screen, matches []string, selectedInd int) *bytes.Buffer {
func listMatches(screen tcell.Screen, matches []string, selectedInd int) string {
mlen := len(matches)
if mlen < 2 {
return nil
return ""
}
b := new(bytes.Buffer)
var b strings.Builder
wtot, _ := screen.Size()
wcol := 0
@@ -1613,13 +1613,13 @@ func listMatches(screen tcell.Screen, matches []string, selectedInd int) *bytes.
target := matches[i]
if selectedInd == i {
fmt.Fprintf(b, "\033[7m%s\033[0m%*s", target, wcol-len(target), "")
fmt.Fprintf(&b, "\033[7m%s\033[0m%*s", target, wcol-len(target), "")
} else {
fmt.Fprintf(b, "%s%*s", target, wcol-len(target), "")
fmt.Fprintf(&b, "%s%*s", target, wcol-len(target), "")
}
}
b.WriteByte('\n')
}
return b
return b.String()
}
+2 -2
View File
@@ -110,7 +110,7 @@ func (watch *watch) loop() {
dir.sort()
watch.dirChan <- dir
}
watch.loads = make(map[string]bool)
clear(watch.loads)
case <-watch.updateTimer.C:
for path := range watch.updates {
if _, err := os.Lstat(path); err != nil {
@@ -118,7 +118,7 @@ func (watch *watch) loop() {
}
watch.fileChan <- newFile(path)
}
watch.updates = make(map[string]bool)
clear(watch.updates)
case <-watch.quit:
return
}