Files
cli/pkg/ux/table_compat.go
zeekay 579f53c3cc chore: remove local replace directives and update dependencies
- Update github.com/luxfi/netrunner v1.15.3 → v1.15.4
- Update github.com/luxfi/node v1.22.77 → v1.22.80
- Remove local replace directive for netrunner
- Use published package versions for reproducible builds
2026-01-03 07:09:01 -08:00

76 lines
2.0 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ux
import (
"os"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/tw"
)
// Alignment constants for backward compatibility
var (
AlignLeft = tw.AlignLeft
AlignCenter = tw.AlignCenter
AlignRight = tw.AlignRight
)
// TableCompatWrapper provides backward compatibility for tablewriter v0.0.5 API
// on top of tablewriter v1.0.9+
type TableCompatWrapper struct {
*tablewriter.Table
headers []string
alignment tw.Align
}
// NewCompatTable creates a new table with v0.0.5-like API
func NewCompatTable() *TableCompatWrapper {
return &TableCompatWrapper{
Table: tablewriter.NewTable(os.Stdout),
alignment: tw.AlignLeft,
}
}
// SetHeader sets the headers using the old API
func (t *TableCompatWrapper) SetHeader(headers []string) {
t.headers = headers
// Convert []string to []any for the new API
anyHeaders := make([]any, len(headers))
for i, h := range headers {
anyHeaders[i] = h
}
t.Header(anyHeaders...)
}
// SetRowLine is a no-op in v1.0.9 (row lines controlled via renderer settings)
func (*TableCompatWrapper) SetRowLine(_ bool) {
// Row lines are now controlled via renderer configuration
// This is a no-op for compatibility
}
// SetAutoMergeCells is a no-op in v1.0.9 (merge mode controlled via config)
func (*TableCompatWrapper) SetAutoMergeCells(_ bool) {
// Cell merging is now controlled via config.Row.Formatting.MergeMode
// This is a no-op for compatibility
}
// SetAlignment sets the alignment for rows
func (t *TableCompatWrapper) SetAlignment(align tw.Align) {
t.alignment = align
t.Configure(func(config *tablewriter.Config) {
config.Row.Alignment.Global = t.alignment
})
}
// AppendCompat adds a row using string slice (old API)
func (t *TableCompatWrapper) AppendCompat(row []string) {
_ = t.Append(row)
}
// CreateCompatTable creates a table with v0.0.5-like API
func CreateCompatTable() *TableCompatWrapper {
return NewCompatTable()
}