{"id":44741003,"url":"https://github.com/Aspectus-PHP/terminal","last_synced_at":"2026-02-28T09:01:01.173Z","repository":{"id":172294054,"uuid":"648955753","full_name":"Aspectus-PHP/terminal","owner":"Aspectus-PHP","description":"Lightweight terminal device abstraction with support for Xterm control sequences","archived":false,"fork":false,"pushed_at":"2025-01-27T23:05:57.000Z","size":65,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-16T02:14:43.785Z","etag":null,"topics":["amphp","ansi","php","terminal","vt100","xterm"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aspectus-PHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-06-03T10:18:50.000Z","updated_at":"2025-03-02T14:32:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"6a226d84-6b93-4903-8f26-0daa7864c7f1","html_url":"https://github.com/Aspectus-PHP/terminal","commit_stats":null,"previous_names":["aspectus-php/terminal"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/Aspectus-PHP/terminal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aspectus-PHP%2Fterminal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aspectus-PHP%2Fterminal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aspectus-PHP%2Fterminal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aspectus-PHP%2Fterminal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aspectus-PHP","download_url":"https://codeload.github.com/Aspectus-PHP/terminal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aspectus-PHP%2Fterminal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29929111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"online","status_checked_at":"2026-02-28T02:00:07.010Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amphp","ansi","php","terminal","vt100","xterm"],"created_at":"2026-02-15T21:00:18.567Z","updated_at":"2026-02-28T09:01:01.157Z","avatar_url":"https://github.com/Aspectus-PHP.png","language":"PHP","funding_links":[],"categories":["Projects using amphp"],"sub_categories":["Tunnel"],"readme":"## Terminal device\n\nThis is an open-source PHP package providing a small abstraction for the terminal. The idea is to\nsee the terminal as a device, which can perform both input and output. The package\nrelies on Amphp to provide non-blocking handling of the streams and an event dispatcher \nto handle input.\n\nFurthermore, this package also provides an abstraction for Xterm that is using the terminal device,\nsupporting most of the escape control sequences in the manual (patch #379) as well dispatching events\nfor handling mouse movement.\n\n## Usage\n\n### Basic Output\n\n```php\nuse Aspectus\\Terminal\\TerminalDevice;\n\n$device = new TerminalDevice();\n\n$device-\u003ewrite(\"This and that\");    // will output \"This and that\" in STDOUT\n$device-\u003eerror(\"There was some error\");     // will output in STDERR\n```\n\n### Basic Input\n\nFor handling the input you can rely on the supplied EventDispatcher. \n\n```php\n\n$device-\u003esubscribe(\n    InputEvent::class,\n    function (InputEvent $event) {\n        $event-\u003edevice-\u003ewrite('Read: ' . bin2hex($event-\u003edata) . PHP_EOL);\n    }\n);\n\n$device-\u003esubscribe(\n    InputEvent::class,\n    function (InputEvent $event) {\n        if ($event-\u003edata === 'q') {\n            exit();\n        }\n    }\n);\n```\n\n### Device Input Events\n\nThe current implementation will distinguish between normal input events (InputEvent)\nand input that is an escape sequence (EscapeSequenceEvent), so your listeners can\nattach to the correct one. Unless you need to read some escape sequence that the\nterminal sends back to you, you probably need to listen to InputEvent.\n\n`InputEvent` - the default event that is emitted.\n\n`EscapeSequenceEvent` - this is emitted when input starts with an escape sequence\n\nAll events hold a reference to the device that dispatched them into the `$event-\u003edevice` property.\n\nFor `Xterm events` see below.\n\n### Event Factory\n\nThe device by default has a minimal implementation for creating new events. You\ncan supply your own by implementing the `EventFactoryInterface`.\n\n```php\ninterface EventFactoryInterface\n{\n    /**\n     * Optionally creates an event to be dispatched\n     *\n     * @param string $received\n     * @return InputEvent|null\n     */\n    public function createEvent(string $received): ?InputEvent;\n}\n```\n\n### Xterm abstraction\n\nThe package comes with an abstraction for Xterm that provides named methods to escape sequences in\na fluent interface. `Xterm` will buffer every call and write it to the device when `flush()` is called\nor return it as a `string` when `getBuffered()` is called.\n\n```php\n$xterm = new \\Aspectus\\Terminal\\Xterm();\n\n$xterm\n    // we reset colors in the beginning\n    -\u003edefault()\n    -\u003ebgDefault()\n    -\u003enormal()\n    -\u003eeraseDisplay()\n\n    // position for first message\n    -\u003emoveCursorTo(5,5)\n\n    // set style\n    -\u003ered()\n    -\u003ebgWhite()\n\n    // write a message\n    -\u003ewrite('Hello world!')\n\n    // position for second message\n    -\u003emoveCursorTo(8, 10)\n\n    // set style\n    -\u003ebold()\n    -\u003ebrightYellow()\n    -\u003ebgBlue()\n\n    // return instructions\n    -\u003ewrite('This is an Xterm abstraction!')\n\n    // write the whole buffer\n    -\u003eflush()\n```\n\n### Xterm Input events\n\nUsing the Xterm abstraction will add a different `EventFactory` implementation which will emit some\nadditional events when they are received.\n\n`SpecialKeyEvent` is emitted when function or arrow keys are pressed. The `data` property of\nthe event is mapped to a generic format, indicating function keys like `\u003cF2\u003e` and arrow keys\nlike `\u003cLEFT\u003e`, `\u003cRIGHT\u003e`.\n\n`MouseInputEvent` - is emitted when mouse tracking is enabled and provides properties like `x` and\n`y` as well as methods for the buttons (like `button1()`) to get information about which buttons\nwere pressed.\n\n`MouseFocusEvent` - is emitted when mouse tracking and focus tracking have been enabled and provides\na way to attach to an event that will trigger when the window loses focus or gains it again.\n\n### More usage examples\n\nMore usage examples can be found in the `examples/` directory.\n\n\n## Contribute\n\nEveryone is welcome to contribute, please see `CONTRIBUTE.md` for more information.\n\n## Licence\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAspectus-PHP%2Fterminal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAspectus-PHP%2Fterminal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAspectus-PHP%2Fterminal/lists"}