Skip to content

Commit

Permalink
Widen the values field in larger terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg committed Mar 6, 2024
1 parent 65b6773 commit e63b1e7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ require (
require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
29 changes: 28 additions & 1 deletion pkg/bincapz/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"

"github.com/olekukonko/tablewriter"
"golang.org/x/term"
"k8s.io/klog/v2"
)

type KeyedBehavior struct {
Expand All @@ -30,6 +32,20 @@ func forceWrap(s string, x int) string {
return strings.Join(fw, "\n")
}

func terminalWidth() int {
if !term.IsTerminal(0) {
return 120
}

width, _, err := term.GetSize(0)
if err != nil {
klog.Errorf("term.getsize: %v", err)
return 80
}

return width
}

func RenderTable(fr *FileReport, w io.Writer) {
path := fr.Path
if fr.Error != "" {
Expand Down Expand Up @@ -69,9 +85,20 @@ func RenderTable(fr *FileReport, w io.Writer) {
data = append(data, []string{"", "", "", ""})
}

valWidth := 24
width := terminalWidth()
if width > 110 {
valWidth += (width - 110)
}
if valWidth > 60 {
valWidth = 60
}

klog.Infof("terminal width: %d / val width: %d", width, valWidth)

for _, k := range kbs {
val := strings.Join(k.Behavior.Strings, " ")
val = forceWrap(val, 24)
val = forceWrap(val, valWidth)

desc := k.Behavior.Description
before, _, found := strings.Cut(desc, ". ")
Expand Down
2 changes: 1 addition & 1 deletion pkg/bincapz/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Scan(c Config) (*Report, error) {
kind := programKind(p)
if !c.IncludeDataFiles && kind == "" {
r.Files[p] = FileReport{Skipped: fmt.Sprintf("data file")}
klog.Infof("skipping %s - does not appear to be a program")
klog.Infof("not a program: %s", p)
continue
}

Expand Down

0 comments on commit e63b1e7

Please sign in to comment.