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
This commit is contained in:
CatsDeservePets authored and GitHub committed 2026-01-14 00:16:23 +01:00
1 parent a96bdae71a
commit 48689f9eab
4 files changed
+37 -36

No files matched your search

+18 -18
View File
@@ -19,24 +19,24 @@ import (
) )
type app struct { type app struct {
ui *ui ui *ui // ui state (screen, windows, input)
nav *nav nav *nav // navigation state (dirs, cursor, selections, preview, caches)
ticker *time.Ticker ticker *time.Ticker // refresh ticker if `period` > 0
quitChan chan struct{} quitChan chan struct{} // signals main loop to exit
cmd *exec.Cmd cmd *exec.Cmd // currently running % (shell-pipe) command
cmdIn io.WriteCloser cmdIn io.WriteCloser // stdin writer for running % command
cmdOutBuf []byte cmdOutBuf []byte // output of running % command
cmdHistory []string cmdHistory []string // command history entries
cmdHistoryBeg int cmdHistoryBeg int // index where commands from this session start in cmdHistory
cmdHistoryInd int cmdHistoryInd int // history navigation offset from most recent
cmdHistoryInput *string cmdHistoryInput *string // initial input used as prefix filter while browsing history
menuCompActive bool menuCompActive bool // whether completion cycling is active
menuCompTmp []string menuCompTmp []string // token snapshot taken when completion cycling starts, used for `cmd-menu-discard`
menuComps []compMatch menuComps []compMatch // completion candidates for active prompt
menuCompInd int menuCompInd int // index of selected completion candidate (-1: none selected)
selectionOut []string selectionOut []string // paths to output on exit, used for `-print-selection` and `-selection-path`
watch *watch watch *watch // fs watcher if `watch` is enabled
quitting bool quitting bool // guard to prevent re-entering quit logic
} }
func newApp(ui *ui, nav *nav) *app { func newApp(ui *ui, nav *nav) *app {
+2 -1
View File
@@ -974,6 +974,7 @@ func exitCompMenu(app *app) {
func (e *callExpr) eval(app *app, _ []string) { func (e *callExpr) eval(app *app, _ []string) {
os.Setenv("lf_count", strconv.Itoa(e.count)) os.Setenv("lf_count", strconv.Itoa(e.count))
// commands that shouldn't clear the message line
silentCmds := []string{ silentCmds := []string{
"addcustominfo", "addcustominfo",
"clearmaps", "clearmaps",
@@ -1570,7 +1571,7 @@ func (e *callExpr) eval(app *app, _ []string) {
case 1: case 1:
k, v = e.args[0], "" k, v = e.args[0], ""
case 2: 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: default:
app.ui.echoerr("addcustominfo: requires either 1 or 2 arguments") app.ui.echoerr("addcustominfo: requires either 1 or 2 arguments")
return return
+16 -16
View File
@@ -32,18 +32,18 @@ const (
) )
type file struct { type file struct {
os.FileInfo os.FileInfo // stat information
linkState linkState linkState linkState // symlink state
linkTarget string linkTarget string // path a symlink points to
path string path string // full path including the name
dirCount int dirCount int // number of items inside the directory (-2: error, -1: unknown)
dirSize int64 dirSize int64 // total directory size (needs to be calculated via `calcdirsize`)
accessTime time.Time accessTime time.Time // time of last access
birthTime time.Time birthTime time.Time // time of file birth
changeTime time.Time changeTime time.Time // time of last status (inode) change
customInfo string customInfo string // property defined via `addcustominfo`
ext string ext string // file extension (including the dot)
err error err error // potential error returned by `os.Lstat`
} }
func newFile(path string) *file { func newFile(path string) *file {
@@ -178,10 +178,10 @@ func readdir(path string) ([]*file, error) {
} }
type dir struct { type dir struct {
loading bool // directory is loading from disk loading bool // whether directory is loading from disk
loadTime time.Time // last load time loadTime time.Time // last load time
ind int // index of current entry in files ind int // 0-based index of current entry in dir.files
pos int // position of current entry in ui pos int // 0-based cursor row in directory window
path string // full path of directory path string // full path of directory
files []*file // displayed files in directory including or excluding hidden ones files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files) 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 hidden bool // hidden value from last sort
reverse bool // reverse value from last sort reverse bool // reverse value from last sort
visualAnchor int // index where Visual mode was initiated 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 hiddenfiles []string // hiddenfiles value from last sort
filter []string // last filter for this directory filter []string // last filter for this directory
ignorecase bool // ignorecase value from last sort ignorecase bool // ignorecase value from last sort
+1 -1
View File
@@ -751,7 +751,7 @@ func (ui *ui) echoerrf(format string, a ...any) {
ui.echoerr(fmt.Sprintf(format, a...)) 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 // This can also be used to represent the preview of a directory if
// `dirpreviews` is enabled. // `dirpreviews` is enabled.
type reg struct { type reg struct {