Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Terminal Laravel Package

php-school/terminal

php-school/terminal is a PHP library for building interactive terminal apps. It provides input/output helpers, ANSI styling, cursor control, and terminal state management, making it easy to create rich CLI UIs with prompts, menus, and formatted output.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer (composer require php-school/terminal). Its primary use case is detecting terminal environment properties to conditionally format output. The first thing you’ll reach for is Terminal::isatty() to verify whether output goes to an actual terminal (vs. a pipe or file), and Terminal::getSize() to get width/height for responsive layout. Look at php-school/terminal’s TerminalInterface—it defines a clean, minimal API with no heavy dependencies. Since the last release was in 2019, assume it’s stable but lightly maintained; ideal for foundational terminal introspection where full frameworks (like Symfony Console) would be overkill.

Implementation Patterns

  • Conditional Styling: Use isatty() to enable colors only when supported (if ($terminal->isatty(STDOUT)) { $output->write('<fg=yellow>…</>'); }), avoiding ANSI codes breaking log files or CI outputs.
  • Responsive Layouts: Pair getSize() with width()/height() to adjust table columns or progress bar width ($width = $terminal->getSize()->getWidth(); $bar->setMaxWidth($width - 10)).
  • Fallback UIs: Detect capabilities via getCapabilities()—e.g., disable interactive prompts if supportsInteractive() returns false (useful for CI, cron jobs, or non-TTY CI runners).
  • Integration: Often used in smaller CLIs or internal tools where extracting console abstraction isn’t justified—e.g., in custom scaffolding tools or monorepo utilities where you want php mytool.php | grep foo to work without garbled output.

Gotchas and Tips

  • Windows Compatibility: Works on Windows 10+ (with ANSI support enabled), but older systems (pre– anniversary update) may fall back to limited mode; always test in actual CI environments (e.g., GitHub Actions windows-latest).
  • Piped Input Detection: isatty(STDIN) is critical for tools that behave differently in pipelines (php mytool.php | grep bar). Never assume TTY → always check stdin/output separately.
  • No Dependency Injection Trap: Because it’s stateful (detects environment once), avoid injecting terminal instance in long-running processes (e.g., Swoole, ReactPHP apps)—re-instantiate on context change or mock in tests.
  • Mocking for Tests: In unit tests, use Terminal::mock() or a test-double that returns fixed dimensions/capabilities—don’t rely on actual terminal environment.
  • Staleness Risk: Since the library hasn’t been updated since 2019, prefer it only for detection logic—not terminal control (e.g., cursor manipulation). For complex交互 (menus, progress bars), layer on top with php-school/terminal as the detection layer, but let a more active library (like symfony/console) handle rendering.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport