Skip to content

Commit

Permalink
Expand terminal attributes example
Browse files Browse the repository at this point in the history
  • Loading branch information
thgs committed Jun 12, 2023
1 parent b29d2f4 commit 09ec970
Showing 1 changed file with 63 additions and 22 deletions.
85 changes: 63 additions & 22 deletions examples/terminal-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,74 @@ function () use ($xterm) {
}
);


$xterm
// boot
->setPrivateModeSaveCursorAndEnterAlternateScreenBuffer()
->hideCursor()
// set colors
->bgBlue()
->brightYellow()
->eraseAll()
// Primary DA
->moveCursorTo(2, 2)
->write("Terminal ID ..... : $primary->terminalId")
->moveCursorTo(3, 2)
->write("Capabilities .... : " . implode(' ', $primary->capabilities))
// Secondary DA
->moveCursorTo(6, 2)
->write("Type ............ : $secondary->type")
->moveCursorTo(8, 2)
->write("Version ......... : $secondary->version")
->moveCursorTo(10, 2)
->write("Cartridge Reg. .. : $secondary->cartridgeRegistration")
//
->moveCursorTo(15, 10)
->blink()
->write("Press any key to exit")
->normal()
->flush()
;

EventLoop::repeat(1, function () use ($xterm, $primary, $secondary) {
$xterm
// set colors
->bgBlue()
->brightYellow()
->eraseAll();

$view = [
// Primary
'Terminal ID' => $primary->terminalId,
'Capabilities' => "\n\t" . implode(
" ",
// only first letter for when its running on xterm
array_map(fn ($capability) => substr($capability, 0, 1), $primary->capabilities)
),

// Secondary
'Type' => $secondary->type,
'Version' => $secondary->version,
'Cartridge Reg' => $secondary->cartridgeRegistration,

// Sizes
'TextArea Position' => implode(' x ', $xterm->reportTextAreaPosition()),
'TextArea Size (px)' => implode(' x ', $xterm->reportTextAreaSizePixels()),
'TextArea Size (char)' => implode(' x ', $xterm->reportTextAreaSizeCharacters()),
'Window Size (px)' => implode(' x ', $xterm->reportWindowSizePixels()),
'Screen Size (px)' => implode(' x ', $xterm->reportScreenSizePixels()),
'Screen Size (char)' => implode(' x ', $xterm->reportScreenSizeCharacters()),
'Character size (px)' => implode(' x ', $xterm->reportCharacterSizePixels()),
];

$lines = [
[2,2],
[3,2],
[6,2],
[8,2],
[10,2],
[2, 40],
[3, 40],
[4, 40],
[6, 40],
[8, 40],
[9, 40],
[11, 40],
];

$i = 0;
foreach ($view as $title => $data) {
$element = str_pad($title . ' ', 25, '.') . ' : ' . $data;
$xterm
->moveCursorTo(...$lines[$i++])
->write($element);
}
//
$xterm
->moveCursorTo(15, 10)
->blink()
->write("Press any key to exit or resize/move your screen")
->normal()
->flush()
;
});

EventLoop::run();

0 comments on commit 09ec970

Please sign in to comment.