terminator package provides utilities for terminal detection, pager management, browser launching, and Homebrew integration.
Installation
Terminal Detection
TTY Detection
Check if the application is running in a terminal:Use Cases
Color Detection
Check if color output is disabled:CI Detection
Detect if running in a Continuous Integration environment:- GitHub Actions
- Travis CI
- CircleCI
- Cirrus CI
- GitLab CI
- AppVeyor
- CodeShip
- Jenkins
- TeamCity
- TaskCluster
Pager Management
Display long output in a paginated format using a pager likeless or more.
Basic Usage
Pager Configuration
The pager respects thePAGER environment variable:
Custom Pager
Pager Example
Pager Type
Pager Methods
Browser Integration
Open URLs in the default web browser.Basic Usage
Cross-Platform Support
Supported Platforms
- macOS: Uses
opencommand - Windows: Uses
cmd /c startcommand - Linux: Uses
xdg-openorwslview(for WSL)
Non-blocking Browser Launch
Interactive Browser Prompt
Homebrew Integration
Utilities for detecting and working with Homebrew on macOS/Linux.Check Homebrew Installation
Check if Binary is from Homebrew
Update Check Example
Complete Example
Here’s a complete example combining multiple terminal utilities:Best Practices
- Always check IsTTY - Before using interactive features or colors
- Respect NO_COLOR - Check
IsColorDisabled()before using colors - Handle CI environments - Use
IsCI()to skip interactive prompts - Use pagers for long output - Improve UX for viewing large amounts of data
- Defer pager cleanup - Always use
defer pager.Stop() - Check TTY before opening browser - Browser commands require a terminal
- Provide fallbacks - Always offer non-interactive alternatives
- Test in different environments - Test with TTY, piped output, and CI