MCPcopy
hub / github.com/jesseduffield/lazygit / getFileLine

Function getFileLine

pkg/gui/presentation/files.go:112–182  ·  view source on GitHub ↗
(
	isCollapsed bool,
	hasUnstagedChanges bool,
	hasStagedChanges bool,
	treeDepth int,
	visualDepth int,
	showNumstat,
	showFileIcons bool,
	submoduleConfigs []*models.SubmoduleConfig,
	node *filetree.Node[models.File],
	customIconsConfig *config.CustomIconsConfig,
	showRootItem bool,
)

Source from the content-addressed store, hash-verified

110}
111
112func getFileLine(
113 isCollapsed bool,
114 hasUnstagedChanges bool,
115 hasStagedChanges bool,
116 treeDepth int,
117 visualDepth int,
118 showNumstat,
119 showFileIcons bool,
120 submoduleConfigs []*models.SubmoduleConfig,
121 node *filetree.Node[models.File],
122 customIconsConfig *config.CustomIconsConfig,
123 showRootItem bool,
124) string {
125 name := fileNameAtDepth(node, treeDepth, showRootItem)
126 output := ""
127
128 var nameColor style.TextStyle
129
130 file := node.File
131
132 indentation := strings.Repeat(" ", visualDepth)
133
134 if hasStagedChanges && !hasUnstagedChanges {
135 nameColor = style.FgGreen
136 } else if hasStagedChanges {
137 nameColor = style.FgYellow
138 } else {
139 nameColor = theme.DefaultTextColor
140 }
141
142 if file == nil {
143 output += indentation + ""
144 arrow := EXPANDED_ARROW
145 if isCollapsed {
146 arrow = COLLAPSED_ARROW
147 }
148
149 arrowStyle := nameColor
150
151 output += arrowStyle.Sprint(arrow) + " "
152 } else {
153 // Sprinting the space at the end in the specific style is for the sake of
154 // when a reverse style is used in the theme, which looks ugly if you just
155 // use the default style
156 output += indentation + formatFileStatus(file, nameColor) + nameColor.Sprint(" ")
157 }
158
159 isSubmodule := file != nil && file.IsSubmodule(submoduleConfigs)
160 isLinkedWorktree := file != nil && file.IsWorktree
161 isDirectory := file == nil
162
163 if showFileIcons {
164 icon := icons.IconForFile(name, isSubmodule, isLinkedWorktree, isDirectory, customIconsConfig)
165 paint := color.HEX(icon.Color, false)
166 output += paint.Sprint(icon.Icon) + nameColor.Sprint(" ")
167 }
168
169 output += nameColor.Sprint(utils.EscapeSpecialChars(name))

Callers 1

RenderFileTreeFunction · 0.85

Calls 8

SprintMethod · 0.95
IconForFileFunction · 0.92
EscapeSpecialCharsFunction · 0.92
fileNameAtDepthFunction · 0.85
formatFileStatusFunction · 0.85
formatLineChangesFunction · 0.85
IsSubmoduleMethod · 0.80
SprintMethod · 0.65

Tested by

no test coverage detected