@@ -25,12 +25,35 @@ import (
2525 "pb/pkg/config"
2626 "pb/pkg/model"
2727
28- "github.com/charmbracelet/bubbles/table"
2928 tea "github.com/charmbracelet/bubbletea"
3029 "github.com/charmbracelet/lipgloss"
3130 "github.com/spf13/cobra"
3231)
3332
33+ type ProfileListItem struct {
34+ title , url , user string
35+ }
36+
37+ func (item * ProfileListItem ) Render (highlight bool ) string {
38+ if highlight {
39+ render := fmt .Sprintf (
40+ "%s\n %s\n %s" ,
41+ selectedStyle .Render (item .title ),
42+ selectedStyleAlt .Render (fmt .Sprintf ("url: %s" , item .url )),
43+ selectedStyleAlt .Render (fmt .Sprintf ("user: %s" , item .user )),
44+ )
45+ return selectedItemOuter .Render (render )
46+ } else {
47+ render := fmt .Sprintf (
48+ "%s\n %s\n %s" ,
49+ standardStyle .Render (item .title ),
50+ standardStyleAlt .Render (fmt .Sprintf ("url: %s" , item .url )),
51+ standardStyleAlt .Render (fmt .Sprintf ("user: %s" , item .user )),
52+ )
53+ return itemOuter .Render (render )
54+ }
55+ }
56+
3457var AddProfileCmd = & cobra.Command {
3558 Use : "add name url <username?> <password?>" ,
3659 Example : "add local_logs http://0.0.0.0:8000 admin admin" ,
@@ -163,40 +186,17 @@ var ListProfileCmd = &cobra.Command{
163186 return nil
164187 }
165188
166- cols := []table.Column {
167- {Title : "PROFILE" , Width : 7 },
168- {Title : "URL" , Width : 5 },
169- {Title : "USER" , Width : 8 },
189+ if len (file_config .Profiles ) != 0 {
190+ println ()
170191 }
171192
172- rows := make ([]table.Row , len (file_config .Profiles ))
173- row_idx := 0
174- selected_row := 0
193+ row := 0
175194 for key , value := range file_config .Profiles {
176- if file_config .Default_profile == key {
177- selected_row = row_idx
178- }
179-
180- rows [row_idx ] = table.Row {key , value .Url , value .Username }
181- row_idx += 1
182-
183- // update max width for table
184- cols [0 ].Width = Max (cols [0 ].Width , len (key ))
185- cols [1 ].Width = Max (cols [1 ].Width , len (value .Url ))
186- cols [2 ].Width = Max (cols [2 ].Width , len (value .Password ))
195+ item := ProfileListItem {key , value .Url , value .Username }
196+ fmt .Println (item .Render (file_config .Default_profile == key ))
197+ row += 1
198+ fmt .Println ()
187199 }
188-
189- tbl := table .New (
190- table .WithColumns (cols ),
191- table .WithRows (rows ),
192- table .WithHeight (len (rows )),
193- table .WithStyles (listingTableStyle ()),
194- )
195-
196- tbl .SetCursor (selected_row )
197-
198- fmt .Println (tbl .View ())
199-
200200 return nil
201201 },
202202}
0 commit comments