Repository: jesseduffield/lazygit
File: pkg/gui/presentation/files.go (Go)

Code before:

		output += arrowStyle.Sprint(arrow) + " "
	} else {
		// Sprinting the space at the end in the specific style is for the sake of
		// when a reverse style is used in the theme, which looks ugly if you just
		// use the default style
		output += indentation + formatFileStatus(file, nameColor) + nameColor.Sprint(" ")
	}

	isSubmodule := file != nil && file.IsSubmodule(submoduleConfigs)
	isLinkedWorktree := file != nil && file.IsWorktree
	isDirectory := file == nil

	if showFileIcons {
		icon := icons.IconForFile(name, isSubmodule, isLinkedWorktree, isDirectory)
		paint := color.C256(icon.Color, false)
		output += paint.Sprint(icon.Icon) + nameColor.Sprint(" ")
	}

	output += nameColor.Sprint(utils.EscapeSpecialChars(name))

	if isSubmodule {
		output += theme.DefaultTextColor.Sprint(" (submodule)")
	}

	if lineChanges := formatLineChanges(file); showNumberOfLineChanges && lineChanges != "" {
		output += " " + lineChanges
	}

	return output
}

func formatFileStatus(file *models.File, restColor style.TextStyle) string {
	firstChar := file.ShortStatus[0:1]
	firstCharCl := style.FgGreen
	if firstChar == "?" {
		firstCharCl = theme.UnstagedChangesColor
	} else if firstChar == " " {
		firstCharCl = restColor
	}

	secondChar := file.ShortStatus[1:2]
	secondCharCl := theme.UnstagedChangesColor
	if secondChar == " " {
		secondCharCl = restColor
	}

	return firstCharCl.Sprint(firstChar) + secondCharCl.Sprint(secondChar)
}

func formatLineChanges(file *models.File) string {

Review comment (suggestion):
I'd wrap this whole thing in `if showNumberOfLineChanges` rather than first computing `formatLineChanges`: generally the earlier you can short-circuit, the better

Code after:
		output += arrowStyle.Sprint(arrow) + " "
	} else {
		// Sprinting the space at the end in the specific style is for the sake of
		// when a reverse style is used in the theme, which looks ugly if you just
		// use the default style
		output += indentation + formatFileStatus(file, nameColor) + nameColor.Sprint(" ")
	}

	isSubmodule := file != nil && file.IsSubmodule(submoduleConfigs)
	isLinkedWorktree := file != nil && file.IsWorktree
	isDirectory := file == nil

	if showFileIcons {
		icon := icons.IconForFile(name, isSubmodule, isLinkedWorktree, isDirectory)
		paint := color.C256(icon.Color, false)
		output += paint.Sprint(icon.Icon) + nameColor.Sprint(" ")
	}

	output += nameColor.Sprint(utils.EscapeSpecialChars(name))

	if isSubmodule {
		output += theme.DefaultTextColor.Sprint(" (submodule)")
	}

	if file != nil && showNumstat {
		if lineChanges := formatLineChanges(file.LinesAdded, file.LinesDeleted); lineChanges != "" {
			output += " " + lineChanges
		}
	}

	return output
}

func formatFileStatus(file *models.File, restColor style.TextStyle) string {
	firstChar := file.ShortStatus[0:1]
	firstCharCl := style.FgGreen
	if firstChar == "?" {
		firstCharCl = theme.UnstagedChangesColor
	} else if firstChar == " " {
		firstCharCl = restColor
	}

	secondChar := file.ShortStatus[1:2]
	secondCharCl := theme.UnstagedChangesColor
	if secondChar == " " {
		secondCharCl = restColor
	}

	return firstCharCl.Sprint(firstChar) + secondCharCl.Sprint(secondChar)
}