(argv []string, stdout io.Writer, stderr io.Writer, exitWithError bool)
| 173 | } |
| 174 | |
| 175 | func (t *testSessionChannel) run(argv []string, stdout io.Writer, stderr io.Writer, exitWithError bool) (err error) { |
| 176 | switch argv[0] { |
| 177 | case "echo": |
| 178 | _, err = stdout.Write([]byte(strings.Join(argv[1:], " ") + "\n")) |
| 179 | case "tput": |
| 180 | if len(argv) > 2 || (argv[1] != "cols" && argv[1] != "rows") { |
| 181 | _, err = stderr.Write([]byte("Usage: tput [rows|cols]")) |
| 182 | if exitWithError { |
| 183 | return fmt.Errorf("usage: tput [rows|cols]") |
| 184 | } |
| 185 | } else if !t.pty { |
| 186 | _, err = stderr.Write([]byte("Stdout is not a TTY")) |
| 187 | if exitWithError { |
| 188 | return fmt.Errorf("usage: tput [rows|cols]") |
| 189 | } |
| 190 | } else { |
| 191 | switch argv[1] { |
| 192 | case "cols": |
| 193 | _, err = stdout.Write([]byte(fmt.Sprintf("%d\n", t.columns))) |
| 194 | case "rows": |
| 195 | _, err = stdout.Write([]byte(fmt.Sprintf("%d\n", t.rows))) |
| 196 | } |
| 197 | } |
| 198 | default: |
| 199 | _, err = stderr.Write([]byte(fmt.Sprintf("unknown program: %s", argv[0]))) |
| 200 | if exitWithError { |
| 201 | return fmt.Errorf("unknown program: %s", argv[0]) |
| 202 | } |
| 203 | } |
| 204 | return err |
| 205 | } |
| 206 | |
| 207 | func (t *testSessionChannel) OnSignal( |
| 208 | _ uint64, |
no test coverage detected