@@ -2,10 +2,12 @@ package cli
22
33import (
44 "fmt"
5+ "regexp"
56 "sort"
67 "strings"
78
89 "github.com/chenasraf/tx/internal/config"
10+ "github.com/chenasraf/tx/internal/table"
911 "github.com/chenasraf/tx/internal/tmux"
1012 "github.com/spf13/cobra"
1113)
@@ -61,13 +63,7 @@ func runList(cmd *cobra.Command, args []string) error {
6163 sessionsOutput , err := tmux .ListSessions (opts )
6264 sessionsStr := ""
6365 if err == nil && sessionsOutput != "" {
64- // Format sessions output
65- lines := strings .Split (strings .TrimSpace (sessionsOutput ), "\n " )
66- for _ , line := range lines {
67- if line != "" {
68- sessionsStr += " " + line + "\n "
69- }
70- }
66+ sessionsStr = formatSessionsTable (sessionsOutput , " " )
7167 } else {
7268 sessionsStr = " No tmux sessions\n "
7369 }
@@ -107,3 +103,28 @@ func runList(cmd *cobra.Command, args []string) error {
107103
108104 return nil
109105}
106+
107+ var sessionLineRe = regexp .MustCompile (`^([^:]+):\s*(\d+)\s+windows?\s*\(created\s+([^)]+)\)\s*(.*)$` )
108+
109+ // formatSessionsTable parses `tmux ls` output and renders it as a bordered
110+ // table with headers. Each output line is prefixed with indent.
111+ func formatSessionsTable (raw , indent string ) string {
112+ lines := strings .Split (strings .TrimSpace (raw ), "\n " )
113+ rows := make ([][]string , 0 , len (lines ))
114+ for _ , line := range lines {
115+ if line == "" {
116+ continue
117+ }
118+ m := sessionLineRe .FindStringSubmatch (line )
119+ if m == nil {
120+ // Fallback: dump the whole line into the Name column
121+ rows = append (rows , []string {line , "" , "" , "" })
122+ continue
123+ }
124+ status := strings .TrimSpace (m [4 ])
125+ status = strings .TrimPrefix (status , "(" )
126+ status = strings .TrimSuffix (status , ")" )
127+ rows = append (rows , []string {m [1 ], m [2 ], m [3 ], status })
128+ }
129+ return table .Render ([]string {"Name" , "Windows" , "Created" , "Status" }, rows , indent )
130+ }
0 commit comments