PHP Classes

CLI Magic: Get input and display console output using tput

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 166 All time: 8,896 This week: 455Up
Version License PHP version Categories
cli-magic 1.0BSD License5.4PHP 5, Unix, Console
Description 

Author

This class can get input and display console output using the tput amd stty commands.

It can perform several types of operations display information on a console using the tput and stty commands to provide a terminal type independent solution.

Currently it can clear the screen or a given area rectangle, show or hide the cursor, place the cursor in a given position, set the foreground and background colors, drawing borders with titles,

The class can also get input and information from the terminal console like checking of the user pressed a key, getting characters that the user typed, the width and height of the terminal window, call a function when the the window size is changed.

Picture of David Tamas
  Performance   Level  
Name: David Tamas <contact>
Classes: 5 packages by
Country: Hungary Hungary
Age: 37
All time rank: 310928 in Hungary Hungary
Week rank: 187 Up3 in Hungary Hungary Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

<?php

require_once 'cli.php';

//standard cli samples
gCli()->showCursor(false);
gCli()->setbgColor('black');
gCli()->setColor('white');
gCli()->clearScrean();

gCli()->gotoXY(5,1);
echo
'Hello';
gCli()->gotoXY(5,2);
echo
gCli()->textParser('%red%Red text%rst%');

gCli()->thickBorder(20, 2, 20, 10, 'Hello window');

gCli()->gotoXY(5,3);
echo
'Press any key';
gCli()->gotoXY(5,4);
echo
'to continue';



while (
true) {
   
gCli()->gotoXY(5,5);
    echo
gCli()->textParser('%spinner% [%knightrider%]');
   
$c = gCli()->isKeypressed();
   
    if (
$c) {
        break;
    }
}


//Windowing system
gCli()->clearScrean();
gCli()->gotoXY(1, 1);

$infoWindow = new gWindow(1, 1, 80, 14, 'G-Lex\'s CLI magics');
$infoWindow->draw();
$statusWindow = new gWindow(81, 1, 50, 14, 'System status');
$statusWindow->draw();


$infoWindow->addLine('Version: %green;bold% 1.0' );
$infoWindow->addLine(' ');
$infoWindow->addLine('You can hold a lot of texts within this area');
$infoWindow->addLine('%green%Press%rst% %red%x%rst% to exit');

$statusSystem = $statusWindow->addStatusSignal('%white;bold%System%rst%');
$statusDriver = $statusWindow->addStatusSignal('Camera driver');
$statusCamera = $statusWindow->addStatusSignal('Camera status', '%red;faint%offline%rst%');
$statusConnection = $statusWindow->addStatusSignal('Camera connection');
$statusCameraWarming = $statusWindow->addStatusSignal('Camera warming');
$statusAlarm = $statusWindow->addStatusSignal('Alarm');
$statusMotion = $statusWindow->addStatusSignal('Motion');
$statusKeyframes = $statusWindow->addStatusSignal('Keyframes');
$statusAutopan = $statusWindow->addStatusSignal('AutoPan');
$statusPanPos = $statusWindow->addStatusSignal('PanPosition');
$statusSystem->setSignal('%yellow;bold%init%rst%', true);

 
$statusDriver->setSignal(true, true);

$statusConnection->setSignal(true, true);
$statusCamera->setSignal('%yellow;bold%online%rst%', true);


$statusPanPos->setSignal('0x0', true);
$statusCamera->setSignal('%yellow;bold%ready%rst%', true);


$statusCamera->setSignal('%yellow;bold%centering%rst%', true);
$statusCameraWarming->setSignal('%knightrider%');

$warmupEnd = time() + 5;
while (
$warmupEnd > time()) {
   
$statusCameraWarming->setSignal('%knightrider%');
   
usleep(10000);
}
$statusCameraWarming->setSignal('%green;bold%ready%rst%');
$statusCamera->setSignal('%green;bold%online%rst%', true);
$statusSystem->setSignal('%green;bold%ARMED%rst%', true);
$statusAlarm->setSignal('%green;bold%no%rst%', true);
$statusMotion->setSignal('%green;bold%no%rst%', true);

 while (
true) {
   
$c = gCli()->isKeypressed();
    if (
$c) {
       
$infoWindow->addLine(dateStamp().'KeyCode: '.ord($c).' | '. dechex(ord($c)));
    }
   
    if (
$c == 'x') {
        break;
    }
   
   
}
 
gCli()->clearScrean();
gCli()->gotoXY(1, 1);
gCli()->showCursor(true);


Screenshots (1)  
  • screenshot.jpg
  Files folder image Files (3)  
File Role Description
Plain text file cli.php Class main classes
Accessible without login Plain text file example.php Example example

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 Download Rankings  
 0%
Total:166
This week:0
All time:8,896
This week:455Up