Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitccba2ba

Browse files
authored
fix: Remove line length limit on MacOS for input prompts (#839)
This caused inputs to be truncated on MacOS terminals.
1 parent2a7ab08 commitccba2ba

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+
funcremoveLineLengthLimit(inputFDint) (func(),error) {
13+
termios,err:=unix.IoctlGetTermios(inputFD,unix.TIOCGETA)
14+
iferr!=nil {
15+
returnnil,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+
iferr!=nil {
26+
returnnil,xerrors.Errorf("set termios: %w",err)
27+
}
28+
returnfunc() {
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+
funcremoveLineLengthLimit(_int) (func(),error) {
9+
returnnil,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
gofunc() {
4344
varlinestring
4445
varerrerror
46+
4547
inFile,valid:=cmd.InOrStdin().(*os.File)
4648
ifopts.Secret&&valid&&isatty.IsTerminal(inFile.Fd()) {
4749
line,err=speakeasy.Ask("")
4850
}else {
51+
ifruntime.GOOS=="darwin"&&valid {
52+
varrestorefunc()
53+
restore,err=removeLineLengthLimit(int(inFile.Fd()))
54+
iferr!=nil {
55+
errCh<-err
56+
return
57+
}
58+
deferrestore()
59+
}
60+
4961
reader:=bufio.NewReader(cmd.InOrStdin())
5062
line,err=reader.ReadString('\n')
5163

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp