php-faketerm/examples/boxdraw.php

78 lines
2.2 KiB
PHP
Raw Normal View History

<?php return [
/**
* Draw a box frame
*/
'drawbox' => function ($term, $column, $line, $width, $height) {
fprintf(STDERR, "drawbox: {%d,%d}+[%d,%d]\n", $column, $line, $width, $height);
$oldpos = $term->getCursorPosition();
$term->setCursor($line, $column);
$term->write("\u{250c}" . str_repeat("\u{2500}", $width - 2) . "\u{2510}");
$term->setCursor($line + $height, $column);
$term->write("\u{2514}" . str_repeat("\u{2500}", $width - 2) . "\u{2518}");
for ($l = $line + 1; $l < $line + $height; $l++) {
$term->setCursor($l, $column);
$term->write("\u{2502}");
$term->setCursor($l, $column + $width - 1);
$term->write("\u{2502}");
}
$term->setCursor($oldpos[0], $oldpos[1]);
},
/**
* Draw a box and fill it
*/
'drawfilledbox' => function ($term, $column, $line, $width, $height) {
fprintf(STDERR, "drawbox: {%d,%d}+[%d,%d]\n", $column, $line, $width, $height);
$oldpos = $term->getCursorPosition();
$term->setCursor($line, $column);
$term->write("\u{250c}" . str_repeat("\u{2500}", $width - 2) . "\u{2510}");
$term->setCursor($line + $height, $column);
$term->write("\u{2514}" . str_repeat("\u{2500}", $width - 2) . "\u{2518}");
for ($l = $line + 1; $l < $line + $height; $l++) {
$term->setCursor($l, $column);
$term->write("\u{2502}" . str_repeat(" ", $width - 2) . "\u{2502}");
}
$term->setCursor($oldpos[0], $oldpos[1]);
},
/**
* Draw a horizontal line
*/
'drawhline' => function ($term, $line, $fromCol, $toCol) {
$oldpos = $term->getCursorPosition();
$term->setCursor($line, $fromCol);
$term->write(str_repeat("\u{2500}", ($toCol-$fromCol)));
$term->setCursor($oldpos[0], $oldpos[1]);
},
/**
* Draw a vertical line
*/
'drawvline' => function ($term, $column, $fromLine, $toLine) {
$oldpos = $term->getCursorPosition();
for ($l = $fromLine; $l <= $toLine; $l++) {
$term->setCursor($l, $column);
$term->write("\u{2502}");
}
$term->setCursor($oldpos[0], $oldpos[1]);
}
];