Skip to content

Commit

Permalink
use library to detect terminal size
Browse files Browse the repository at this point in the history
  • Loading branch information
foteinigk committed Apr 29, 2024
1 parent 53265d5 commit f7db8cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/urfave/cli/v2 v2.3.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
gopkg.in/ini.v1 v1.62.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
5 changes: 5 additions & 0 deletions internal/txlib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/mattn/go-isatty"
"github.com/transifex/cli/internal/txlib/config"
"github.com/transifex/cli/pkg/jsonapi"
"golang.org/x/crypto/ssh/terminal"

Check failure on line 15 in internal/txlib/utils.go

View workflow job for this annotation

GitHub Actions / staticcheck

package golang.org/x/crypto/ssh/terminal is deprecated: this package moved to golang.org/x/term. (SA1019)
)

func figureOutBranch(branch string) string {
Expand Down Expand Up @@ -213,6 +214,10 @@ func isValidResolutionPolicy(policy string) (IsValid bool) {

func truncateMessage(message string) string {
maxLength := 80
width, _, err := terminal.GetSize(int(os.Stdout.Fd()))
if err != nil && width > 0 {
maxLength = width
}
if len(message) > maxLength {
return message[:maxLength-2] + ".."
}
Expand Down

0 comments on commit f7db8cc

Please sign in to comment.