For indented directory headers, only print the new portion of the header

This commit is contained in:
2024-01-23 16:35:05 -05:00
parent fc48c1dd21
commit e54fef3d74
+17 -4
View File
@@ -27,6 +27,19 @@ func indentSubtractor(skippedDirList []bool, dirList []string, currentDirIndex i
if indent < 0 { // disallow negative indentation multipliers if indent < 0 { // disallow negative indentation multipliers
indent = 0 indent = 0
} else if indent > 0 {
var sliceIndex int
var count int
for currentIndex := 0; currentIndex < len(dirList[currentDirIndex]); currentIndex++ {
if string(dirList[currentDirIndex][currentIndex]) == "/" {
count++
if count == indent+1 {
sliceIndex = currentIndex
break
}
}
}
dirList[currentDirIndex] = dirList[currentDirIndex][sliceIndex+1:]
} }
return indent return indent
@@ -151,9 +164,9 @@ func EntryListGen() {
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(skippedDirList, dirList, i, indent) // 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", dirList[i])
} else { } else {
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", strings.ReplaceAll(directory, PathSeparator, "/")) fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", strings.ReplaceAll(dirList[i], PathSeparator, "/"))
} }
} }
@@ -167,9 +180,9 @@ func EntryListGen() {
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(skippedDirList, dirList, i, indent) // 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", dirList[i])
} else { } else {
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", strings.ReplaceAll(directory, PathSeparator, "/")) fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+ansiReset+"\n", strings.ReplaceAll(dirList[i], PathSeparator, "/"))
} }
fmt.Print(strings.Repeat(" ", indent*2) + "\033[38;5;11m-empty directory-" + ansiReset) fmt.Print(strings.Repeat(" ", indent*2) + "\033[38;5;11m-empty directory-" + ansiReset)
} else { // warn if the only thing that exists is the root-level directory } else { // warn if the only thing that exists is the root-level directory