become: Set stdin to /dev/tty

This commit is contained in:
Junegunn Choi 2023-02-14 23:21:34 +09:00
parent 9e9c0ceaf4
commit 4e305eca26
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 11 additions and 0 deletions

View File

@ -2876,6 +2876,7 @@ func (t *Terminal) Loop() {
if t.history != nil { if t.history != nil {
t.history.append(string(t.input)) t.history.append(string(t.input))
} }
util.SetStdin(tui.TtyIn())
syscall.Exec(shellPath, []string{shell, "-c", command}, os.Environ()) syscall.Exec(shellPath, []string{shell, "-c", command}, os.Environ())
} }
} }

View File

@ -6,6 +6,8 @@ import (
"os" "os"
"os/exec" "os/exec"
"syscall" "syscall"
"golang.org/x/sys/unix"
) )
// ExecCommand executes the given command with $SHELL // ExecCommand executes the given command with $SHELL
@ -45,3 +47,7 @@ func SetNonblock(file *os.File, nonblock bool) {
func Read(fd int, b []byte) (int, error) { func Read(fd int, b []byte) (int, error) {
return syscall.Read(int(fd), b) return syscall.Read(int(fd), b)
} }
func SetStdin(file *os.File) {
unix.Dup2(int(file.Fd()), 0)
}

View File

@ -81,3 +81,7 @@ func SetNonblock(file *os.File, nonblock bool) {
func Read(fd int, b []byte) (int, error) { func Read(fd int, b []byte) (int, error) {
return syscall.Read(syscall.Handle(fd), b) return syscall.Read(syscall.Handle(fd), b)
} }
func SetStdin(file *os.File) {
// No-op
}