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

Commite498821

Browse files
committed
fix: Remove line length limit on MacOS for input prompts
This caused inputs to be truncated on MacOS terminals.
1 parent2a7ab08 commite498821

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+
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 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+
iferr!=nil {
23+
returnnil,xerrors.Errorf("set termios: %w",err)
24+
}
25+
returnfunc() {
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+
funcremoveLineLengthLimit(inputFDint) (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,7 +43,18 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
4243
gofunc() {
4344
varlinestring
4445
varerrerror
46+
4547
inFile,valid:=cmd.InOrStdin().(*os.File)
48+
ifruntime.GOOS=="darwin"&&valid {
49+
varrestorefunc()
50+
restore,err=removeLineLengthLimit(int(inFile.Fd()))
51+
iferr!=nil {
52+
errCh<-err
53+
return
54+
}
55+
deferrestore()
56+
}
57+
4658
ifopts.Secret&&valid&&isatty.IsTerminal(inFile.Fd()) {
4759
line,err=speakeasy.Ask("")
4860
}else {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp