fix(path): return early when powerlevel is < max_width

resolves #3607
This commit is contained in:
Jan De Dobbeleer 2023-03-27 16:50:47 +02:00 committed by Jan De Dobbeleer
parent 08b631a994
commit 96868bfd4f
2 changed files with 19 additions and 2 deletions

View file

@ -309,6 +309,14 @@ func (pt *Path) getUniqueLettersPath(maxWidth int) string {
if pt.root != pt.env.PathSeparator() {
elements = append([]string{pt.root}, elements...)
}
if maxWidth > 0 {
path := strings.Join(elements, separator)
if len(path) <= maxWidth {
return path
}
}
n := len(elements)
letters := make(map[string]bool)
for i := 0; i < n-1; i++ {

View file

@ -203,7 +203,7 @@ func TestAgnosterPathStyles(t *testing.T) {
Style: Powerlevel,
Expected: "t > w > o > a > v > l > p > wh > we > i > wa > th > the > d > f > u > it > c > to > a > co > stream",
HomePath: homeDir,
Pwd: "there/was/once/a/very/long/path/which/wended/its/way/through/the/dark/forest/until/it/came/to/a/cold/stream",
Pwd: "/there/was/once/a/very/long/path/which/wended/its/way/through/the/dark/forest/until/it/came/to/a/cold/stream",
PathSeparator: "/",
FolderSeparatorIcon: " > ",
MaxWidth: 20,
@ -212,11 +212,20 @@ func TestAgnosterPathStyles(t *testing.T) {
Style: Powerlevel,
Expected: "t > w > o > a > v > l > p > which > wended > its > way > through > the",
HomePath: homeDir,
Pwd: "there/was/once/a/very/long/path/which/wended/its/way/through/the",
Pwd: "/there/was/once/a/very/long/path/which/wended/its/way/through/the",
PathSeparator: "/",
FolderSeparatorIcon: " > ",
MaxWidth: 70,
},
{
Style: Powerlevel,
Expected: "var/cache/pacman",
HomePath: homeDir,
Pwd: "/var/cache/pacman",
PathSeparator: "/",
FolderSeparatorIcon: "/",
MaxWidth: 50,
},
{
Style: Letter,