Skip to content

Commit ccba2ba

Browse files
authored
fix: Remove line length limit on MacOS for input prompts (#839)
This caused inputs to be truncated on MacOS terminals.
1 parent 2a7ab08 commit ccba2ba

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

cli/cliui/cliui_darwin.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build darwin
2+
// +build darwin
3+
4+
package cliui
5+
6+
import (
7+
"golang.org/x/sys/unix"
8+
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 line 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+
//
21+
// This removes canonical input processing, so deletes will not function
22+
// as expected. This _seems_ fine for most use-cases, but is unfortunate.
23+
newState.Lflag &^= unix.ICANON
24+
err = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, &newState)
25+
if err != nil {
26+
return nil, xerrors.Errorf("set termios: %w", err)
27+
}
28+
return func() {
29+
_ = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, termios)
30+
}, nil
31+
}

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,10 +43,21 @@ 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)
4648
if opts.Secret && valid && isatty.IsTerminal(inFile.Fd()) {
4749
line, err = speakeasy.Ask("")
4850
} else {
51+
if runtime.GOOS == "darwin" && valid {
52+
var restore func()
53+
restore, err = removeLineLengthLimit(int(inFile.Fd()))
54+
if err != nil {
55+
errCh <- err
56+
return
57+
}
58+
defer restore()
59+
}
60+
4961
reader := bufio.NewReader(cmd.InOrStdin())
5062
line, err = reader.ReadString('\n')
5163

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