diff --git a/SCRIPTING.md b/SCRIPTING.md index 5787927..4f89855 100644 --- a/SCRIPTING.md +++ b/SCRIPTING.md @@ -46,6 +46,29 @@ Removes all annontations in one go. clearannotate +### cursor - Cursor display control + +Controls cursor visibility and rendering style. Use `cursor show` and +`cursor hide` to toggle the visiblity of the cursor. + + cursor show + cursor hide + +You can configure the cursor blink rate, f.ex. setting it to 500ms with +`cursor blink 500`, or change its style using `cursor style` followed by +the desired style. + + cursor blink + cursor style {none|block|under|left} + +To push (save) the current cursor position, use `cursor push`. Move +wherever and do what you need, followed by `cursor pop`. Don't forget +to pop if you push! + + cursor push + cursor pop + + ### delay - Wait for time to pass Only useful if you have `set fps` to a non-zero value, this command will diff --git a/examples/cursorblink.ftm b/examples/cursorblink.ftm new file mode 100644 index 0000000..01247ad --- /dev/null +++ b/examples/cursorblink.ftm @@ -0,0 +1,27 @@ +set terminal 60x10 +set colors 16 +set typedelay 250 +set fps 30 + +cursor blink 500 +cursor show + +delay 2000 + +type "We have a cursor!" + +delay 2000 + +type + +cursor style solid +type "We can even change the style..." + +cursor blink 0 +type "And we can make it blink not at all..." +delay 1000 +cursor blink 100 +type " or like its life depended on it!" +delay 2000 + + diff --git a/examples/cursorblink.gif b/examples/cursorblink.gif new file mode 100644 index 0000000..79ee33c Binary files /dev/null and b/examples/cursorblink.gif differ diff --git a/examples/cursorblink.mp4 b/examples/cursorblink.mp4 new file mode 100644 index 0000000..9ba0cb9 Binary files /dev/null and b/examples/cursorblink.mp4 differ diff --git a/examples/keys.ftm b/examples/keys.ftm index d0a27e2..d516a56 100644 --- a/examples/keys.ftm +++ b/examples/keys.ftm @@ -1,5 +1,6 @@ set terminal 80x25 +cursor style solid showkeys ctrl alt shift F4 up up down down left right left right B A -savepng keys.png \ No newline at end of file +savepng keys.png diff --git a/examples/keys.png b/examples/keys.png index 03fa7c8..684a1a3 100644 Binary files a/examples/keys.png and b/examples/keys.png differ diff --git a/src/FakeTerminal.php b/src/FakeTerminal.php index 2d005e3..bee41ce 100644 --- a/src/FakeTerminal.php +++ b/src/FakeTerminal.php @@ -48,6 +48,10 @@ class FakeTerminal private $writtenFiles = []; + private $cursorBlinkRate = 0; + + private $cursorStyle = GdRenderer::CURSOR_BLOCK; + public function __construct() { $this->renderer = new GdRenderer(); @@ -255,6 +259,30 @@ class FakeTerminal $this->renderer->setKeyOverlay($args); break; + case 'cursor': + $op = array_shift($args); + switch ($op) { + case 'push': + // push cursor position + break; + case 'pop': + // pop cursor position + break; + case 'blink': + // set cursorBlinkRate + $this->cursorBlinkRate = intval(array_shift($args)); + break; + case 'style': + $style = array_shift($args); + switch ($style) { + case 'none': $this->cursorStyle = GdRenderer::CURSOR_NONE; break; + case 'block': $this->cursorStyle = GdRenderer::CURSOR_BLOCK; break; + case 'solid': $this->cursorStyle = GdRenderer::CURSOR_SOLID; break; + } + break; + } + break; + case 'clear': $what = array_shift($args); $tw = $this->term->getColumns(); @@ -333,6 +361,20 @@ class FakeTerminal public function writeFrame($name=null) { + $ft = ($this->frame * $this->frameDuration); + + if ($this->cursorBlinkRate > 0) { + //printf("\nft=%.1f r=%.1f\n", $ft, $this->cursorBlinkRate); + $visible = (floor($ft / $this->cursorBlinkRate) % 2) == 0; + if ($visible) { + $this->renderer->setCursorStyle($this->cursorStyle); + } else { + $this->renderer->setCursorStyle(GdRenderer::CURSOR_NONE); + } + } else { + $this->renderer->setCursorStyle($this->cursorStyle); + } + $this->renderer->render($this->term); if ($name) {