macroman/terminal-progress-bar
Composer 安装命令:
composer require macroman/terminal-progress-bar
包简介
Flexible ascii progress bar.
README 文档
README
Flexible ascii progress bar.
Installation
composer require macroman/terminal-progress-bar
Usage
First we create a Bar, giving it a format string
as well as the total, telling the progress bar when it will
be considered complete. Then call tick() when needed.
// examples/basic.php use TerminalProgress\Bar; $pg = new Bar(1000); for ($i = 0; $i < 1000; $i++) { usleep(10000); $pg->tick(); }
You can also use update(amount) to set the current tick value instead of ticking each time there is an increment:
// examples/update.php use TerminalProgress\Bar; $pg = new Bar(1000); for ($i = 0; $i < 1000; $i++) { usleep(10000); $pg->update($i); }
Options
These are properties in the object you can read/set:
symbolCompleteCompletion character defaulting to "="symbolIncompleteIncomplete character defaulting to " "throttleMinimum time between updates in seconds defaulting to 0.016currentCurrent ticktotalSame value passed in when initialisingsecondPrecisionNumber of decimal digits to use in "seconds" unitspercentPrecisionNumber of decimal digits to use in "percentage" unitspercent(read only) Current percentage completioneta(read only) Estimate seconds until completionrate(read only) Number of ticks per secondelapsed(read only) Seconds since initialisation
Tokens
These are tokens you can use in the format of your progress bar.
:barthe progress bar itself:currentcurrent tick number:totaltotal ticks:elapsedtime elapsed in seconds:percentcompletion percentage:etaestimated completion time in seconds:raterate of ticks per second
Format example
// examples/format.php // Full options new Bar(10, "Progress: [:bar] - :current/:total - :percent% - Elapsed::elapseds - ETA::etas - Rate::rate/s");
// examples/format_percent.php // Just percentage plus the bar new Bar(10, ":bar :percent%");
// examples/format_no_bar.php // You don't even have to have a bar new Bar(10, "Look mum, no bar! :current/:total - :percent% - Elapsed::elapseds - ETA::etas - Rate::rate/s");
Interrupt example
To display a message during progress bar execution, use interrupt()
// examples/interrupt.php $pg = new Bar(1000); for ($i = 0; $i < 1000; $i++) { usleep(10000); if ($i % 100 == 0) { // Interupt every 100th tick $pg->interupt($i); } $pg->tick(); }
Symbols/Precision example
To change the symbols or precision used on the progress bar
// examples/symbols.php $pg = new Bar(1000); $pg->symbolComplete = "#"; $pg->symbolIncomplete = "-"; $pg->secondPrecision = 2; $pg->percentPrecision = 4;
Throttle example
The draw interval is throttled at once per 100ms for performance. You can change this value if desired, eg lower for a smoother animation or higher if your work is resource intensive.
// examples/throttle.php $pg = new Bar(1000); $pg->throttle = 0.05; // Set a 50 millisecond throttle
License
See LICENSE
macroman/terminal-progress-bar 适用场景与选型建议
macroman/terminal-progress-bar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46.14k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2020 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 macroman/terminal-progress-bar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 macroman/terminal-progress-bar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 46.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 52
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2020-11-03