fix(path): apply style correctly
Some checks failed
Code QL / code-ql (push) Has been cancelled
Release / changelog (push) Has been cancelled
Release / artifacts (push) Has been cancelled

This commit is contained in:
L. Yeung 2024-08-08 15:33:22 +08:00 committed by Jan De Dobbeleer
parent 70d6f73d83
commit 90aada5187

View file

@ -183,12 +183,12 @@ func (pt *Path) Init(props properties.Properties, env runtime.Environment) {
func (pt *Path) setStyle() { func (pt *Path) setStyle() {
if len(pt.relative) == 0 { if len(pt.relative) == 0 {
pt.Path = pt.root // Only append a separator to a non-filesystem PSDrive root or a Windows drive root.
if (len(pt.env.Flags().PSWD) != 0 || pt.windowsPath) && strings.HasSuffix(pt.root, ":") {
if strings.HasSuffix(pt.Path, ":") { pt.root += pt.getFolderSeparator()
pt.Path += pt.getFolderSeparator()
} }
pt.Path = pt.colorizePath(pt.root, nil)
return return
} }
@ -207,10 +207,7 @@ func (pt *Path) setStyle() {
pt.Path = pt.getUniqueLettersPath(0) pt.Path = pt.getUniqueLettersPath(0)
case AgnosterLeft: case AgnosterLeft:
pt.Path = pt.getAgnosterLeftPath() pt.Path = pt.getAgnosterLeftPath()
case Short: case Full, Short: // "short" is a duplicate of "full", just here for backwards compatibility
// "short" is a duplicate of "full", just here for backwards compatibility
fallthrough
case Full:
pt.Path = pt.getFullPath() pt.Path = pt.getFullPath()
case FolderType: case FolderType:
pt.Path = pt.getFolderPath() pt.Path = pt.getFolderPath()
@ -279,27 +276,25 @@ func (pt *Path) getFolderSeparator() string {
} }
func (pt *Path) getMixedPath() string { func (pt *Path) getMixedPath() string {
var buffer strings.Builder
threshold := int(pt.props.GetFloat64(MixedThreshold, 4)) threshold := int(pt.props.GetFloat64(MixedThreshold, 4))
folderIcon := pt.props.GetString(FolderIcon, "..") folderIcon := pt.props.GetString(FolderIcon, "..")
separator := pt.getFolderSeparator()
if pt.root != pt.pathSeparator { if pt.root == pt.pathSeparator {
pt.Folders = append(Folders{{Name: pt.root}}, pt.Folders...) pt.root = pt.Folders[0].Name
pt.Folders = pt.Folders[1:]
} }
n := len(pt.Folders) var folders []string
buffer.WriteString(pt.Folders[0].Name)
for i := 1; i < n; i++ { for i, n := 0, len(pt.Folders); i < n; i++ {
folder := pt.Folders[i].Name folder := pt.Folders[i].Name
if len(folder) > threshold && i != n-1 && !pt.Folders[i].Display { if len(folder) > threshold && i != n-1 && !pt.Folders[i].Display {
folder = folderIcon folder = folderIcon
} }
buffer.WriteString(fmt.Sprintf("%s%s", separator, folder)) folders = append(folders, folder)
} }
return buffer.String()
return pt.colorizePath(pt.root, folders)
} }
func (pt *Path) getAgnosterPath() string { func (pt *Path) getAgnosterPath() string {
@ -510,8 +505,7 @@ func (pt *Path) getFullPath() string {
} }
func (pt *Path) getFolderPath() string { func (pt *Path) getFolderPath() string {
pwd := runtime.Base(pt.env, pt.pwd) return pt.colorizePath(runtime.Base(pt.env, pt.pwd), nil)
return pt.replaceFolderSeparators(pwd)
} }
func (pt *Path) replaceMappedLocations() (string, string) { func (pt *Path) replaceMappedLocations() (string, string) {
@ -736,7 +730,7 @@ func (pt *Path) colorizePath(root string, elements []string) string {
} }
if len(elements) == 0 { if len(elements) == 0 {
root := fmt.Sprintf(leftFormat, root) root = fmt.Sprintf(leftFormat, root)
return colorizeElement(root) return colorizeElement(root)
} }
@ -749,8 +743,8 @@ func (pt *Path) colorizePath(root string, elements []string) string {
var builder strings.Builder var builder strings.Builder
root = fmt.Sprintf(leftFormat, root) formattedRoot := fmt.Sprintf(leftFormat, root)
builder.WriteString(colorizeElement(root)) builder.WriteString(colorizeElement(formattedRoot))
if root != pt.pathSeparator && len(root) != 0 { if root != pt.pathSeparator && len(root) != 0 {
builder.WriteString(colorizeSeparator()) builder.WriteString(colorizeSeparator())