Skip to content

Commit 00050a3

Browse files
Gilbert SanchezHeyItsGilbert
authored andcommitted
feat(Get-ListPanel): ✨ enhance item display logic
* Improved the visual representation of items in the list. * Added handling for parent items and adjusted styles for selected/unselected items. * Refactored code for better readability and maintainability.
1 parent f3840a7 commit 00050a3

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

PesterExplorer/Private/Get-ListPanel.ps1

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,40 @@ function Get-ListPanel {
66
[string]
77
$SelectedItem
88
)
9-
$resultList = $List | ForEach-Object {
9+
$unselectedStyle = @{
10+
RootColor = [Spectre.Console.Color]::Grey
11+
SeparatorColor = [Spectre.Console.Color]::Grey
12+
StemColor = [Spectre.Console.Color]::Grey
13+
LeafColor = [Spectre.Console.Color]::White
14+
}
15+
$results = $List | ForEach-Object {
1016
$name = $_
11-
if ($name -eq $SelectedItem) {
12-
$name = "[Turquoise2]$($name)[/]"
17+
if($name -eq '..') {
18+
# This is a parent item, so we show it as a folder
19+
if ($name -eq $SelectedItem) {
20+
Write-SpectreHost ":up_arrow: [Turquoise2]$name[/]" -PassThru | Format-SpectrePadded -Padding 1
21+
} else {
22+
Write-SpectreHost "$name" -PassThru | Format-SpectrePadded -Padding 0
23+
}
24+
}
25+
elseif(Test-Path $name){
26+
$relativePath = [System.IO.Path]::GetRelativePath(
27+
(Get-Location).Path,
28+
$name
29+
)
30+
if ($name -eq $SelectedItem) {
31+
Format-SpectreTextPath -Path $relativePath | Format-SpectrePadded -Padding 1
32+
} else {
33+
Format-SpectreTextPath -Path $relativePath -PathStyle $unselectedStyle | Format-SpectrePadded -Padding 0
34+
}
35+
}
36+
else {
37+
if ($name -eq $SelectedItem) {
38+
Write-SpectreHost ":right_arrow: [Turquoise2]$name[/]" -PassThru | Format-SpectrePadded -Padding 1
39+
} else {
40+
Write-SpectreHost $name -PassThru | Format-SpectrePadded -Padding 0
41+
}
1342
}
14-
return $name
1543
}
16-
return $resultList | Format-SpectreRows | Format-SpectrePanel -Header "[white]List[/]" -Expand
44+
$results | Format-SpectreRows | Format-SpectrePanel -Header "[white]List[/]" -Expand
1745
}

PesterExplorer/Public/Show-PesterResult.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function Show-PesterResult {
7676
$selectedItem = $list[0]
7777
$stack = [System.Collections.Stack]::new()
7878
$object = $PesterResult
79-
$stack.Push($object)
79+
#$stack.Push($object)
8080
#endregion Initial State
8181

8282
while ($true) {
@@ -90,17 +90,19 @@ function Show-PesterResult {
9090
$selectedItem = $list[($list.IndexOf($selectedItem) - 1 + $list.Count) % $list.Count]
9191
} elseif ($lastKeyPressed.Key -eq "Enter") {
9292
<# Recurse into Pester Object #>
93-
if($items.Item($selectedItem).GetType().Name -eq "Test") {
94-
# This is a test. We don't want to go deeper.
95-
}
9693
if($selectedItem -like '*..*') {
9794
# Move up one via selecting ..
9895
$object = $stack.Pop()
9996
Write-Debug "Popped item from stack: $($object.Name)"
10097
} else {
10198
Write-Debug "Pushing item into stack: $($items.Item($selectedItem).Name)"
99+
102100
$stack.Push($object)
103101
$object = $items.Item($selectedItem)
102+
if($object.GetType().Name -eq "Test") {
103+
# This is a test. We don't want to go deeper.
104+
$object = $stack.Pop()
105+
}
104106
}
105107
$items = Get-ListFromObject -Object $object
106108
$list = [array]$items.Keys

0 commit comments

Comments
 (0)