aharabara / habarnam
Ncurses 封装库,用于快速构建 TUI
v0.4.7
2019-06-07 11:07 UTC
Requires
- ext-ctype: *
- ext-mbstring: *
- ext-ncurses: *
- ext-simplexml: *
- analog/analog: ^1.0
- sabberworm/php-css-parser: ^8.3
- symfony/css-selector: ^4.2
- vlucas/phpdotenv: ^3.3@dev
This package is auto-updated.
Last update: 2024-09-09 10:55:19 UTC
README
⚡ Habarnam
警告! ⚠️
此包处于早期开发阶段,请在了解风险之前不要使用。
为 ext-ncurses
提供框架/封装,允许您使用少量 XML 和 PHP 编写简单的 CLI 应用程序。
如果您喜欢它,请给它一个 ⭐,如果不喜欢,请告诉我,我们将使其变得更好。
使用 habarnam
制作
很快就可以实现
- 聊天(进行中)
- Redis 或 MySQL 浏览器
- Reddit 浏览器
- Ascii 绘图工具
如果您有任何想法,请创建一个问题,我们将讨论它 🤘
使用方法
#go to you project directory and require it into your project composer require aharabara/habarnam # then install ext-ncurses with its patches, so it will work for php 7.* # and add 'extension=ncurses.so' to your php.ini ./vendor/aharabara/habarnam/install.sh touch ./index.php mkdir ./src/ mkdir ./logs/ mkdir ./views/ mkdir ./assets/ touch ./views/surfaces.xml touch ./views/main.xml touch ./assets/styles.css
index.php 内容
<?php use Base\{Application, Core\Installer, Core\Workspace, Services\ViewRender}; require __DIR__ . '/vendor/autoload.php'; $projectName = '<You project name>'; // will be used to create a folder inside ~/.config $workspace = new Workspace("habarnam-{$projectName}"); $installer = new Installer($workspace); $installer->checkCompatibility(); if (!$installer->isInstalled()) { $installer->run(); } /* folder with surfaces.xml and other view files */ $render = new ViewRender(__DIR__. '/views/'); (new Application($workspace, $render->prepare(), 'main')) ->debug(true) ->handle();
surface.xml 内容
<surfaces> <!-- each surface should be declared inside application>surfaces element and should have 'id' attribute --> <surface id="example.middle"> <!-- top left corner of the surface--> <pos x="10" y="4"/> <!-- top bottom corner of the surface--> <pos x="-10" y="8"/> <!-- y="-5" will lead to calculation from bottom and not from the top --> <!-- x="-5" will lead to calculation from right and not from the left --> </surface> <surface id="example.fullscreen"/> <!-- In some cases you just need a popup, so you can use [type=centered] and specify it's [height] and [width] --> <surface id="example.popup" height="7" type="centered"/> </surfaces>
main.xml 内容
<template id="main"> <!-- template tag represents a screen with components --> <!-- you can jump between view using Application->switchTo('TemplateID') or BaseController->switchTo('TemplateID')--> <head> <!-- you can specify here which css files you want to load for this template--> <link src="/assets/styles.css"/> </head> <body> <section title="Users" surface="column.left"> <!-- surface attribute will set section size and position --> <ol id="users" on.item.selected="\App\UserController@login"> <!-- on.* are events that are triggered during interaction --> <li value="user-1">User</li> <!-- you can nest some components, for example ol > li --> </ol> </section> <section title="History" surface="column.right.top"> <!-- or section > * --> <textarea id="info"/> </section> <section title="Message" surface="column.right.bottom"> <input id="message"/> <!-- you can address any (non-dynamic) component via Application->findFirst('.css>selector')--> <button on.press="\App\UserController@login" id="send">Send</button> <!-- or via Application->findAll('selector')--> </section> </body> </template>
提示
- 使用
Tab
和Shift + Tab
或键盘箭头在组件间导航。 - 调用
Application->debug(true)
并按 F1,您将能够看到组件表面。表面计算仍存在错误,但您可以使用它。 - 按
F3
切换调整大小模式 - 按
F5
从 css 文件中刷新样式。(:cool:) - 按
Ctrl+X
退出应用程序。请小心,并在退出前保存所有内容。 - 更多即将到来...