INNER CODE UNIT · Go

makePauseHandler

umputun/ralphex · cmd/ralphex/main.go:944

func makePauseHandler(stdin io.Reader, stdout io.Writer) func(ctx context.Context) bool {
	return func(ctx context.Context) bool {
		fmt.Fprintln(stdout, "\nsession interrupted. press Enter to continue, Ctrl+C to abort")

		resultCh := make(chan bool, 1)
		go func() {
			buf := make([]byte, 1)
			n, _ := stdin.Read(buf) // blocks until Enter or EOF
			resultCh <- n > 0       // true = Enter (resume), false = EOF (abort)
		}()

		select {
		case resume := <-resultCh:
			return resume
		case <-ctx.Done():
			return false
		}
	}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…