()
| 166 | } |
| 167 | |
| 168 | func (s *Shell) run() { |
| 169 | shell: |
| 170 | for s.Active() { |
| 171 | var line []string |
| 172 | var err error |
| 173 | read := make(chan struct{}) |
| 174 | go func() { |
| 175 | line, err = s.read() |
| 176 | read <- struct{}{} |
| 177 | }() |
| 178 | select { |
| 179 | case <-read: |
| 180 | break |
| 181 | case <-s.haltChan: |
| 182 | continue shell |
| 183 | } |
| 184 | |
| 185 | if err == io.EOF { |
| 186 | if s.eof == nil { |
| 187 | fmt.Println("EOF") |
| 188 | break |
| 189 | } |
| 190 | if err := handleEOF(s); err != nil { |
| 191 | s.Println("Error:", err) |
| 192 | continue |
| 193 | } |
| 194 | } else if err != nil && err != readline.ErrInterrupt { |
| 195 | s.Println("Error:", err) |
| 196 | continue |
| 197 | } |
| 198 | |
| 199 | if err == readline.ErrInterrupt { |
| 200 | // interrupt received |
| 201 | err = handleInterrupt(s, line) |
| 202 | } else { |
| 203 | // reset interrupt counter |
| 204 | s.interruptCount = 0 |
| 205 | |
| 206 | // normal flow |
| 207 | if len(line) == 0 { |
| 208 | // no input line |
| 209 | continue |
| 210 | } |
| 211 | |
| 212 | err = handleInput(s, line) |
| 213 | } |
| 214 | if err != nil { |
| 215 | s.Println("Error:", err) |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // Active tells if the shell is active. i.e. Start is previously called. |
| 221 | func (s *Shell) Active() bool { |
no test coverage detected