mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-05 16:47:20 -04:00
Remove all global variables (slices) only used in entryList.go
This commit is contained in:
+7
-9
@@ -8,19 +8,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// global variables used only in this file
|
|
||||||
var (
|
|
||||||
fileList []string
|
|
||||||
dirList []string
|
|
||||||
)
|
|
||||||
|
|
||||||
// global constants used only in this file
|
// global constants used only in this file
|
||||||
const (
|
const (
|
||||||
ansiAlternateEntryColor = "\033[38;5;8m"
|
ansiAlternateEntryColor = "\033[38;5;8m"
|
||||||
)
|
)
|
||||||
|
|
||||||
// calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories)
|
// calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories)
|
||||||
func indentSubtractor(indent int, skippedDirList []bool, currentDirIndex int) int {
|
func indentSubtractor(skippedDirList []bool, dirList []string, currentDirIndex int, indent int) int {
|
||||||
var subtractor int // tracks how much to subtract from expected indentation multiplier
|
var subtractor int // tracks how much to subtract from expected indentation multiplier
|
||||||
|
|
||||||
for i := len(skippedDirList[:currentDirIndex]) - 1; i >= 0; i-- { // checks each skipped directory to determine if it is a parent to the current directory
|
for i := len(skippedDirList[:currentDirIndex]) - 1; i >= 0; i-- { // checks each skipped directory to determine if it is a parent to the current directory
|
||||||
@@ -74,6 +68,10 @@ func printFileEntry(entry string, lastSlash int, charCounter int, colorAlternato
|
|||||||
func EntryListGen() {
|
func EntryListGen() {
|
||||||
fmt.Print("\n" + ansiBlackOnWhite + "libmutton entries:" + ansiReset)
|
fmt.Print("\n" + ansiBlackOnWhite + "libmutton entries:" + ansiReset)
|
||||||
|
|
||||||
|
// define file/directory containing slices so that they may be accessed by the anonymous WalkDir function
|
||||||
|
var fileList []string
|
||||||
|
var dirList []string
|
||||||
|
|
||||||
// walk entry directory
|
// walk entry directory
|
||||||
_ = filepath.WalkDir(EntryRoot,
|
_ = filepath.WalkDir(EntryRoot,
|
||||||
func(fullPath string, entry fs.DirEntry, err error) error {
|
func(fullPath string, entry fs.DirEntry, err error) error {
|
||||||
@@ -154,7 +152,7 @@ func EntryListGen() {
|
|||||||
if !containsFiles {
|
if !containsFiles {
|
||||||
containsFiles = true
|
containsFiles = true
|
||||||
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
|
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
|
||||||
indent = indentSubtractor(indent, skippedDirList, i) // calculate the final indentation multiplier
|
indent = indentSubtractor(skippedDirList, dirList, i, indent) // calculate the final indentation multiplier
|
||||||
if !Windows { // for consistency, format directories with UNIX-style path separators on all platforms
|
if !Windows { // for consistency, format directories with UNIX-style path separators on all platforms
|
||||||
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", directory)
|
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", directory)
|
||||||
} else {
|
} else {
|
||||||
@@ -170,7 +168,7 @@ func EntryListGen() {
|
|||||||
if !containsSubdirectory { // nor does it contain any subdirectories...
|
if !containsSubdirectory { // nor does it contain any subdirectories...
|
||||||
if dirListLength > 1 { // and directories besides the root-level exist... display directory header and empty directory warning
|
if dirListLength > 1 { // and directories besides the root-level exist... display directory header and empty directory warning
|
||||||
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
|
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
|
||||||
indent = indentSubtractor(indent, skippedDirList, i) // calculate the final indentation multiplier
|
indent = indentSubtractor(skippedDirList, dirList, i, indent) // calculate the final indentation multiplier
|
||||||
if !Windows { // for consistency, format directories with UNIX-style path separators on all platforms
|
if !Windows { // for consistency, format directories with UNIX-style path separators on all platforms
|
||||||
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", directory)
|
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", directory)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user