182 lines
2.9 KiB
PHP
182 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Control;
|
|
|
|
use App\Classes\Control;
|
|
use App\Classes\Parser\Ansi;
|
|
|
|
/**
|
|
* Class Edit Frame handles frame editing
|
|
*
|
|
* @package App\Classes\Control
|
|
*/
|
|
class EditFrame extends Control
|
|
{
|
|
private $x = 1;
|
|
private $y = 1;
|
|
|
|
protected function boot()
|
|
{
|
|
// Clear screen and setup edit.
|
|
$this->so->co->send(CLS.HOME.DOWN.CON);
|
|
|
|
// @todo Add page number + "EDIT" (prob only required for login pages which dont show page num)
|
|
$this->so->co->send($this->fo->raw().$this->so->moveCursor(1,2));
|
|
|
|
$this->updateBaseline();
|
|
}
|
|
|
|
public function handle(string $read)
|
|
{
|
|
static $esc = FALSE;
|
|
static $brace = FALSE;
|
|
static $out = '';
|
|
static $key = '';
|
|
|
|
$out .= $read;
|
|
|
|
switch ($read)
|
|
{
|
|
case 'A':
|
|
if ($esc AND $brace)
|
|
{
|
|
$this->y--;
|
|
if ($this->y < 1) {
|
|
$this->y = 1;
|
|
$out = '';
|
|
}
|
|
|
|
$brace = $esc = FALSE;
|
|
}
|
|
break;
|
|
|
|
case 'B':
|
|
if ($esc AND $brace)
|
|
{
|
|
$this->y++;
|
|
if ($this->y > $this->fo->frame_length()) {
|
|
$this->y = $this->fo->frame_length();
|
|
$out = '';
|
|
}
|
|
|
|
$brace =$esc = FALSE;
|
|
}
|
|
break;
|
|
|
|
case 'C':
|
|
if ($esc AND $brace)
|
|
{
|
|
$this->x++;
|
|
if ($this->x > $this->fo->frame_width()) {
|
|
$this->x = $this->fo->frame_width();
|
|
$out = '';
|
|
}
|
|
|
|
$brace =$esc = FALSE;
|
|
}
|
|
break;
|
|
|
|
case 'D':
|
|
if ($esc AND $brace)
|
|
{
|
|
$this->x--;
|
|
if ($this->x < 1) {
|
|
$this->x = 1;
|
|
$out = '';
|
|
}
|
|
|
|
$brace = $esc = FALSE;
|
|
}
|
|
break;
|
|
|
|
case '[':
|
|
if ($esc)
|
|
$brace = TRUE;
|
|
break;
|
|
|
|
case '1':
|
|
case '2':
|
|
case '3':
|
|
case '4':
|
|
case '5':
|
|
case '6':
|
|
case '7':
|
|
case '8':
|
|
case '9':
|
|
case '0':
|
|
if ($esc AND $brace) {
|
|
$key .= $read;
|
|
} else {
|
|
$this->x++;
|
|
}
|
|
break;
|
|
|
|
case '~':
|
|
if ($esc AND $brace)
|
|
{
|
|
switch ($key)
|
|
{
|
|
// F9 Pressed
|
|
case 20:
|
|
break;
|
|
|
|
// F10 Pressed
|
|
case 21:
|
|
$this->complete = TRUE;
|
|
$this->state = ['action'=>ACTION_GOTO,'mode'=>NULL];
|
|
break;
|
|
}
|
|
|
|
$brace = $esc = FALSE;
|
|
$key = '';
|
|
}
|
|
break;
|
|
|
|
case ESC;
|
|
$esc = TRUE;
|
|
break;
|
|
|
|
case LF: $this->y++; break;
|
|
case CR; $this->x = 1; break;
|
|
|
|
default:
|
|
if ($esc)
|
|
$esc = FALSE;
|
|
|
|
$this->x++;
|
|
}
|
|
|
|
if (! $esc)
|
|
{
|
|
printf(" . SENDING OUT: %s\n",$out);
|
|
$this->so->co->send($out);
|
|
$this->updateBaseline();
|
|
$out = '';
|
|
}
|
|
|
|
printf(" . X:%d,Y:%d,C:%s,ESC:%s\n",
|
|
$this->x,
|
|
$this->y,
|
|
(ord($read) < 32 ? '.' : $read),
|
|
($esc AND $brace) ? 'TRUE' : 'FALSE');
|
|
|
|
return $read;
|
|
}
|
|
|
|
public function updateBaseline()
|
|
{
|
|
$this->so->sendBaseline(
|
|
$this->so->co,
|
|
sprintf('%02.0f:%02.0f]%s'.RESET.'[',
|
|
$this->y,
|
|
$this->x,
|
|
($this->fo->attr($this->x,$this->y) != '-' ? ESC.'['.$this->fo->attr($this->x,$this->y) : '').$this->fo->char($this->x,$this->y),
|
|
)
|
|
);
|
|
}
|
|
|
|
public function process()
|
|
{
|
|
dump(__METHOD__);
|
|
}
|
|
} |