Added blinking cursor and settings
* The cursor can now be controlled with the cursor command, documented in examples and in scripting docs.
This commit is contained in:
parent
e23559fd72
commit
0b3f3e38d1
23
SCRIPTING.md
23
SCRIPTING.md
@ -46,6 +46,29 @@ Removes all annontations in one go.
|
|||||||
|
|
||||||
clearannotate
|
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 <rate>
|
||||||
|
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
|
### delay - Wait for time to pass
|
||||||
|
|
||||||
Only useful if you have `set fps` to a non-zero value, this command will
|
Only useful if you have `set fps` to a non-zero value, this command will
|
||||||
|
27
examples/cursorblink.ftm
Normal file
27
examples/cursorblink.ftm
Normal file
@ -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 <return>
|
||||||
|
|
||||||
|
cursor style solid
|
||||||
|
type "We can even change the style..." <return>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
BIN
examples/cursorblink.gif
Normal file
BIN
examples/cursorblink.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 236 KiB |
BIN
examples/cursorblink.mp4
Normal file
BIN
examples/cursorblink.mp4
Normal file
Binary file not shown.
@ -1,4 +1,5 @@
|
|||||||
set terminal 80x25
|
set terminal 80x25
|
||||||
|
cursor style solid
|
||||||
|
|
||||||
showkeys ctrl alt shift F4 up up down down left right left right B A
|
showkeys ctrl alt shift F4 up up down down left right left right B A
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
@ -48,6 +48,10 @@ class FakeTerminal
|
|||||||
|
|
||||||
private $writtenFiles = [];
|
private $writtenFiles = [];
|
||||||
|
|
||||||
|
private $cursorBlinkRate = 0;
|
||||||
|
|
||||||
|
private $cursorStyle = GdRenderer::CURSOR_BLOCK;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->renderer = new GdRenderer();
|
$this->renderer = new GdRenderer();
|
||||||
@ -255,6 +259,30 @@ class FakeTerminal
|
|||||||
$this->renderer->setKeyOverlay($args);
|
$this->renderer->setKeyOverlay($args);
|
||||||
break;
|
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':
|
case 'clear':
|
||||||
$what = array_shift($args);
|
$what = array_shift($args);
|
||||||
$tw = $this->term->getColumns();
|
$tw = $this->term->getColumns();
|
||||||
@ -333,6 +361,20 @@ class FakeTerminal
|
|||||||
|
|
||||||
public function writeFrame($name=null)
|
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);
|
$this->renderer->render($this->term);
|
||||||
|
|
||||||
if ($name) {
|
if ($name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user