PHP Classes

How to Use a PHP Console Drawing Class to Display Text Messages in Decorated Boxes Using the Package PHP Box Designer: Draw text boxes to display in a terminal console

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-07-15 (14 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
php-box-designer 1.0Custom (specified...8Graphics, Console, PHP 8
Description 

Author

This package can draw text boxes to display in a terminal console.

It provides a box class that can create boxes that can have specific width and height in terms of the number of characters that the boxes will occupy in a terminal console where the boxes are displayed.

The box class can output ASCII or UTF8 characters to display the boxes.

It can display a given text inside a box and the style of the border can be changed to use different box decoration styles.

Picture of Lucas Marques Dutra
  Performance   Level  
Name: Lucas Marques Dutra <contact>
Classes: 2 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 2x

Instructions

Example

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
BoxDesigner\CustomBorder;
use
BoxDesigner\PreBuilt\DarkerBorder;
use
BoxDesigner\PreBuilt\DoubleLineBorder;
use
BoxDesigner\Box;
use
BoxDesigner\SideLessThanOneException;

$doubleBorder = new DoubleLineBorder();
$darkerBorder = new DarkerBorder();

$output_filtered = fn(string $input): string => htmlspecialchars($input, ENT_QUOTES, 'UTF-8') . PHP_EOL;

try {
   
$box = new Box(1, 1);
    echo
$output_filtered($box->draw());


   
$box = new Box(1, 1);
   
$single = $box->draw();

   
$box = new Box(3, 3);
   
$box->setContentInsideBox($single);
   
$double = $box->draw($doubleBorder);

   
$box = new Box(5, 5);
   
$box->setContentInsideBox($double);
    echo
$output_filtered($box->draw($darkerBorder));

   
$customBorder = new CustomBorder('*', '*', '*', '*', '-', '|');
   
$box = new Box(8, 3);
    echo
$output_filtered($box->draw($customBorder));

   
$box = new Box(10, 1);
    echo
$output_filtered($box->draw());

   
$box = new Box(8, 3);
   
$box->setContentInsideBox('John Doe Lorem Ipsum Dolor Sit Amet');
    echo
$output_filtered($box->draw());

   
$box = new Box(16, 2);
   
$box->setContentInsideBox("by terremoth\nand friends");
    echo
$output_filtered($box->draw());

   
$box = new Box(2, 2);
   
$draw = $output_filtered($box->draw());

   
$box = new Box(4, 4);
   
$box->setContentInsideBox($draw);
   
$output_filtered($box->draw($doubleBorder));

    echo
$output_filtered($box->draw($doubleBorder));
} catch (
SideLessThanOneException $e) {
    echo
$output_filtered($e->getMessage());
}
//end try


Details

PHP Box Designer

Boxes. There are Boxes. Everywhere.

Simple app that draws boxes using chars with or without text content inside. This repo main idea is to demonstrate the highest state of the art a PHP repo can be.

codecov Test Coverage Psalm type coverage Psalm level Test Run Status Codacy Badge Maintainability OpenSSF Scorecard License

See demos/drawing.php for examples.

Installation

composer require terremoth/php-box-designer

What it looks like?

image


  Files folder image Files (27)  
File Role Description
Files folder image.github (1 directory)
Files folder imagedemos (1 file)
Files folder imagesrc (1 directory)
Files folder imagetests (1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (27)  /  .github  
File Role Description
Files folder imageworkflows (2 files)

  Files folder image Files (27)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file scorecard.yml Data Auxiliary data
  Accessible without login Plain text file workflow.yml Data Auxiliary data

  Files folder image Files (27)  /  demos  
File Role Description
  Accessible without login Plain text file drawing.php Example Example script

  Files folder image Files (27)  /  src  
File Role Description
Files folder imageBoxDesigner (4 files, 1 directory)

  Files folder image Files (27)  /  src  /  BoxDesigner  
File Role Description
Files folder imagePreBuilt (3 files)
  Plain text file BorderInterface.php Class Class source
  Plain text file Box.php Class Class source
  Plain text file CustomBorder.php Class Class source
  Plain text file SideLessThanOneException.php Class Class source

  Files folder image Files (27)  /  src  /  BoxDesigner  /  PreBuilt  
File Role Description
  Plain text file DarkerBorder.php Class Class source
  Plain text file DoubleLineBorder.php Class Class source
  Plain text file SingleLineBorder.php Class Class source

  Files folder image Files (27)  /  tests  
File Role Description
Files folder imageBoxDesigner (4 files, 1 directory)

  Files folder image Files (27)  /  tests  /  BoxDesigner  
File Role Description
Files folder imagePreBuilt (4 files)
  Plain text file BorderInterfaceTest.php Class Class source
  Plain text file CustomBorderTest.php Class Class source
  Plain text file SideLessThanOneExceptionTest.php Class Class source
  Plain text file SingleBorderWithContentTest.php Class Class source

  Files folder image Files (27)  /  tests  /  BoxDesigner  /  PreBuilt  
File Role Description
  Plain text file DarkerBorderTest.php Class Class source
  Plain text file DoubleLineBorderTest.php Class Class source
  Plain text file SingleBorderBoxTest.php Class Class source
  Plain text file SingleLineBorderTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0