2018-12-07 05:19:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes\Server;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
use App\Classes\Server as AbstractServer;
|
|
|
|
use App\Models\Mode;
|
|
|
|
|
2018-12-07 05:19:51 +00:00
|
|
|
class Ansi extends AbstractServer {
|
2018-12-08 22:43:18 +00:00
|
|
|
public function __construct(Mode $o)
|
|
|
|
{
|
|
|
|
define('ESC', chr(27));
|
|
|
|
define('CON', ESC.'[?25h'); // Cursor On
|
|
|
|
define('COFF', ESC.'[?25l'); // Cursor Off
|
2018-12-25 01:48:57 +00:00
|
|
|
define('CSAVE', ESC.'[s'); // Save Cursor position
|
|
|
|
define('CRESTORE',ESC.'[u'); // Restore to saved position
|
2018-12-08 22:43:18 +00:00
|
|
|
define('HOME', ESC.'[0;0f');
|
|
|
|
define('LEFT', ESC.'[D'); // Move Cursor
|
|
|
|
define('RIGHT', ESC.'[C'); // Move Cursor
|
2018-12-13 13:02:42 +00:00
|
|
|
define('DOWN', ESC.'[B'); // Move Cursor
|
|
|
|
define('UP', ESC.'[A'); // Move Cursor
|
2018-12-08 22:43:18 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:02:42 +00:00
|
|
|
function outputPosition($x,$y) {
|
|
|
|
return ESC.'['.$y.';'.$x.'f';
|
|
|
|
}
|
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
// Abstract function
|
|
|
|
public function sendBaseline($client,$text,$reposition=FALSE) {
|
2018-12-25 01:48:57 +00:00
|
|
|
$client->send(CSAVE.ESC.'[24;0f'.$text.
|
2018-12-08 22:43:18 +00:00
|
|
|
($this->blp > $this->strlenv($text)
|
|
|
|
? str_repeat(' ',$this->blp-$this->strlenv($text)).
|
2018-12-25 01:48:57 +00:00
|
|
|
($reposition ? ESC.'[24;0f'.str_repeat(RIGHT,$this->strlenv($text)) : CRESTORE)
|
|
|
|
: ($reposition ? '' : CRESTORE))
|
2018-12-08 22:43:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->blp = $this->strlenv($text);
|
2018-12-25 01:48:57 +00:00
|
|
|
$this->baseline = $text;
|
2018-12-08 22:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Abstract function
|
|
|
|
public function strlenv($text):int {
|
|
|
|
return strlen($text ? preg_replace('/'.ESC.'\[[0-9;?]+[a-zA-Z]/','',$text) : $text);
|
|
|
|
}
|
2018-12-07 05:19:51 +00:00
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
// Abstract function
|
|
|
|
public function testFrame()
|
|
|
|
{
|
|
|
|
return \App\Classes\Frame\Ansi::testFrame($this);
|
|
|
|
}
|
2018-12-07 05:19:51 +00:00
|
|
|
}
|