{"id":23842368,"url":"https://github.com/php-toolkit/cli-utils","last_synced_at":"2025-04-07T15:10:23.533Z","repository":{"id":43414646,"uuid":"132077482","full_name":"php-toolkit/cli-utils","owner":"php-toolkit","description":"Provide some useful utils for the php CLI. console color, CLI env, CLI code highlighter.","archived":false,"fork":false,"pushed_at":"2024-12-05T12:19:41.000Z","size":1163,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T14:11:24.244Z","etag":null,"topics":["cli-utilities","color","highlight","terminal"],"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/php-toolkit.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}},"created_at":"2018-05-04T02:52:30.000Z","updated_at":"2025-02-16T02:01:32.000Z","dependencies_parsed_at":"2024-06-18T16:59:27.735Z","dependency_job_id":"50b3bb6f-e600-448b-864b-da1f8783fda3","html_url":"https://github.com/php-toolkit/cli-utils","commit_stats":{"total_commits":120,"total_committers":4,"mean_commits":30.0,"dds":"0.10833333333333328","last_synced_commit":"bc07930a1669372566d8bc9f521a57cc3bb5b499"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fcli-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fcli-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fcli-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fcli-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-toolkit","download_url":"https://codeload.github.com/php-toolkit/cli-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675607,"owners_count":20977378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cli-utilities","color","highlight","terminal"],"created_at":"2025-01-02T18:38:20.349Z","updated_at":"2025-04-07T15:10:23.505Z","avatar_url":"https://github.com/php-toolkit.png","language":"PHP","readme":"# CLI Utils\n\n[![License](https://img.shields.io/packagist/l/toolkit/cli-utils.svg?style=flat-square)](LICENSE)\n[![Php Version](https://img.shields.io/badge/php-%3E=8.0.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/toolkit/cli-utils)\n[![Latest Stable Version](http://img.shields.io/packagist/v/toolkit/cli-utils.svg)](https://packagist.org/packages/toolkit/cli-utils)\n[![Github Actions Status](https://github.com/php-toolkit/cli-utils/workflows/Unit-tests/badge.svg)](https://github.com/php-toolkit/cli-utils/actions)\n\nProvide some useful utils for the php CLI application. \n\n- Simple CLI arguments and options parser.\n- Terminal console color render\n- CLI code highlighter\n- Build simple CLI application\n- CLI ENV information helper\n\n## Install\n\n- Required PHP 8.0+\n\n```bash\ncomposer require toolkit/cli-utils\n```\n\n## Console color\n\n```php\nColor::printf('\u003cinfo\u003e%s\u003c/info\u003e world', 'hello');\nColor::println('hello world', 'info');\nColor::println('hello world', 'error');\nColor::println('hello world', 'warning');\nColor::println('hello world', 'success');\n\necho Color::render('hello world', 'success');\n```\n\n![colors](example/images/color-styles.png)\n\n## Console log\n\n```php\nuse Toolkit\\Cli\\Util\\Clog;\n\n// run: php example/log.php\nforeach (Clog::getLevelNames() as $level) {\n    Clog::log($level, \"example log $level message\");\n}\n\n```\n\n![clog-example](example/images/clog-example.png)\n\n## Simple console app\n\n```php\nuse Toolkit\\Cli\\CliApp;\n\n// run:\n// php example/mycmd\n// php example/mycmd -i abc --lon def ag1 ag2 ag3\n$cmd = CliApp::new('cmd1', 'this is my cli application');\n$cmd-\u003eaddOpt('info', 'i', 'Output some information');\n$cmd-\u003eaddOpt('long-option-name', 'lon', 'this is a long option for command');\n$cmd-\u003eaddArg('arg1', 'this is first argument');\n\n$cmd-\u003esetHandler(function (CliApp $cmd) {\n  var_dump($cmd-\u003egetOpts(), $cmd-\u003egetArgs(), $cmd-\u003egetRemainArgs());\n});\n\n$cmd-\u003erun();\n```\n\n![clog-example](example/images/cli-app.png)\n\n## Terminal control\n\nexamples:\n\n```php\nuse Toolkit\\Cli\\Util\\Terminal;\n\nTerminal::forward(3);\nTerminal::backward(2);\n\nTerminal::clearLine();\n\nTerminal::clearScreen();\n```\n\n### Control Methods\n\n```php\n/**\n * @method static showCursor()\n * @method static hideCursor()\n * @method static savePosition()\n * @method static restorePosition()\n * @method static toTop()\n * @method static toColumn(int $step)\n * @method static up(int $step = 1)\n * @method static down(int $step = 1)\n * @method static forward(int $step = 1)\n * @method static backward(int $step = 1) Moves the terminal cursor backward\n * @method static toPrevNLineStart(int $step = 1)\n * @method static toNextNLineStart(int $step = 1)\n * @method static coordinate(int $col, int $row = 0)\n * @method static clearScreen()\n * @method static clearLine()\n * @method static clearToScreenBegin()\n * @method static clearToScreenEnd()\n * @method static scrollUp(int $step = 1)\n * @method static scrollDown(int $step = 1)\n * @method static showSecondaryScreen()\n * @method static showPrimaryScreen()\n */\n```\n\n## PHP file highlight\n\n\u003e This is inspire `jakub-onderka/php-console-highlighter`\n\n```php\nuse Toolkit\\Cli\\Util\\Highlighter;\n\n// this is an comment\n$rendered = Highlighter::create()-\u003ehighlight(file_get_contents(__FILE__));\n\n\\Toolkit\\Cli\\Cli::write($rendered);\n```\n\n![colors](example/cli-php-file-highlight.png)\n\n## CLI downloader\n\n```php\nuse Toolkit\\Cli\\Download;\n\n$url  = 'http://no2.php.net/distributions/php-7.2.5.tar.bz2';\n$down = Download::file($url, '');\n\n// $down-\u003esetShowType('bar');\n// $down-\u003esetDebug(true);\n$down-\u003estart();\n```\n\n**Progress bar**\n\n![down-file-bar](./example/down-file-bar.jpg)\n\n**Progress text**\n\n![down-file-txt-bar](./example/down-file-txt-bar.jpg)\n\n## Projects \n\n- https://github.com/inhere/php-console Build rich console application\n- https://github.com/php-toolkit/pflag Generic flags parse library, build simple console application.\n\n## Refer\n\n- https://www.sitepoint.com/howd-they-do-it-phpsnake-detecting-keypresses/\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-toolkit%2Fcli-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-toolkit%2Fcli-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-toolkit%2Fcli-utils/lists"}