@@ -14,7 +14,9 @@ import (
1414 "path/filepath"
1515 "syscall"
1616
17- "github.com/jedib0t/go-pretty/table"
17+ "github.com/charmbracelet/colorprofile"
18+ "github.com/charmbracelet/lipgloss"
19+ "github.com/charmbracelet/lipgloss/table"
1820
1921 "github.com/smallstep/panoramix/v5/logware"
2022 "go.step.sm/crypto/randutil"
@@ -99,29 +101,9 @@ func runSimulator(ctx context.Context) (err error) {
99101 }
100102 }()
101103
102- t1 := table .NewWriter ()
103- t1 .SetOutputMirror (os .Stdout )
104- t1 .AppendRows ([]table.Row {
105- {"Version" , info .Version },
106- {"Interface" , fmt .Sprintf ("%s (simulator)" , info .Interface )},
107- {"Manufacturer" , info .Manufacturer },
108- {"Vendor Info" , info .VendorInfo },
109- {"Firmware Version" , info .FirmwareVersion },
110- })
111- for _ , ek := range eks {
112- u , err := ek .FingerprintURI ()
113- if err != nil {
114- return err
115- }
116- t1 .AppendRow (table.Row {
117- fmt .Sprintf ("EK URI (%s)" , ek .Type ()), u .String (),
118- })
104+ if err := printTPMInfo (info , eks , socket , seed ); err != nil {
105+ logger .ErrorContext (ctx , "failed printing TPM info" , logware .Error (err ))
119106 }
120- t1 .AppendRows ([]table.Row {
121- {"UNIX socket" , socket },
122- {"Seed" , seed },
123- })
124- t1 .Render ()
125107
126108 logger .InfoContext (ctx , "TPM simulator available" , slog .String ("socket" , socket ))
127109
@@ -188,6 +170,52 @@ func runSimulator(ctx context.Context) (err error) {
188170 }
189171}
190172
173+ var (
174+ purple = lipgloss .Color ("99" )
175+ gray = lipgloss .Color ("245" )
176+ lightGray = lipgloss .Color ("241" )
177+ headerStyle = lipgloss .NewStyle ().Foreground (purple ).Bold (true ).Align (lipgloss .Center )
178+ cellStyle = lipgloss .NewStyle ().Padding (0 , 1 ).MaxWidth (80 )
179+ oddRowStyle = cellStyle .Foreground (gray )
180+ evenRowStyle = cellStyle .Foreground (lightGray )
181+ )
182+
183+ func printTPMInfo (info * tpm.Info , eks []* tpm.EK , socket , seed string ) error {
184+ tbl := table .New ().
185+ Border (lipgloss .NormalBorder ()).
186+ BorderStyle (lipgloss .NewStyle ().Foreground (purple )).
187+ StyleFunc (func (row , col int ) lipgloss.Style {
188+ switch {
189+ case row == table .HeaderRow :
190+ return headerStyle
191+ case row % 2 == 0 :
192+ return evenRowStyle
193+ default :
194+ return oddRowStyle
195+ }
196+ })
197+
198+ tbl .Row ("Version" , info .Version .String ())
199+ tbl .Row ("Interface" , fmt .Sprintf ("%s (simulator)" , info .Interface ))
200+ tbl .Row ("Manufacturer" , info .Manufacturer .String ())
201+ tbl .Row ("Vendor Info" , info .VendorInfo )
202+ tbl .Row ("Firmware Version" , info .FirmwareVersion .String ())
203+ for _ , ek := range eks {
204+ u , err := ek .FingerprintURI ()
205+ if err != nil {
206+ return err
207+ }
208+ tbl .Row (fmt .Sprintf ("EK URI (%s)" , ek .Type ()), u .String ())
209+ }
210+ tbl .Row ("UNIX socket" , socket )
211+ tbl .Row ("Seed" , seed )
212+
213+ w := colorprofile .NewWriter (os .Stdout , os .Environ ())
214+ fmt .Fprintln (w , tbl )
215+
216+ return nil
217+ }
218+
191219func getTPMSimulatorSocketPath () (sockAddr string , err error ) {
192220 paths := []string {"/run" , "/var/run" }
193221 for _ , dir := range paths {
0 commit comments