diff --git a/src/cmd/list.go b/src/cmd/list.go index ac9d9cc..6f5492a 100644 --- a/src/cmd/list.go +++ b/src/cmd/list.go @@ -1,11 +1,18 @@ package cmd import ( + "github.com/dtvem/dtvem/src/internal/config" "github.com/dtvem/dtvem/src/internal/runtime" "github.com/dtvem/dtvem/src/internal/ui" "github.com/spf13/cobra" ) +// Version indicator emojis +const ( + globalIndicator = "🌐" + localIndicator = "📍" +) + var listCmd = &cobra.Command{ Use: "list [runtime]", Short: "List installed versions", @@ -49,15 +56,13 @@ func listAllRuntimes() { } hasAny = true + runtimeName := provider.Name() globalVersion, _ := provider.GlobalVersion() + localVersion, _ := config.LocalVersion(runtimeName) ui.Printf(" %s:\n", ui.Highlight(provider.DisplayName())) for _, v := range versions { - if v.String() == globalVersion { - ui.Printf(" %s (global)\n", ui.HighlightVersion(v.String())) - } else { - ui.Printf(" %s\n", ui.HighlightVersion(v.String())) - } + printVersionLine(v.String(), globalVersion, localVersion) } } @@ -89,13 +94,37 @@ func listSingleRuntime(runtimeName string) { } globalVersion, _ := provider.GlobalVersion() + localVersion, _ := config.LocalVersion(runtimeName) for _, v := range versions { - if v.String() == globalVersion { - ui.Printf(" %s (global)\n", ui.HighlightVersion(v.String())) - } else { - ui.Printf(" %s\n", ui.HighlightVersion(v.String())) - } + printVersionLine(v.String(), globalVersion, localVersion) + } +} + +// printVersionLine prints a single version with appropriate indicators and colors +// Active version (local > global) is shown in green +// Indicators: 🌐 for global, 📍 for local +func printVersionLine(version, globalVersion, localVersion string) { + isGlobal := version == globalVersion + isLocal := version == localVersion + + // Determine if this is the active version (local takes priority over global) + isActive := isLocal || (isGlobal && localVersion == "") + + // Build the indicator string + var indicators string + if isLocal { + indicators += " " + localIndicator + } + if isGlobal { + indicators += " " + globalIndicator + } + + // Format and print + if isActive { + ui.Printf(" %s%s\n", ui.ActiveVersion(version), indicators) + } else { + ui.Printf(" %s%s\n", version, indicators) } } diff --git a/src/internal/config/version.go b/src/internal/config/version.go index 5becb14..c2a8c75 100644 --- a/src/internal/config/version.go +++ b/src/internal/config/version.go @@ -151,6 +151,11 @@ func FindLocalRuntimesFile() (string, error) { return "", fmt.Errorf("no .dtvem/runtimes.json file found") } +// LocalVersion reads the local version for a runtime by walking up the directory tree +func LocalVersion(runtimeName string) (string, error) { + return findLocalVersion(runtimeName) +} + // GlobalVersion reads the global version for a runtime func GlobalVersion(runtimeName string) (string, error) { configPath := GlobalConfigPath() diff --git a/src/internal/ui/output.go b/src/internal/ui/output.go index 922db59..63c34df 100644 --- a/src/internal/ui/output.go +++ b/src/internal/ui/output.go @@ -81,6 +81,16 @@ func HighlightVersion(version string) string { return color.New(color.FgMagenta, color.Bold).Sprint(version) } +// ActiveVersion prints a version string in green (for currently active version) +func ActiveVersion(version string) string { + return color.New(color.FgGreen, color.Bold).Sprint(version) +} + +// DimText prints text in a dimmed/gray color (for inactive items) +func DimText(text string) string { + return color.New(color.Faint).Sprint(text) +} + // PromptInstall prompts the user to install a missing version. // Returns true if the user wants to install, false otherwise. // Respects DTVEM_AUTO_INSTALL environment variable: