github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/columns/options.go (about) 1 // Copyright 2022-2023 The Inspektor Gadget authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package columns 16 17 import "github.com/inspektor-gadget/inspektor-gadget/pkg/columns/ellipsis" 18 19 type Option func(*Options) 20 21 type Options struct { 22 DefaultAlignment Alignment // default text alignment to use; default AlignLeft 23 DefaultEllipsis ellipsis.EllipsisType // default type of ellipsis to use for overflowing text; default: ellipsis.End 24 DefaultWidth int // width to be used when no width is specified for a column; default: 16 25 RequireColumnDefinition bool // if set to false, Columns will consider all struct members, regardless of the column tag (in backticks behind the struct field, like `column:"columnName"`) being present; default: true 26 } 27 28 func GetDefault() *Options { 29 return &Options{ 30 DefaultAlignment: AlignLeft, 31 DefaultEllipsis: ellipsis.End, 32 DefaultWidth: 16, 33 RequireColumnDefinition: true, 34 } 35 } 36 37 // WithAlignment sets the default alignment 38 func WithAlignment(a Alignment) Option { 39 return func(opts *Options) { 40 opts.DefaultAlignment = a 41 } 42 } 43 44 // WithEllipsis sets the default ellipsis type 45 func WithEllipsis(e ellipsis.EllipsisType) Option { 46 return func(opts *Options) { 47 opts.DefaultEllipsis = e 48 } 49 } 50 51 // WithRequireColumnDefinition sets whether the library should handle struct members without a column tag 52 func WithRequireColumnDefinition(require bool) Option { 53 return func(opts *Options) { 54 opts.RequireColumnDefinition = require 55 } 56 } 57 58 // WithWidth sets the default column width 59 func WithWidth(w int) Option { 60 return func(opts *Options) { 61 opts.DefaultWidth = w 62 } 63 }