From 48689f9eabfab0ed5827b792230f1b699a34dca2 Mon Sep 17 00:00:00 2001 From: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com> Date: Wed, 14 Jan 2026 00:16:23 +0100 Subject: [PATCH] docs: improve code comments (#2349) * docs: annotate `app` struct fields * docs: annotate `file` struct fields * docs: improve existing code comments * docs: add new code comments --- app.go | 36 ++++++++++++++++++------------------ eval.go | 3 ++- nav.go | 32 ++++++++++++++++---------------- ui.go | 2 +- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/app.go b/app.go index 242e0f0e..f03b8e76 100644 --- a/app.go +++ b/app.go @@ -19,24 +19,24 @@ import ( ) type app struct { - ui *ui - nav *nav - ticker *time.Ticker - quitChan chan struct{} - cmd *exec.Cmd - cmdIn io.WriteCloser - cmdOutBuf []byte - cmdHistory []string - cmdHistoryBeg int - cmdHistoryInd int - cmdHistoryInput *string - menuCompActive bool - menuCompTmp []string - menuComps []compMatch - menuCompInd int - selectionOut []string - watch *watch - quitting bool + ui *ui // ui state (screen, windows, input) + nav *nav // navigation state (dirs, cursor, selections, preview, caches) + ticker *time.Ticker // refresh ticker if `period` > 0 + quitChan chan struct{} // signals main loop to exit + cmd *exec.Cmd // currently running % (shell-pipe) command + cmdIn io.WriteCloser // stdin writer for running % command + cmdOutBuf []byte // output of running % command + cmdHistory []string // command history entries + cmdHistoryBeg int // index where commands from this session start in cmdHistory + cmdHistoryInd int // history navigation offset from most recent + cmdHistoryInput *string // initial input used as prefix filter while browsing history + menuCompActive bool // whether completion cycling is active + menuCompTmp []string // token snapshot taken when completion cycling starts, used for `cmd-menu-discard` + menuComps []compMatch // completion candidates for active prompt + menuCompInd int // index of selected completion candidate (-1: none selected) + selectionOut []string // paths to output on exit, used for `-print-selection` and `-selection-path` + watch *watch // fs watcher if `watch` is enabled + quitting bool // guard to prevent re-entering quit logic } func newApp(ui *ui, nav *nav) *app { diff --git a/eval.go b/eval.go index 633c1901..d25e3b74 100644 --- a/eval.go +++ b/eval.go @@ -974,6 +974,7 @@ func exitCompMenu(app *app) { func (e *callExpr) eval(app *app, _ []string) { os.Setenv("lf_count", strconv.Itoa(e.count)) + // commands that shouldn't clear the message line silentCmds := []string{ "addcustominfo", "clearmaps", @@ -1570,7 +1571,7 @@ func (e *callExpr) eval(app *app, _ []string) { case 1: k, v = e.args[0], "" case 2: - k, v = e.args[0], e.args[1] + k, v = e.args[0], e.args[1] // don't trim to allow for custom alignment default: app.ui.echoerr("addcustominfo: requires either 1 or 2 arguments") return diff --git a/nav.go b/nav.go index 500ad264..f8bbb02a 100644 --- a/nav.go +++ b/nav.go @@ -32,18 +32,18 @@ const ( ) type file struct { - os.FileInfo - linkState linkState - linkTarget string - path string - dirCount int - dirSize int64 - accessTime time.Time - birthTime time.Time - changeTime time.Time - customInfo string - ext string - err error + os.FileInfo // stat information + linkState linkState // symlink state + linkTarget string // path a symlink points to + path string // full path including the name + dirCount int // number of items inside the directory (-2: error, -1: unknown) + dirSize int64 // total directory size (needs to be calculated via `calcdirsize`) + accessTime time.Time // time of last access + birthTime time.Time // time of file birth + changeTime time.Time // time of last status (inode) change + customInfo string // property defined via `addcustominfo` + ext string // file extension (including the dot) + err error // potential error returned by `os.Lstat` } func newFile(path string) *file { @@ -178,10 +178,10 @@ func readdir(path string) ([]*file, error) { } type dir struct { - loading bool // directory is loading from disk + loading bool // whether directory is loading from disk loadTime time.Time // last load time - ind int // index of current entry in files - pos int // position of current entry in ui + ind int // 0-based index of current entry in dir.files + pos int // 0-based cursor row in directory window path string // full path of directory files []*file // displayed files in directory including or excluding hidden ones allFiles []*file // all files in directory including hidden ones (same array as files) @@ -192,7 +192,7 @@ type dir struct { hidden bool // hidden value from last sort reverse bool // reverse value from last sort visualAnchor int // index where Visual mode was initiated - visualWrap int // wrap direction in Visual mode + visualWrap int // wrap direction in Visual mode (0: none, +: bottom->top, -: top->bottom) hiddenfiles []string // hiddenfiles value from last sort filter []string // last filter for this directory ignorecase bool // ignorecase value from last sort diff --git a/ui.go b/ui.go index 817d326b..80888193 100644 --- a/ui.go +++ b/ui.go @@ -751,7 +751,7 @@ func (ui *ui) echoerrf(format string, a ...any) { ui.echoerr(fmt.Sprintf(format, a...)) } -// This represents the preview for a regular file. +// This represents the preview for a file. // This can also be used to represent the preview of a directory if // `dirpreviews` is enabled. type reg struct {