Skip to content

Commit 2908830

Browse files
committed
fix: Remove line length limit on MacOS for input prompts
This caused inputs to be truncated on MacOS terminals.
1 parent 2a7ab08 commit 2908830

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

cli/cliui/cliui_other.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package cliui
5+
6+
import (
7+
"golang.org/x/sys/unix"
8+
"golang.org/x/xerrors"
9+
)
10+
11+
func removeLineLengthLimit(inputFD int) (func(), error) {
12+
termios, err := unix.IoctlGetTermios(inputFD, unix.TCGETS)
13+
if err != nil {
14+
return nil, xerrors.Errorf("get termios: %w", err)
15+
}
16+
newState := *termios
17+
// MacOS has a default lint limit of 1024. See:
18+
// https://unix.stackexchange.com/questions/204815/terminal-does-not-accept-pasted-or-typed-lines-of-more-than-1024-characters
19+
newState.Lflag |= unix.ICANON
20+
err = unix.IoctlSetTermios(inputFD, unix.TCSETS, &newState)
21+
if err != nil {
22+
return nil, xerrors.Errorf("set termios: %w", err)
23+
}
24+
return func() {
25+
_ = unix.IoctlSetTermios(inputFD, unix.TCSETS, termios)
26+
}, nil
27+
}

cli/cliui/cliui_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package cliui
5+
6+
import "golang.org/x/xerrors"
7+
8+
func removeLineLengthLimit(inputFD int) (func(), error) {
9+
return nil, xerrors.New("not implemented")
10+
}

cli/cliui/prompt.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"os"
1010
"os/signal"
11+
"runtime"
1112
"strings"
1213

1314
"github.com/bgentry/speakeasy"
@@ -42,7 +43,18 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
4243
go func() {
4344
var line string
4445
var err error
46+
4547
inFile, valid := cmd.InOrStdin().(*os.File)
48+
if runtime.GOOS == "darwin" && valid {
49+
var restore func()
50+
restore, err = removeLineLengthLimit(int(inFile.Fd()))
51+
if err != nil {
52+
errCh <- err
53+
return
54+
}
55+
defer restore()
56+
}
57+
4658
if opts.Secret && valid && isatty.IsTerminal(inFile.Fd()) {
4759
line, err = speakeasy.Ask("")
4860
} else {

0 commit comments

Comments
 (0)