73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Server;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use App\Classes\Server as AbstractServer;
|
|
use App\Models\Mode;
|
|
|
|
class Ansi extends AbstractServer {
|
|
public function __construct(Mode $o)
|
|
{
|
|
define('ESC', chr(27));
|
|
define('CON', ESC.'[?25h'); // Cursor On
|
|
define('COFF', ESC.'[?25l'); // Cursor Off
|
|
define('HOME', ESC.'[0;0f');
|
|
define('LEFT', ESC.'[D'); // Move Cursor
|
|
define('RIGHT', ESC.'[C'); // Move Cursor
|
|
define('DOWN', chr(10)); // Move Cursor
|
|
define('UP', chr(11)); // Move Cursor
|
|
define('CR', chr(13));
|
|
define('LF', chr(10));
|
|
define('CLS', ESC.'[2J');
|
|
define('HASH', '#'); // Enter
|
|
define('STAR', '*'); // Star Entry
|
|
define('SPACE', ' '); // Space
|
|
|
|
// NOTE: This consts are effective output
|
|
define('RED', ESC.'[0;31m'.SPACE);
|
|
define('GREEN', ESC.'[0;32m'.SPACE);
|
|
define('YELLOW', ESC.'[1;33m'.SPACE);
|
|
define('BLUE', ESC.'[0;34m'.SPACE);
|
|
define('MAGENTA', ESC.'[0;35m'.SPACE);
|
|
define('CYAN', ESC.'[0;36m'.SPACE);
|
|
define('WHITE', ESC.'[1;37m'.SPACE);
|
|
define('NEWBG', '');
|
|
|
|
// Raw attributes - used when storing frames.
|
|
define('R_RED', RED);
|
|
define('R_GREEN', GREEN);
|
|
define('R_YELLOW', YELLOW);
|
|
define('R_BLUE', BLUE);
|
|
define('R_MAGENTA', MAGENTA);
|
|
define('R_CYAN', CYAN);
|
|
define('R_WHITE', WHITE);
|
|
//define('FLASH',chr(8));
|
|
|
|
parent::__construct($o);
|
|
}
|
|
|
|
// Abstract function
|
|
public function sendBaseline($client,$text,$reposition=FALSE) {
|
|
$client->send(ESC.'[24;0f'.$text.
|
|
($this->blp > $this->strlenv($text)
|
|
? str_repeat(' ',$this->blp-$this->strlenv($text)).
|
|
($reposition ? ESC.'[24;0f'.str_repeat(RIGHT,$this->strlenv($text)) : '')
|
|
: '')
|
|
);
|
|
|
|
$this->blp = $this->strlenv($text);
|
|
}
|
|
|
|
// Abstract function
|
|
public function strlenv($text):int {
|
|
return strlen($text ? preg_replace('/'.ESC.'\[[0-9;?]+[a-zA-Z]/','',$text) : $text);
|
|
}
|
|
|
|
// Abstract function
|
|
public function testFrame()
|
|
{
|
|
return \App\Classes\Frame\Ansi::testFrame($this);
|
|
}
|
|
} |