go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/cli/components/components.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package components
     5  
     6  import (
     7  	"errors"
     8  	"os"
     9  
    10  	"golang.org/x/term"
    11  )
    12  
    13  func TerminalWidth(f *os.File) (int, error) {
    14  	w, _, err := term.GetSize(int(f.Fd()))
    15  	if err != nil {
    16  		return 0, errors.New("can't query terminal size")
    17  	}
    18  	return w, nil
    19  }