Much awesome, very Wow!
* Import native PHP code as callable functions (load) * Include other scripts (include) * Multitude of fixes
This commit is contained in:
77
examples/boxdraw.php
Normal file
77
examples/boxdraw.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?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]);
|
||||
|
||||
}
|
||||
|
||||
];
|
Reference in New Issue
Block a user