2018-12-07 05:19:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes\Server;
|
|
|
|
|
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));
|
2019-07-12 03:42:01 +00:00
|
|
|
define('BS', chr(8));
|
2018-12-08 22:43:18 +00:00
|
|
|
define('CLS', ESC.'[2J');
|
|
|
|
define('HASH', '#'); // Enter
|
|
|
|
define('STAR', '*'); // Star Entry
|
2019-07-14 12:43:31 +00:00
|
|
|
define('SPACE', ' '); // Space (for compatibility with Videotex)
|
2018-12-08 22:43:18 +00:00
|
|
|
|
|
|
|
// NOTE: This consts are effective output
|
2019-07-31 12:19:41 +00:00
|
|
|
define('RESET', ESC.'[0;39;49m');
|
2019-07-14 12:43:31 +00:00
|
|
|
define('RED', ESC.'[0;31m');
|
|
|
|
define('GREEN', ESC.'[0;32m');
|
|
|
|
define('YELLOW', ESC.'[1;33m');
|
|
|
|
define('BLUE', ESC.'[0;34m');
|
|
|
|
define('MAGENTA', ESC.'[0;35m');
|
|
|
|
define('CYAN', ESC.'[0;36m');
|
|
|
|
define('WHITE', ESC.'[1;37m');
|
2018-12-08 22:43:18 +00:00
|
|
|
define('NEWBG', '');
|
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
// Compatibility attributes (to Videotex).
|
|
|
|
define('R_RED', RED.SPACE);
|
|
|
|
define('R_GREEN', GREEN.SPACE);
|
|
|
|
define('R_YELLOW', YELLOW.SPACE);
|
|
|
|
define('R_BLUE', BLUE.SPACE);
|
|
|
|
define('R_MAGENTA', MAGENTA.SPACE);
|
|
|
|
define('R_CYAN', CYAN.SPACE);
|
|
|
|
define('R_WHITE', WHITE.SPACE);
|
2018-12-08 22:43:18 +00:00
|
|
|
//define('FLASH',chr(8));
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
// Keyboard presses
|
|
|
|
// @todo Check where these are used vs the keys defined above?
|
|
|
|
define('KEY_DELETE', chr(8));
|
|
|
|
define('KEY_LEFT', chr(136));
|
|
|
|
define('KEY_RIGHT', chr(137));
|
|
|
|
define('KEY_DOWN', chr(138));
|
|
|
|
define('KEY_UP', chr(139));
|
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
parent::__construct($o);
|
|
|
|
}
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
function moveCursor($x,$y) {
|
|
|
|
printf(". Move cursor %s,%s\n",$x,$y);
|
2018-12-13 13:02:42 +00:00
|
|
|
return ESC.'['.$y.';'.$x.'f';
|
|
|
|
}
|
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
// Abstract function
|
|
|
|
public function sendBaseline($client,$text,$reposition=FALSE) {
|
2019-07-31 12:19:41 +00:00
|
|
|
$client->send(CSAVE.ESC.'[24;0f'.RESET.$text.
|
2019-07-12 03:42:01 +00:00
|
|
|
($this->blp > $this->fo->strlenv($text)
|
|
|
|
? str_repeat(' ',$this->blp-$this->fo->strlenv($text)).
|
|
|
|
($reposition ? ESC.'[24;0f'.str_repeat(RIGHT,$this->fo->strlenv($text)) : CRESTORE)
|
2018-12-25 01:48:57 +00:00
|
|
|
: ($reposition ? '' : CRESTORE))
|
2018-12-08 22:43:18 +00:00
|
|
|
);
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
$this->blp = $this->fo->strlenv($text);
|
2018-12-25 01:48:57 +00:00
|
|
|
$this->baseline = $text;
|
2018-12-08 22:43:18 +00:00
|
|
|
}
|
2018-12-07 05:19:51 +00:00
|
|
|
}
|