Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/fs"
"log"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -79,23 +78,23 @@ func (app *app) quit() {

if gOpts.history {
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
errorf("writing history file: %s", err)
}
}
if !gSingleMode {
if err := remote(fmt.Sprintf("drop %d", gClientID)); err != nil {
log.Printf("dropping connection: %s", err)
errorf("dropping connection: %s", err)
}
if gOpts.autoquit {
if err := remote("quit"); err != nil {
log.Printf("auto quitting server: %s", err)
errorf("auto quitting server: %s", err)
}
}
}
}

func (app *app) readFile(path string) {
log.Printf("reading file: %s", path)
infof("reading file: %s", path)

f, err := os.Open(path)
if err != nil {
Expand Down Expand Up @@ -150,7 +149,7 @@ func loadFiles() (clipboard clipboard, err error) {
return
}

log.Printf("loading clipboard: %v", clipboard.paths)
infof("loading clipboard: %v", clipboard.paths)

return
}
Expand All @@ -166,7 +165,7 @@ func saveFiles(clipboard clipboard) error {
}
defer files.Close()

log.Printf("saving files: %v", clipboard.paths)
infof("saving clipboard: %v", clipboard.paths)

if clipboard.mode == clipboardCopy {
fmt.Fprintln(files, "copy")
Expand Down Expand Up @@ -265,7 +264,7 @@ func (app *app) loop() {
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
app.readFile(gConfigPath)
} else {
log.Printf("config file does not exist: %s", err)
errorf("config file does not exist: %s", err)
}
} else {
for _, path := range gConfigPaths {
Expand All @@ -289,7 +288,7 @@ func (app *app) loop() {

wd, err := os.Getwd()
if err != nil {
log.Printf("getting current directory: %s", err)
errorf("getting current directory: %s", err)
}

app.nav.updateDirs(wd)
Expand Down Expand Up @@ -331,7 +330,7 @@ func (app *app) loop() {

app.nav.previewChan <- ""

log.Printf("*************** closing client, PID: %d ***************", os.Getpid())
infof("*************** closing client, PID: %d ***************", os.Getpid())

return
case n := <-app.nav.copyJobsChan:
Expand Down Expand Up @@ -526,7 +525,7 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pauseAfter bool) {
app.nav.previewChan <- ""

if err := app.ui.suspend(); err != nil {
log.Printf("suspend: %s", err)
errorf("suspend: %s", err)
}
defer func() {
if err := app.ui.resume(); err != nil {
Expand Down Expand Up @@ -605,15 +604,15 @@ func (app *app) runShell(s string, args []string, prefix string) {
// the output has been fully read or not.
inReader, inWriter, err := os.Pipe()
if err != nil {
log.Printf("creating input pipe: %s", err)
errorf("creating input pipe: %s", err)
return
}
cmd.Stdin = inReader
app.cmdIn = inWriter

outReader, outWriter, err = os.Pipe()
if err != nil {
log.Printf("creating output pipe: %s", err)
errorf("creating output pipe: %s", err)
return
}
cmd.Stdout = outWriter
Expand All @@ -639,7 +638,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
b, err := reader.ReadByte()
if err != nil {
if !errors.Is(err, io.EOF) && !errors.Is(err, fs.ErrClosed) {
log.Printf("reading command output: %s", err)
errorf("reading command output: %s", err)
}
break
}
Expand All @@ -657,7 +656,7 @@ func (app *app) runShell(s string, args []string, prefix string) {

go func() {
if err := cmd.Wait(); err != nil {
log.Printf("running shell: %s", err)
errorf("running shell: %s", err)
}
inReader.Close()
inWriter.Close()
Expand All @@ -671,7 +670,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
case "&":
go func() {
if err := cmd.Wait(); err != nil {
log.Printf("running shell: %s", err)
errorf("running shell: %s", err)
}
app.ui.exprChan <- &callExpr{"load", nil, 1}
}()
Expand Down
15 changes: 8 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func run() {
log.SetOutput(io.Discard)
}

log.Printf("*************** starting client, PID: %d ***************", os.Getpid())
io.WriteString(log.Writer(), "\n")
infof("*************** starting client, PID: %d ***************", os.Getpid())

var screen tcell.Screen
var err error
Expand Down Expand Up @@ -89,28 +90,28 @@ func run() {
func writeLastDir(filename string, lastDir string) {
f, err := os.Create(filename)
if err != nil {
log.Printf("opening last dir file: %s", err)
errorf("opening last dir file: %s", err)
return
}
defer f.Close()

_, err = f.WriteString(lastDir)
if err != nil {
log.Printf("writing last dir file: %s", err)
errorf("writing last dir file: %s", err)
}
}

func writeSelection(filename string, selection []string) {
f, err := os.Create(filename)
if err != nil {
log.Printf("opening selection file: %s", err)
errorf("opening selection file: %s", err)
return
}
defer f.Close()

_, err = f.WriteString(strings.Join(selection, "\n"))
if err != nil {
log.Printf("writing selection file: %s", err)
errorf("writing selection file: %s", err)
}
}

Expand All @@ -122,7 +123,7 @@ func readExpr() <-chan expr {

c, err := net.Dial(gSocketProt, gSocketPath)
for err != nil {
log.Printf("connecting server: %s", err)
errorf("connecting server: %s", err)
time.Sleep(duration)
duration *= 2
c, err = net.Dial(gSocketProt, gSocketPath)
Expand All @@ -135,7 +136,7 @@ func readExpr() <-chan expr {

s := bufio.NewScanner(c)
for s.Scan() {
log.Printf("recv: %s", s.Text())
debugf("recv: %s", s.Text())

// `query` has to be handled outside of the main thread, which is
// blocked when running a synchronous shell command ("$" or "!").
Expand Down
23 changes: 11 additions & 12 deletions colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"log"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -184,7 +183,7 @@ loop:
case "38":
color, offset, err := parseColor(toks[i+1:])
if err != nil {
log.Printf("error processing ansi code 38: %s", err)
errorf("error processing ansi code 38: %s", err)
break loop
}
st = st.Foreground(color)
Expand All @@ -198,40 +197,40 @@ loop:
case "48":
color, offset, err := parseColor(toks[i+1:])
if err != nil {
log.Printf("error processing ansi code 48: %s", err)
errorf("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)
errorf("error processing ansi code 58: %s", err)
break loop
}
st = st.Underline(color)
i += offset
default:
log.Printf("unknown ansi code: %s", toks[i])
errorf("unknown ansi code: %s", toks[i])
}
}

return st
}

func (sm styleMap) parseFile(path string) {
log.Printf("reading file: %s", path)
infof("reading file: %s", path)

f, err := os.Open(path)
if err != nil {
log.Printf("opening colors file: %s", err)
errorf("opening colors file: %s", err)
return
}
defer f.Close()

pairs, err := readPairs(f)
if err != nil {
log.Printf("reading colors file: %s", err)
errorf("reading colors file: %s", err)
return
}

Expand All @@ -250,7 +249,7 @@ func (sm *styleMap) parseGNU(env string) {
pair := strings.Split(entry, "=")

if len(pair) != 2 {
log.Printf("invalid $LS_COLORS entry: %s", entry)
errorf("invalid $LS_COLORS entry: %s", entry)
return
}

Expand All @@ -277,7 +276,7 @@ func (sm *styleMap) parsePair(pair []string) {
// This function parses $LSCOLORS environment variable.
func (sm styleMap) parseBSD(env string) {
if len(env) != 22 {
log.Printf("invalid $LSCOLORS variable: %s", env)
errorf("invalid $LSCOLORS variable: %s", env)
return
}

Expand All @@ -294,7 +293,7 @@ func (sm styleMap) parseBSD(env string) {
case 'a' <= r1 && r1 <= 'h':
st = st.Foreground(tcell.PaletteColor(int(r1 - 'a')))
default:
log.Printf("invalid $LSCOLORS entry: %c", r1)
errorf("invalid $LSCOLORS entry: %c", r1)
return tcell.StyleDefault
}

Expand All @@ -304,7 +303,7 @@ func (sm styleMap) parseBSD(env string) {
case 'a' <= r2 && r2 <= 'h':
st = st.Background(tcell.PaletteColor(int(r2 - 'a')))
default:
log.Printf("invalid $LSCOLORS entry: %c", r2)
errorf("invalid $LSCOLORS entry: %c", r2)
return tcell.StyleDefault
}

Expand Down
9 changes: 4 additions & 5 deletions complete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"log"
"maps"
"os"
"path/filepath"
Expand Down Expand Up @@ -248,7 +247,7 @@ func matchFile(s string, dirOnly bool, escape func(string) string, unescape func
}
files, err := os.ReadDir(d)
if err != nil {
log.Printf("reading directory: %s", err)
errorf("reading directory: %s", err)
result = s
return
}
Expand Down Expand Up @@ -316,7 +315,7 @@ func matchExec(s string) (matches []compMatch, result string) {
files, err := os.ReadDir(p)
if err != nil {
if !os.IsNotExist(err) {
log.Printf("reading path: %s", err)
errorf("reading path: %s", err)
}
continue
}
Expand All @@ -328,7 +327,7 @@ func matchExec(s string) (matches []compMatch, result string) {

finfo, err := f.Info()
if err != nil {
log.Printf("getting file information: %s", err)
errorf("getting file information: %s", err)
continue
}

Expand All @@ -346,7 +345,7 @@ func matchExec(s string) (matches []compMatch, result string) {
func matchSearch(s string) (matches []compMatch, result string) {
files, err := os.ReadDir(".")
if err != nil {
log.Printf("reading directory: %s", err)
errorf("reading directory: %s", err)
result = s
return
}
Expand Down
4 changes: 1 addition & 3 deletions df_openbsd.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package main

import (
"log"

"golang.org/x/sys/unix"
)

func diskFree(wd string) string {
var stat unix.Statfs_t

if err := unix.Statfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
errorf("diskfree: %s", err)
return ""
}

Expand Down
4 changes: 1 addition & 3 deletions df_statfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
package main

import (
"log"

"golang.org/x/sys/unix"
)

func diskFree(wd string) string {
var stat unix.Statfs_t

if err := unix.Statfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
errorf("diskfree: %s", err)
return ""
}

Expand Down
4 changes: 1 addition & 3 deletions df_statvfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
package main

import (
"log"

"golang.org/x/sys/unix"
)

func diskFree(wd string) string {
var stat unix.Statvfs_t

if err := unix.Statvfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
errorf("diskfree: %s", err)
return ""
}

Expand Down
Loading