Skip to content

Commit

Permalink
Merge branch 'master' into fsnotify
Browse files Browse the repository at this point in the history
  • Loading branch information
joelim-work committed Jun 22, 2024
2 parents 3902642 + 73030b5 commit d3f7c6a
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 52 deletions.
11 changes: 8 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ func (app *app) loop() {
return
case n := <-app.nav.copyBytesChan:
app.nav.copyBytes += n
// n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied
if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 {
// n is usually 32*1024B (default io.Copy() buffer) so update roughly per 32KB x 128 = 4MB copied
if app.nav.copyUpdate++; app.nav.copyUpdate >= 128 {
app.nav.copyUpdate = 0
app.ui.draw(app.nav)
}
Expand Down Expand Up @@ -390,6 +390,11 @@ func (app *app) loop() {
app.nav.dirCache[d.path] = d
}

var oldCurrPath string
if curr, err := app.nav.currFile(); err == nil {
oldCurrPath = curr.path
}

for i := range app.nav.dirs {
if app.nav.dirs[i].path == d.path {
app.nav.dirs[i] = d
Expand All @@ -400,7 +405,7 @@ func (app *app) loop() {

curr, err := app.nav.currFile()
if err == nil {
if d.path == app.nav.currDir().path {
if curr.path != oldCurrPath {
app.ui.loadFile(app, true)
if app.ui.msgIsStat {
app.ui.loadFileInfo(app.nav)
Expand Down
42 changes: 23 additions & 19 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ import (
"github.com/djherbis/times"
)

type ProgressWriter struct {
writer io.Writer
nums chan<- int64
}

func NewProgressWriter(writer io.Writer, nums chan<- int64) *ProgressWriter {
return &ProgressWriter{
writer: writer,
nums: nums,
}
}

func (progressWriter *ProgressWriter) Write(b []byte) (int, error) {
n, err := progressWriter.writer.Write(b)
progressWriter.nums <- int64(n)
return n, err
}

func copySize(srcs []string) (int64, error) {
var total int64

Expand Down Expand Up @@ -47,8 +65,6 @@ func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan in
}
}

buf := make([]byte, 4096)

r, err := os.Open(src)
if err != nil {
return err
Expand All @@ -60,23 +76,11 @@ func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan in
return err
}

for {
n, err := r.Read(buf)
if err != nil && err != io.EOF {
w.Close()
os.Remove(dst)
return err
}

if n == 0 {
break
}

if _, err := w.Write(buf[:n]); err != nil {
return err
}

nums <- int64(n)
_, err = io.Copy(NewProgressWriter(w, nums), r)
if err != nil {
w.Close()
os.Remove(dst)
return err
}

if err := w.Close(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ The following options can be used to customize the behavior of lf:
globfilter bool (default false)
globsearch bool (default false)
hidden bool (default false)
hiddenfiles []string (default '.*')
hiddenfiles []string (default '.*' for Unix and '' for Windows)
hidecursorinactive bool (default false)
history bool (default true)
icons bool (default false)
Expand Down Expand Up @@ -765,9 +765,9 @@ Otherwise, these characters are interpreted as they are.

Show hidden files.
On Unix systems, hidden files are determined by the value of `hiddenfiles`.
On Windows, only files with hidden attributes are considered hidden files.
On Windows, files with hidden attributes are also considered hidden files.

## hiddenfiles ([]string) (default `.*`)
## hiddenfiles ([]string) (default `.*` for Unix and `` for Windows)

List of hidden file glob patterns.
Patterns can be given as relative or absolute paths.
Expand Down
2 changes: 1 addition & 1 deletion etc/lfcd.nu
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

# For nushell version >= 0.87.0
def --env --wrapped lfcd [...args: string] {
cd (lf -print-last-dir $args)
cd (lf -print-last-dir ...$args)
}
2 changes: 0 additions & 2 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdPrefix = "delete " + strconv.Itoa(len(list)) + " items? [y/N] "
}
}
app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
case "clear":
if !app.nav.init {
Expand Down Expand Up @@ -1648,7 +1647,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(extension)...)
}
}
app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
case "sync":
if err := app.nav.sync(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gdamore/tcell/v2 v2.7.4
github.com/mattn/go-runewidth v0.0.15
golang.org/x/sys v0.19.0
golang.org/x/term v0.19.0
golang.org/x/sys v0.21.0
golang.org/x/term v0.21.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBc
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.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
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.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
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=
Expand Down
19 changes: 11 additions & 8 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ func (nav *nav) previewLoop(ui *ui) {
}
}

//lint:ignore U1000 This function is not used on Windows
func matchPattern(pattern, name, path string) bool {
s := name

Expand Down Expand Up @@ -890,25 +889,29 @@ func (nav *nav) preview(path string, win *win) {

// bufio.Scanner can't handle files containing long lines if they exceed the
// size of its internal buffer
addLine := true
line := []byte{}
for len(reg.lines) < win.h {
line, isPrefix, err := reader.ReadLine()
bytes, isPrefix, err := reader.ReadLine()
if err != nil {
if len(line) > 0 {
reg.lines = append(reg.lines, string(line))
}
break
}

for _, r := range line {
if r == 0 {
for _, byte := range bytes {
if byte == 0 {
reg.lines = []string{"\033[7mbinary\033[0m"}
return
}
}

if addLine {
line = append(line, bytes...)

if !isPrefix {
reg.lines = append(reg.lines, string(line))
line = []byte{}
}

addLine = !isPrefix
}
}

Expand Down
2 changes: 1 addition & 1 deletion opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func init() {
gOpts.truncatechar = "~"
gOpts.truncatepct = 100
gOpts.ratios = []int{1, 2, 3}
gOpts.hiddenfiles = []string{".*"}
gOpts.hiddenfiles = gDefaultHiddenFiles
gOpts.history = true
gOpts.info = nil
gOpts.ruler = nil
Expand Down
9 changes: 5 additions & 4 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ var (
)

var (
gDefaultShell = "sh"
gDefaultShellFlag = "-c"
gDefaultSocketProt = "unix"
gDefaultSocketPath string
gDefaultShell = "sh"
gDefaultShellFlag = "-c"
gDefaultSocketProt = "unix"
gDefaultSocketPath string
gDefaultHiddenFiles = []string{".*"}
)

var (
Expand Down
26 changes: 21 additions & 5 deletions os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ var (
var envPathExt = os.Getenv("PATHEXT")

var (
gDefaultShell = "cmd"
gDefaultShellFlag = "/c"
gDefaultSocketProt = "unix"
gDefaultSocketPath string
gDefaultShell = "cmd"
gDefaultShellFlag = "/c"
gDefaultSocketProt = "unix"
gDefaultSocketPath string
gDefaultHiddenFiles []string
)

var (
Expand Down Expand Up @@ -181,7 +182,22 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
if err != nil {
return false
}
return attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0

if attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0 {
return true
}

hidden := false
for _, pattern := range hiddenfiles {
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
if strings.HasPrefix(pattern, "!") && matched {
hidden = false
} else if matched {
hidden = true
}
}

return hidden
}

func userName(f os.FileInfo) string {
Expand Down

0 comments on commit d3f7c6a

Please sign in to comment.