Download the PHP package aspectus/terminal without Composer
On this page you can find all versions of the php package aspectus/terminal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package terminal
Terminal device
This is an open-source PHP package providing a small abstraction for the terminal. The idea is to see the terminal as a device, which can perform both input and output. The package relies on Amphp to provide non-blocking handling of the streams and an event dispatcher to handle input.
Furthermore, this package also provides an abstraction for Xterm that is using the terminal device, supporting most of the escape control sequences in the manual (patch #379) as well dispatching events for handling mouse movement.
Usage
Basic Output
Basic Input
For handling the input you can rely on the supplied EventDispatcher.
Device Input Events
The current implementation will distinguish between normal input events (InputEvent) and input that is an escape sequence (EscapeSequenceEvent), so your listeners can attach to the correct one. Unless you need to read some escape sequence that the terminal sends back to you, you probably need to listen to InputEvent.
InputEvent
- the default event that is emitted.
EscapeSequenceEvent
- this is emitted when input starts with an escape sequence
All events hold a reference to the device that dispatched them into the $event->device
property.
For Xterm events
see below.
Event Factory
The device by default has a minimal implementation for creating new events. You
can supply your own by implementing the EventFactoryInterface
.
Xterm abstraction
The package comes with an abstraction for Xterm that provides named methods to escape sequences in
a fluent interface. Xterm
will buffer every call and write it to the device when flush()
is called
or return it as a string
when getBuffered()
is called.
Xterm Input events
Using the Xterm abstraction will add a different EventFactory
implementation which will emit some
additional events when they are received.
SpecialKeyEvent
is emitted when function or arrow keys are pressed. The data
property of
the event is mapped to a generic format, indicating function keys like <F2>
and arrow keys
like <LEFT>
, <RIGHT>
.
MouseInputEvent
- is emitted when mouse tracking is enabled and provides properties like x
and
y
as well as methods for the buttons (like button1()
) to get information about which buttons
were pressed.
MouseFocusEvent
- is emitted when mouse tracking and focus tracking have been enabled and provides
a way to attach to an event that will trigger when the window loses focus or gains it again.
More usage examples
More usage examples can be found in the examples/
directory.
Contribute
Everyone is welcome to contribute, please see CONTRIBUTE.md
for more information.
Licence
MIT