Skip to content

Commit 6867c54

Browse files
authored
feat(list): add version indicators and color coding (#101)
1 parent 24eb80f commit 6867c54

3 files changed

Lines changed: 54 additions & 10 deletions

File tree

src/cmd/list.go

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package cmd
22

33
import (
4+
"github.com/dtvem/dtvem/src/internal/config"
45
"github.com/dtvem/dtvem/src/internal/runtime"
56
"github.com/dtvem/dtvem/src/internal/ui"
67
"github.com/spf13/cobra"
78
)
89

10+
// Version indicator emojis
11+
const (
12+
globalIndicator = "🌐"
13+
localIndicator = "📍"
14+
)
15+
916
var listCmd = &cobra.Command{
1017
Use: "list [runtime]",
1118
Short: "List installed versions",
@@ -49,15 +56,13 @@ func listAllRuntimes() {
4956
}
5057

5158
hasAny = true
59+
runtimeName := provider.Name()
5260
globalVersion, _ := provider.GlobalVersion()
61+
localVersion, _ := config.LocalVersion(runtimeName)
5362

5463
ui.Printf(" %s:\n", ui.Highlight(provider.DisplayName()))
5564
for _, v := range versions {
56-
if v.String() == globalVersion {
57-
ui.Printf(" %s (global)\n", ui.HighlightVersion(v.String()))
58-
} else {
59-
ui.Printf(" %s\n", ui.HighlightVersion(v.String()))
60-
}
65+
printVersionLine(v.String(), globalVersion, localVersion)
6166
}
6267
}
6368

@@ -89,13 +94,37 @@ func listSingleRuntime(runtimeName string) {
8994
}
9095

9196
globalVersion, _ := provider.GlobalVersion()
97+
localVersion, _ := config.LocalVersion(runtimeName)
9298

9399
for _, v := range versions {
94-
if v.String() == globalVersion {
95-
ui.Printf(" %s (global)\n", ui.HighlightVersion(v.String()))
96-
} else {
97-
ui.Printf(" %s\n", ui.HighlightVersion(v.String()))
98-
}
100+
printVersionLine(v.String(), globalVersion, localVersion)
101+
}
102+
}
103+
104+
// printVersionLine prints a single version with appropriate indicators and colors
105+
// Active version (local > global) is shown in green
106+
// Indicators: 🌐 for global, 📍 for local
107+
func printVersionLine(version, globalVersion, localVersion string) {
108+
isGlobal := version == globalVersion
109+
isLocal := version == localVersion
110+
111+
// Determine if this is the active version (local takes priority over global)
112+
isActive := isLocal || (isGlobal && localVersion == "")
113+
114+
// Build the indicator string
115+
var indicators string
116+
if isLocal {
117+
indicators += " " + localIndicator
118+
}
119+
if isGlobal {
120+
indicators += " " + globalIndicator
121+
}
122+
123+
// Format and print
124+
if isActive {
125+
ui.Printf(" %s%s\n", ui.ActiveVersion(version), indicators)
126+
} else {
127+
ui.Printf(" %s%s\n", version, indicators)
99128
}
100129
}
101130

src/internal/config/version.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ func FindLocalRuntimesFile() (string, error) {
151151
return "", fmt.Errorf("no .dtvem/runtimes.json file found")
152152
}
153153

154+
// LocalVersion reads the local version for a runtime by walking up the directory tree
155+
func LocalVersion(runtimeName string) (string, error) {
156+
return findLocalVersion(runtimeName)
157+
}
158+
154159
// GlobalVersion reads the global version for a runtime
155160
func GlobalVersion(runtimeName string) (string, error) {
156161
configPath := GlobalConfigPath()

src/internal/ui/output.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ func HighlightVersion(version string) string {
8181
return color.New(color.FgMagenta, color.Bold).Sprint(version)
8282
}
8383

84+
// ActiveVersion prints a version string in green (for currently active version)
85+
func ActiveVersion(version string) string {
86+
return color.New(color.FgGreen, color.Bold).Sprint(version)
87+
}
88+
89+
// DimText prints text in a dimmed/gray color (for inactive items)
90+
func DimText(text string) string {
91+
return color.New(color.Faint).Sprint(text)
92+
}
93+
8494
// PromptInstall prompts the user to install a missing version.
8595
// Returns true if the user wants to install, false otherwise.
8696
// Respects DTVEM_AUTO_INSTALL environment variable:

0 commit comments

Comments
 (0)