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

fix: Remove line length limit on MacOS for input prompts#839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kylecarbs merged 1 commit intomainfrommacterm
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletionscli/cliui/cliui_darwin.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
//go:build darwin
// +build darwin

package cliui

import (
"golang.org/x/sys/unix"

"golang.org/x/xerrors"
)

func removeLineLengthLimit(inputFD int) (func(), error) {
termios, err := unix.IoctlGetTermios(inputFD, unix.TIOCGETA)
if err != nil {
return nil, xerrors.Errorf("get termios: %w", err)
}
newState := *termios
// MacOS has a default line limit of 1024. See:
// https://unix.stackexchange.com/questions/204815/terminal-does-not-accept-pasted-or-typed-lines-of-more-than-1024-characters
//
// This removes canonical input processing, so deletes will not function
// as expected. This _seems_ fine for most use-cases, but is unfortunate.
newState.Lflag &^= unix.ICANON
err = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, &newState)
if err != nil {
return nil, xerrors.Errorf("set termios: %w", err)
}
return func() {
_ = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, termios)
}, nil
}
10 changes: 10 additions & 0 deletionscli/cliui/cliui_other.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
//go:build !darwin
// +build !darwin

package cliui

import "golang.org/x/xerrors"

func removeLineLengthLimit(_ int) (func(), error) {
return nil, xerrors.New("not implemented")
}
12 changes: 12 additions & 0 deletionscli/cliui/prompt.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
"io"
"os"
"os/signal"
"runtime"
"strings"

"github.com/bgentry/speakeasy"
Expand DownExpand Up@@ -42,10 +43,21 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
go func() {
var line string
var err error

inFile, valid := cmd.InOrStdin().(*os.File)
if opts.Secret && valid && isatty.IsTerminal(inFile.Fd()) {
line, err = speakeasy.Ask("")
} else {
if runtime.GOOS == "darwin" && valid {
var restore func()
restore, err = removeLineLengthLimit(int(inFile.Fd()))
if err != nil {
errCh <- err
return
}
defer restore()
}

reader := bufio.NewReader(cmd.InOrStdin())
line, err = reader.ReadString('\n')

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp