@@ -3,9 +3,11 @@ package codespace
33import (
44 "context"
55 "fmt"
6+ "time"
67
7- "github.com/cli/cli/v2/pkg/cmd/codespace/output "
8+ "github.com/cli/cli/v2/internal/codespaces/api "
89 "github.com/cli/cli/v2/pkg/cmdutil"
10+ "github.com/cli/cli/v2/utils"
911 "github.com/spf13/cobra"
1012)
1113
@@ -40,19 +42,49 @@ func (a *App) List(ctx context.Context, asJSON bool, limit int) error {
4042 return fmt .Errorf ("error getting codespaces: %w" , err )
4143 }
4244
43- table := output .NewTable (a .io .Out , asJSON )
44- table .SetHeader ([]string {"Name" , "Repository" , "Branch" , "State" , "Created At" })
45+ if err := a .io .StartPager (); err != nil {
46+ a .errLogger .Printf ("error starting pager: %v" , err )
47+ }
48+ defer a .io .StopPager ()
49+
50+ tp := utils .NewTablePrinter (a .io )
51+ if tp .IsTTY () {
52+ tp .AddField ("NAME" , nil , nil )
53+ tp .AddField ("REPOSITORY" , nil , nil )
54+ tp .AddField ("BRANCH" , nil , nil )
55+ tp .AddField ("STATE" , nil , nil )
56+ tp .AddField ("CREATED AT" , nil , nil )
57+ tp .EndRow ()
58+ }
59+
60+ cs := a .io .ColorScheme ()
4561 for _ , apiCodespace := range codespaces {
46- cs := codespace {apiCodespace }
47- table .Append ([]string {
48- cs .Name ,
49- cs .Repository .FullName ,
50- cs .branchWithGitStatus (),
51- cs .State ,
52- cs .CreatedAt ,
53- })
62+ c := codespace {apiCodespace }
63+
64+ var stateColor func (string ) string
65+ switch c .State {
66+ case api .CodespaceStateStarting :
67+ stateColor = cs .Yellow
68+ case api .CodespaceStateAvailable :
69+ stateColor = cs .Green
70+ }
71+
72+ tp .AddField (c .Name , nil , cs .Yellow )
73+ tp .AddField (c .Repository .FullName , nil , nil )
74+ tp .AddField (c .branchWithGitStatus (), nil , cs .Cyan )
75+ tp .AddField (c .State , nil , stateColor )
76+
77+ if tp .IsTTY () {
78+ ct , err := time .Parse (time .RFC3339 , c .CreatedAt )
79+ if err != nil {
80+ return fmt .Errorf ("error parsing date %q: %w" , c .CreatedAt , err )
81+ }
82+ tp .AddField (utils .FuzzyAgoAbbr (time .Now (), ct ), nil , cs .Gray )
83+ } else {
84+ tp .AddField (c .CreatedAt , nil , nil )
85+ }
86+ tp .EndRow ()
5487 }
5588
56- table .Render ()
57- return nil
89+ return tp .Render ()
5890}
0 commit comments