()
| 93 | } |
| 94 | |
| 95 | func (h *hijackedIOStreamer) setupInput() (restore func(), _ error) { |
| 96 | if h.inputStream == nil || !h.tty { |
| 97 | // No need to setup input TTY. |
| 98 | // The restore func is a nop. |
| 99 | return func() {}, nil |
| 100 | } |
| 101 | if err := validateDetachKeys(h.detachKeys); err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | if err := setRawTerminal(h.streams); err != nil { |
| 105 | return nil, fmt.Errorf("unable to set IO streams as raw terminal: %s", err) |
| 106 | } |
| 107 | |
| 108 | // Use sync.Once so we may call restore multiple times but ensure we |
| 109 | // only restore the terminal once. |
| 110 | restore = sync.OnceFunc(func() { |
| 111 | _ = restoreTerminal(h.streams, h.inputStream) |
| 112 | }) |
| 113 | |
| 114 | // Wrap the input to detect detach escape sequence. |
| 115 | // Use default escape keys if an invalid sequence is given. |
| 116 | escapeKeys := defaultEscapeKeys |
| 117 | if h.detachKeys != "" { |
| 118 | var err error |
| 119 | escapeKeys, err = term.ToBytes(h.detachKeys) |
| 120 | if err != nil { |
| 121 | restore() |
| 122 | return nil, err |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | h.inputStream = &readCloserWrapper{ |
| 127 | Reader: term.NewEscapeProxy(h.inputStream, escapeKeys), |
| 128 | closer: h.inputStream.Close, |
| 129 | } |
| 130 | |
| 131 | return restore, nil |
| 132 | } |
| 133 | |
| 134 | func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error { |
| 135 | if h.outputStream == nil && h.errorStream == nil { |
no test coverage detected