Skip to content

Commit 4e87001

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 4e87001

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

cli/cliui/cliui_darwin.go

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

cli/cliui/cliui_other.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build !darwin
2+
// +build !darwin
3+
4+
package cliui
5+
6+
import "golang.org/x/xerrors"
7+
8+
func removeLineLengthLimit(_ 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy