Skip to content

Commit 15087e2

Browse files
committed
优化 Start 函数中的 shell 启动延迟逻辑,调整时间并重组代码结构
1 parent 3aadf34 commit 15087e2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

internal/crosspty/pty.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,10 @@ func Start(shellPath string, env map[string]string) error {
5252

5353
defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
5454

55+
time.Sleep(1500 * time.Millisecond) // Give the shell some time to start.
56+
5557
// Copy stdin to the pty and the pty to stdout.
5658
// NOTE: The goroutine will keep reading until the next keystroke before returning.
57-
go func() {
58-
_, _ = io.Copy(ptmx, os.Stdin)
59-
}()
60-
go func() {
61-
_, _ = io.Copy(os.Stdout, ptmx)
62-
}()
63-
64-
time.Sleep(500 * time.Millisecond) // Give the shell some time to start.
65-
6659
shellName := filepath.Base(shellPath)
6760

6861
// Set environment variables
@@ -95,5 +88,13 @@ func Start(shellPath string, env map[string]string) error {
9588
_, _ = ptmx.Write([]byte("clear\n"))
9689
}
9790

91+
go func() {
92+
_, _ = io.Copy(ptmx, os.Stdin)
93+
}()
94+
95+
go func() {
96+
_, _ = io.Copy(os.Stdout, ptmx)
97+
}()
98+
9899
return c.Wait()
99100
}

0 commit comments

Comments
 (0)