-
Notifications
You must be signed in to change notification settings - Fork 263
/
formatter_text.go
39 lines (31 loc) · 960 Bytes
/
formatter_text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package controldisplay
import (
"context"
"fmt"
"io"
"strings"
"github.com/turbot/steampipe/pkg/constants"
"github.com/turbot/steampipe/pkg/control/controlexecute"
"github.com/turbot/steampipe/pkg/display"
"github.com/turbot/steampipe/pkg/utils"
)
const MaxColumns = 200
type TextFormatter struct {
FormatterBase
}
func (tf TextFormatter) Format(_ context.Context, tree *controlexecute.ExecutionTree) (io.Reader, error) {
renderer := NewTableRenderer(tree)
widthConstraint := utils.NewRangeConstraint(renderer.MinimumWidth(), MaxColumns)
renderedText := renderer.Render(widthConstraint.Constrain(display.GetMaxCols()))
res := strings.NewReader(fmt.Sprintf("\n%s\n", renderedText))
return res, nil
}
func (tf TextFormatter) FileExtension() string {
return constants.TextExtension
}
func (tf TextFormatter) Name() string {
return constants.OutputFormatText
}
func (tf TextFormatter) Alias() string {
return constants.OutputFormatBrief
}