11package cmd
22
33import (
4+ "fmt"
5+
46 "github.com/dtvem/dtvem/src/internal/config"
57 "github.com/dtvem/dtvem/src/internal/runtime"
8+ "github.com/dtvem/dtvem/src/internal/tui"
69 "github.com/dtvem/dtvem/src/internal/ui"
710 "github.com/spf13/cobra"
811)
@@ -41,8 +44,6 @@ func listAllRuntimes() {
4144 return
4245 }
4346
44- ui .Header ("Installed versions:" )
45-
4647 hasAny := false
4748 for _ , provider := range providers {
4849 versions , err := provider .ListInstalled ()
@@ -60,10 +61,23 @@ func listAllRuntimes() {
6061 globalVersion , _ := provider .GlobalVersion ()
6162 localVersion , _ := config .LocalVersion (runtimeName )
6263
63- ui .Printf (" %s:\n " , ui .Highlight (provider .DisplayName ()))
64+ // Create table for this runtime with title
65+ table := tui .NewTable ("Version" , "Status" )
66+ table .SetTitle (provider .DisplayName ())
67+
6468 for _ , v := range versions {
65- printVersionLine (v .String (), globalVersion , localVersion )
69+ version := v .String ()
70+ status := getVersionStatus (version , globalVersion , localVersion )
71+ isActive := isVersionActive (version , globalVersion , localVersion )
72+
73+ if isActive {
74+ table .AddActiveRow (version , status )
75+ } else {
76+ table .AddRow (version , status )
77+ }
6678 }
79+
80+ fmt .Println (table .Render ())
6781 }
6882
6983 if ! hasAny {
@@ -80,8 +94,6 @@ func listSingleRuntime(runtimeName string) {
8094 return
8195 }
8296
83- ui .Header ("Installed %s versions:" , provider .DisplayName ())
84-
8597 versions , err := provider .ListInstalled ()
8698 if err != nil {
8799 ui .Error ("%v" , err )
@@ -96,36 +108,57 @@ func listSingleRuntime(runtimeName string) {
96108 globalVersion , _ := provider .GlobalVersion ()
97109 localVersion , _ := config .LocalVersion (runtimeName )
98110
111+ // Create table with title
112+ table := tui .NewTable ("Version" , "Status" )
113+ table .SetTitle (provider .DisplayName ())
114+
99115 for _ , v := range versions {
100- printVersionLine (v .String (), globalVersion , localVersion )
116+ version := v .String ()
117+ status := getVersionStatus (version , globalVersion , localVersion )
118+ isActive := isVersionActive (version , globalVersion , localVersion )
119+
120+ if isActive {
121+ table .AddActiveRow (version , status )
122+ } else {
123+ table .AddRow (version , status )
124+ }
101125 }
126+
127+ fmt .Println (table .Render ())
102128}
103129
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 ) {
130+ // getVersionStatus returns a status string for a version (global, local, or empty)
131+ func getVersionStatus (version , globalVersion , localVersion string ) string {
108132 isGlobal := version == globalVersion
109133 isLocal := version == localVersion
110134
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
135+ var parts []string
116136 if isLocal {
117- indicators += " " + localIndicator
137+ parts = append ( parts , localIndicator + " local" )
118138 }
119139 if isGlobal {
120- indicators += " " + globalIndicator
140+ parts = append ( parts , globalIndicator + " global" )
121141 }
122142
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 )
143+ if len (parts ) == 0 {
144+ return ""
145+ }
146+
147+ status := ""
148+ for i , p := range parts {
149+ if i > 0 {
150+ status += ", "
151+ }
152+ status += p
128153 }
154+ return status
155+ }
156+
157+ // isVersionActive returns true if this version is the currently active one
158+ func isVersionActive (version , globalVersion , localVersion string ) bool {
159+ isGlobal := version == globalVersion
160+ isLocal := version == localVersion
161+ return isLocal || (isGlobal && localVersion == "" )
129162}
130163
131164func init () {
0 commit comments