Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Chewie

joetannenbaum/chewie image

Chewie stats

Downloads
220
Stars
23
Open Issues
0
Forks
1

View on GitHub →

Chewie

Chewie is a package that helps you build text-based user interfaces (TUIs) with Laravel Prompts. It helps to reduce some of the boilerplate code and adds some helpers for alignment, animation, and more.

[!WARNING] This package is currently in active development. The API is subject to change. Documentation will also improve over time.

Installation

composer require joetannenbaum/chewie

Registering Renderers

use App\Renderers\DemoRenderer;
use Chewie\Concerns\RegistersRenderers;
 
class Demo extends Prompt
{
use RegistersRenderers;
 
public function __construct()
{
$this->registerRenderer(DemoRenderer::class);
}
}

You can also tell Chewie that all of your renderers live within a specific namespace, then Chewie will resolve your renderers automatically.

For example, if you call the following in your AppServiceProvider:

use Chewie\Renderer;
 
class AppServiceProvider
{
public function boot()
{
Renderer::setNamespace('App\\Renderers');
}
}

Then you can simply do the following when registering renderers. Chewie assumes your renderer class will be your app class + Renderer:

use Chewie\Concerns\RegistersRenderers;
 
class Demo extends Prompt
{
use RegistersRenderers;
 
public function __construct()
{
// Will register App\Renderers\DemoRenderer
$this->registerRenderer();
}
}

Drawing Art

You can easily print ASCII art from a file out to the terminal in your renderer:

use Chewie\Concerns\DrawsArt;
 
class DemoRenderer extends Renderer
{
use DrawsArt;
 
public function __invoke(Demo $prompt): string
{
// Returns a collection of the lines from your art,
// assumes a ".txt" extension
$this->artLines(storage_path('my-art/horse'))
->each($this->line(...));
 
return $this;
}
}

You can also tell Chewie where all of your art files live:

use Chewie\Art;
 
class AppServiceProvider
{
public function boot()
{
Art::setDirectory(storage_path('my-art'));
}
}

which allows you to simplify the artLines call to:

use Chewie\Concerns\DrawsArt;
 
class DemoRenderer extends Renderer
{
use DrawsArt;
 
public function __invoke(Demo $prompt): string
{
$this->artLines('horse')->each($this->line(...));
 
return $this;
}
}

Alignment

Chewie comes with methods that help align content within the terminal.

use Chewie\Concerns\Aligns;
 
class DemoRenderer extends Renderer
{
use Aligns;
 
public function __invoke(Demo $prompt): string
{
$width = $prompt->terminal()->cols();
$height = $prompt->terminal()->lines();
 
$lines = [
'Hello!',
'My name is Joe',
];
 
$this->centerHorizontally($lines, $width)
->each($this->line(...));
 
$this->centerVertically($lines, $height)
->each($this->line(...));
 
$this->center($lines, $width, $height)
->each($this->line(...));
 
$this->line($this->spaceBetween($width, ...$lines));
 
$this->pinToBottom($height, function() {
$this->newLine();
$this->line('This is pinned to the bottom!');
});
 
return $this;
}
}
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Joetannenbaum Chewie Related Articles

PestPHP Intellisense in Laravel VS Code Extension v1.7.0 image

PestPHP Intellisense in Laravel VS Code Extension v1.7.0

Read article
Laravel Prompts v0.3.15 Adds Streaming, Tasks, Autocomplete, and More image

Laravel Prompts v0.3.15 Adds Streaming, Tasks, Autocomplete, and More

Read article
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech