switon/console

Reusable terminal primitives including progress bars, width detection, and ANSI styling for Switon Framework

Maintainers

Package info

github.com/switon-php/console

Documentation

pkg:composer/switon/console

Statistics

Installs: 38

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 02:01:44 UTC


README

CI PHP 8.3+

Reusable terminal primitives for progress bars, terminal width detection, and ANSI styling in Switon Framework.

Highlights

  • Progress bars: ProgressBarInterface with elapsed and remaining time rendering.
  • Width detection: TerminalWidthDetectorInterface with Unix and Windows fallbacks.
  • ANSI style flags: Colors bitmask 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.