@@ -10,18 +10,6 @@ import (
1010 "github.com/cli/cli/v2/pkg/liveshare"
1111)
1212
13- type logger interface {
14- Print (v ... interface {}) (int , error )
15- Println (v ... interface {}) (int , error )
16- }
17-
18- // TODO(josebalius): clean this up once we standardrize
19- // logging for codespaces
20- type liveshareLogger interface {
21- Println (v ... interface {})
22- Printf (f string , v ... interface {})
23- }
24-
2513func connectionReady (codespace * api.Codespace ) bool {
2614 return codespace .Connection .SessionID != "" &&
2715 codespace .Connection .SessionToken != "" &&
@@ -35,43 +23,43 @@ type apiClient interface {
3523 StartCodespace (ctx context.Context , name string ) error
3624}
3725
26+ type progressIndicator interface {
27+ StartProgressIndicatorWithLabel (s string )
28+ StopProgressIndicator ()
29+ }
30+
31+ type logger interface {
32+ Println (v ... interface {})
33+ Printf (f string , v ... interface {})
34+ }
35+
3836// ConnectToLiveshare waits for a Codespace to become running,
3937// and connects to it using a Live Share session.
40- func ConnectToLiveshare (ctx context.Context , log logger , sessionLogger liveshareLogger , apiClient apiClient , codespace * api.Codespace ) (* liveshare.Session , error ) {
41- var startedCodespace bool
38+ func ConnectToLiveshare (ctx context.Context , progress progressIndicator , sessionLogger logger , apiClient apiClient , codespace * api.Codespace ) (sess * liveshare.Session , err error ) {
4239 if codespace .State != api .CodespaceStateAvailable {
43- startedCodespace = true
44- log .Print ("Starting your codespace..." )
40+ progress .StartProgressIndicatorWithLabel ("Starting codespace" )
4541 if err := apiClient .StartCodespace (ctx , codespace .Name ); err != nil {
4642 return nil , fmt .Errorf ("error starting codespace: %w" , err )
4743 }
4844 }
4945
5046 for retries := 0 ; ! connectionReady (codespace ); retries ++ {
5147 if retries > 1 {
52- if retries % 2 == 0 {
53- log .Print ("." )
54- }
55-
5648 time .Sleep (1 * time .Second )
5749 }
5850
5951 if retries == 30 {
6052 return nil , errors .New ("timed out while waiting for the codespace to start" )
6153 }
6254
63- var err error
6455 codespace , err = apiClient .GetCodespace (ctx , codespace .Name , true )
6556 if err != nil {
6657 return nil , fmt .Errorf ("error getting codespace: %w" , err )
6758 }
6859 }
6960
70- if startedCodespace {
71- fmt .Print ("\n " )
72- }
73-
74- log .Println ("Connecting to your codespace..." )
61+ progress .StartProgressIndicatorWithLabel ("Connecting to codespace" )
62+ defer progress .StopProgressIndicator ()
7563
7664 return liveshare .Connect (ctx , liveshare.Options {
7765 ClientName : "gh" ,
0 commit comments