switon / console
Reusable terminal primitives including progress bars, width detection, and ANSI styling for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
Reusable terminal primitives for progress bars, terminal width detection, and ANSI styling in Switon Framework.
Highlights
- Progress bars:
ProgressBarInterfacewith elapsed and remaining time rendering. - Width detection:
TerminalWidthDetectorInterfacewith Unix and Windows fallbacks. - ANSI style flags:
Colorsbitmask constants for foreground, background, and text attributes. - Narrow contracts: swap progress or width implementations without changing call sites.
Installation
composer require switon/console
The package ships primitives only; switon/cli wires them for command authoring.
Quick Start
use Switon\Console\Colors; use Switon\Console\ProgressBarInterface; use Switon\Core\Attribute\Autowired; use Switon\Core\ConsoleInterface; final class ImportUsers { #[Autowired] protected ProgressBarInterface $progressBar; #[Autowired] protected ConsoleInterface $console; public function run(array $rows): void { $this->progressBar->start(count($rows)); foreach ($rows as $row) { $this->importRow($row); $this->progressBar->advance(); } $this->progressBar->finish(); $this->console->writeLn( $this->console->colorize('Import complete', Colors::FC_LIGHT_GREEN | Colors::AT_BOLD) ); } }
Docs: https://docs.switon.dev/latest/console
License
MIT.