Fix empty directory warning appearing for root if no subdirectories are present (but files are)

This commit is contained in:
2024-01-16 17:56:24 -05:00
parent 6e4453c773
commit 88b2bb51a3
+8 -5
View File
@@ -43,7 +43,7 @@ func printFileEntry(entry string, lastSlash int, charCounter int, colorAlternato
// EntryListGen generates and displays full entry list
func EntryListGen() {
fmt.Print("\nfor a list of usable commands, run \"mutn help\"\n\n\033[38;5;0;48;5;15mlibmutton entries:\033[0m")
fmt.Print("\n\u001B[38;5;0;48;5;15mlibmutton entries:\u001B[0m")
// walk entry directory
_ = filepath.WalkDir(EntryRoot,
@@ -83,7 +83,8 @@ func EntryListGen() {
}
// DirListMain iteration
dirListMainLength := len(dirListMain) // save length for multiple references below
if dirListMainLength > 1 { // DirListMain iteration - only run if non-root-level directories are present
nextStartIndex := 0 // set to track where to resume when iterating through fileListMain
var containsSubdirectory bool // set to track whether the current directory contains a subdirectory - if it does, empty directory warnings will not be printed
for i, directory := range dirListMain {
@@ -93,7 +94,7 @@ func EntryListGen() {
colorAlternator = 1
// check if next directory is within the current one
if len(dirListMain) > i+1 {
if dirListMainLength > i+1 {
nextDir := dirListMain[i+1]
if directory == nextDir[:strings.LastIndex(nextDir, PathSeparator)] {
containsSubdirectory = true
@@ -142,9 +143,11 @@ func EntryListGen() {
} else {
fmt.Printf("\n\n\033[38;5;7;48;5;8m%s/\033[0m\n", strings.ReplaceAll(directory, PathSeparator, "/"))
}
fmt.Print("\033[38;5;9m-empty directory-\033[0m")
fmt.Print("\033[38;5;9m-Empty Directory-\033[0m")
}
}
} else if !ran {
fmt.Print("\n\nNothing's here! For help creating your first entry, run \"mutn help\".")
}
// print trailing new lines for proper spacing after entry list is complete