зеркало из https://github.com/mislav/hub.git
Set the stdin for the child process instead of reset the stdin of the parent process
This commit is contained in:
Родитель
aa9e564e01
Коммит
d937d28703
15
cmd/cmd.go
15
cmd/cmd.go
|
@ -14,8 +14,11 @@ import (
|
|||
)
|
||||
|
||||
type Cmd struct {
|
||||
Name string
|
||||
Args []string
|
||||
Name string
|
||||
Args []string
|
||||
Stdin *os.File
|
||||
Stdout *os.File
|
||||
Stderr *os.File
|
||||
}
|
||||
|
||||
func (cmd Cmd) String() string {
|
||||
|
@ -63,9 +66,9 @@ func (cmd *Cmd) Run() error {
|
|||
func (cmd *Cmd) Spawn() error {
|
||||
verboseLog(cmd)
|
||||
c := exec.Command(cmd.Name, cmd.Args...)
|
||||
c.Stdin = os.Stdin
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
c.Stdin = cmd.Stdin
|
||||
c.Stdout = cmd.Stdout
|
||||
c.Stderr = cmd.Stderr
|
||||
|
||||
return c.Run()
|
||||
}
|
||||
|
@ -98,7 +101,7 @@ func New(cmd string) *Cmd {
|
|||
for _, arg := range cmds[1:] {
|
||||
args = append(args, arg)
|
||||
}
|
||||
return &Cmd{Name: name, Args: args}
|
||||
return &Cmd{Name: name, Args: args, Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr}
|
||||
}
|
||||
|
||||
func NewWithArray(cmd []string) *Cmd {
|
||||
|
|
|
@ -118,7 +118,7 @@ func openTextEditor(program, file string) error {
|
|||
}
|
||||
editCmd.WithArg(file)
|
||||
// Reattach stdin to the console before opening the editor
|
||||
resetConsole()
|
||||
setConsole(editCmd)
|
||||
|
||||
return editCmd.Spawn()
|
||||
}
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"os"
|
||||
|
||||
"github.com/github/hub/cmd"
|
||||
)
|
||||
|
||||
func resetConsole() {
|
||||
fd, err := syscall.Open("/dev/tty", syscall.O_RDONLY, 0660)
|
||||
func setConsole(cmd *cmd.Cmd) {
|
||||
|
||||
stdin, err := os.OpenFile("/dev/tty", os.O_RDONLY, 0660)
|
||||
if err == nil {
|
||||
syscall.Dup2(fd, syscall.Stdin)
|
||||
cmd.Stdin = stdin
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
package commands
|
||||
|
||||
// This does nothing on windows
|
||||
func resetConsole() {
|
||||
func setConsole(cmd *cmd.Cmd) {
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче