mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-19 17:59:05 -05:00
Go 1.17 and earlier used a different syntax for build constraint comments, starting with "+build". Go 1.18 changed this to the modern "go:build" form as part of standardizing the structure of toolchain directive comments, and so for a while it was convention to include comments in both styles to allow building with both old and new Go compilers. However, Go 1.17 is no longer supported, and regardless of that we only expect OpenTofu to be built with the specific version we have selected in "go.mod" and ".go-version" anyway, so we no longer need the legacy form of these comments: the all supported Go toolchains now support the new form, which this commit retains. golangci-lint v2.6.0 includes a check for this legacy form, so removing this will also allow us to upgrade to a newer version of that linter aggregator in a future commit. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
//go:build !windows
|
|
|
|
package terminal
|
|
|
|
import (
|
|
"os"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
// This is the implementation for all operating systems except Windows, where
|
|
// we don't expect to need to do any special initialization to get a working
|
|
// Virtual Terminal.
|
|
//
|
|
// For this implementation we just delegate everything upstream to
|
|
// golang.org/x/term, since it already has a variety of different
|
|
// implementations for quirks of more esoteric operating systems like plan9,
|
|
// and will hopefully grow to include others as Go is ported to other platforms
|
|
// in future.
|
|
//
|
|
// For operating systems that golang.org/x/term doesn't support either, it
|
|
// defaults to indicating that nothing is a terminal and returns an error when
|
|
// asked for a size, which we'll handle below.
|
|
|
|
func configureOutputHandle(f *os.File) (*OutputStream, error) {
|
|
return &OutputStream{
|
|
File: f,
|
|
isTerminal: isTerminalGolangXTerm,
|
|
getColumns: getColumnsGolangXTerm,
|
|
}, nil
|
|
}
|
|
|
|
func configureInputHandle(f *os.File) (*InputStream, error) {
|
|
return &InputStream{
|
|
File: f,
|
|
isTerminal: isTerminalGolangXTerm,
|
|
}, nil
|
|
}
|
|
|
|
func isTerminalGolangXTerm(f *os.File) bool {
|
|
return term.IsTerminal(int(f.Fd()))
|
|
}
|
|
|
|
func getColumnsGolangXTerm(f *os.File) int {
|
|
width, _, err := term.GetSize(int(f.Fd()))
|
|
if err != nil {
|
|
// Suggests that it's either not a terminal at all or that we're on
|
|
// a platform that golang.org/x/term doesn't support. In both cases
|
|
// we'll just return the placeholder default value.
|
|
return defaultColumns
|
|
}
|
|
return width
|
|
}
|