mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
fix: Remove line length limit on MacOS for input prompts (#839)
This caused inputs to be truncated on MacOS terminals.
This commit is contained in:
31
cli/cliui/cliui_darwin.go
Normal file
31
cli/cliui/cliui_darwin.go
Normal file
@ -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
cli/cliui/cliui_other.go
Normal file
10
cli/cliui/cliui_other.go
Normal file
@ -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")
|
||||||
|
}
|
@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bgentry/speakeasy"
|
"github.com/bgentry/speakeasy"
|
||||||
@ -42,10 +43,21 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
|
|||||||
go func() {
|
go func() {
|
||||||
var line string
|
var line string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
inFile, valid := cmd.InOrStdin().(*os.File)
|
inFile, valid := cmd.InOrStdin().(*os.File)
|
||||||
if opts.Secret && valid && isatty.IsTerminal(inFile.Fd()) {
|
if opts.Secret && valid && isatty.IsTerminal(inFile.Fd()) {
|
||||||
line, err = speakeasy.Ask("")
|
line, err = speakeasy.Ask("")
|
||||||
} else {
|
} 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())
|
reader := bufio.NewReader(cmd.InOrStdin())
|
||||||
line, err = reader.ReadString('\n')
|
line, err = reader.ReadString('\n')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user