Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions src/cmd/list.go
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/internal/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions src/internal/ui/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down