()
| 476 | } |
| 477 | |
| 478 | func System() *IOStreams { |
| 479 | terminal := ghTerm.FromEnv() |
| 480 | |
| 481 | var stdout fileWriter = os.Stdout |
| 482 | // On Windows with no virtual terminal processing support, translate ANSI escape |
| 483 | // sequences to console syscalls. |
| 484 | if colorableStdout := colorable.NewColorable(os.Stdout); colorableStdout != os.Stdout { |
| 485 | // Ensure that the file descriptor of the original stdout is preserved. |
| 486 | stdout = &fdWriter{ |
| 487 | fd: os.Stdout.Fd(), |
| 488 | Writer: colorableStdout, |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | var stderr fileWriter = os.Stderr |
| 493 | // On Windows with no virtual terminal processing support, translate ANSI escape |
| 494 | // sequences to console syscalls. |
| 495 | if colorableStderr := colorable.NewColorable(os.Stderr); colorableStderr != os.Stderr { |
| 496 | // Ensure that the file descriptor of the original stderr is preserved. |
| 497 | stderr = &fdWriter{ |
| 498 | fd: os.Stderr.Fd(), |
| 499 | Writer: colorableStderr, |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | io := &IOStreams{ |
| 504 | In: os.Stdin, |
| 505 | Out: stdout, |
| 506 | ErrOut: stderr, |
| 507 | pagerCommand: os.Getenv("PAGER"), |
| 508 | term: &terminal, |
| 509 | } |
| 510 | |
| 511 | stdoutIsTTY := io.IsStdoutTTY() |
| 512 | stderrIsTTY := io.IsStderrTTY() |
| 513 | |
| 514 | if stdoutIsTTY && stderrIsTTY { |
| 515 | io.progressIndicatorEnabled = true |
| 516 | } |
| 517 | |
| 518 | if stdoutIsTTY && hasAlternateScreenBuffer(terminal.IsTrueColorSupported()) { |
| 519 | io.alternateScreenBufferEnabled = true |
| 520 | } |
| 521 | |
| 522 | return io |
| 523 | } |
| 524 | |
| 525 | type fakeTerm struct{} |
| 526 |
no test coverage detected