Skip to content

Commit 1cbe60d

Browse files
committed
优化 Start 函数中的延迟逻辑,减少 shell 启动和读取超时的时间
1 parent 4e2013d commit 1cbe60d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/crosspty/pty.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Start(shellPath string, env map[string]string, welcome string) error {
6262

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

65-
time.Sleep(1500 * time.Millisecond) // Give the shell some time to start.
65+
time.Sleep(1000 * time.Millisecond) // Give the shell some time to start.
6666

6767
// Copy stdin to the pty and the pty to stdout.
6868
// NOTE: The goroutine will keep reading until the next keystroke before returning.
@@ -100,7 +100,7 @@ func Start(shellPath string, env map[string]string, welcome string) error {
100100
_, _ = ptmx.Write([]byte("clear" + newLine))
101101
}
102102

103-
// 清空掉 ptmx 的 stdout 缓冲区,使用 channel 并限制最多读取 500 毫秒
103+
// 清空掉 ptmx 的 stdout 缓冲区,使用 channel 并限制最多读取 200 毫秒
104104
buf := make([]byte, 1024)
105105
readCh := make(chan struct{})
106106
stopCh := make(chan struct{})
@@ -122,8 +122,8 @@ func Start(shellPath string, env map[string]string, welcome string) error {
122122
select {
123123
case <-readCh:
124124
// Completed reading
125-
case <-time.After(500 * time.Millisecond):
126-
// Timeout after 500ms, signal to stop reading
125+
case <-time.After(200 * time.Millisecond):
126+
// Timeout after 200ms, signal to stop reading
127127
close(stopCh)
128128
}
129129

0 commit comments

Comments
 (0)