()
| 508 | } |
| 509 | |
| 510 | func System() *IOStreams { |
| 511 | terminal := ghTerm.FromEnv() |
| 512 | |
| 513 | var stdout fileWriter = os.Stdout |
| 514 | // On Windows with no virtual terminal processing support, translate ANSI escape |
| 515 | // sequences to console syscalls. |
| 516 | if colorableStdout := colorable.NewColorable(os.Stdout); colorableStdout != os.Stdout { |
| 517 | // Ensure that the file descriptor of the original stdout is preserved. |
| 518 | stdout = &fdWriter{ |
| 519 | fd: os.Stdout.Fd(), |
| 520 | Writer: colorableStdout, |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | var stderr fileWriter = os.Stderr |
| 525 | // On Windows with no virtual terminal processing support, translate ANSI escape |
| 526 | // sequences to console syscalls. |
| 527 | if colorableStderr := colorable.NewColorable(os.Stderr); colorableStderr != os.Stderr { |
| 528 | // Ensure that the file descriptor of the original stderr is preserved. |
| 529 | stderr = &fdWriter{ |
| 530 | fd: os.Stderr.Fd(), |
| 531 | Writer: colorableStderr, |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | io := &IOStreams{ |
| 536 | In: os.Stdin, |
| 537 | Out: stdout, |
| 538 | ErrOut: stderr, |
| 539 | pagerCommand: os.Getenv("PAGER"), |
| 540 | term: &terminal, |
| 541 | sanitizeContent: true, |
| 542 | } |
| 543 | io.ContentOut = newContentWriter(io.Out, io.sanitizeContent) |
| 544 | |
| 545 | stdoutIsTTY := io.IsStdoutTTY() |
| 546 | stderrIsTTY := io.IsStderrTTY() |
| 547 | |
| 548 | if stdoutIsTTY && stderrIsTTY { |
| 549 | io.progressIndicatorEnabled = true |
| 550 | } |
| 551 | |
| 552 | if stdoutIsTTY && hasAlternateScreenBuffer(terminal.IsTrueColorSupported()) { |
| 553 | io.alternateScreenBufferEnabled = true |
| 554 | } |
| 555 | |
| 556 | return io |
| 557 | } |
| 558 | |
| 559 | type fakeTerm struct{} |
| 560 |
no test coverage detected