diff --git a/composer.json b/composer.json index 1e0cea8..ff34be2 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ } }, "suggest": { - "symfony/process": "php process operation" + "symfony/process": "php process operation", + "text/template": "Single-Class string template engine for PHP5/7 supporting if/loops/filters" } } diff --git a/examples/Controllers/ProcessController.php b/examples/Controllers/ProcessController.php index ab62380..d806b22 100644 --- a/examples/Controllers/ProcessController.php +++ b/examples/Controllers/ProcessController.php @@ -30,6 +30,16 @@ protected static function commandAliases() ]; } + /** + * simple process example for child-process + */ + public function runScriptCommand() + { + $script = ''; + + + } + /** * simple process example for child-process */ @@ -69,4 +79,4 @@ public function multiProcessCommand() { } -} \ No newline at end of file +} diff --git a/src/BuiltIn/Resources/auto-complete-scripts/phalcon.bash b/src/BuiltIn/Resources/auto-complete-scripts/phalcon.bash new file mode 100644 index 0000000..bf490fb --- /dev/null +++ b/src/BuiltIn/Resources/auto-complete-scripts/phalcon.bash @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# +# +------------------------------------------------------------------------+ +# | Phalcon Developer Tools | +# +------------------------------------------------------------------------+ +# | Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) | +# +------------------------------------------------------------------------+ +# | This source file is subject to the New BSD License that is bundled | +# | with this package in the file LICENSE.txt. | +# | | +# | If you did not receive a copy of the license and are unable to | +# | obtain it through the world-wide-web, please send an email | +# | to license@phalconphp.com so we can send you a copy immediately. | +# +------------------------------------------------------------------------+ +# | Authors: Andres Gutierrez | +# | Eduar Carvajal | +# | Jakob <@jamurko> | +# +------------------------------------------------------------------------+ +# + +_phalcon() +{ + local cur prev + _get_comp_words_by_ref -n = cur prev + + commands="commands list enumerate controller create-controller model \ + create-model all-models create-all-models project create-project scaffold \ + create-scaffold migration create-migration webtools create-webtools" + + case "$prev" in + project|create-project) + COMPREPLY=($(compgen -W "--name --webtools --directory --type --template-path --use-config-ini --trace --help --namespace" -- "$cur")) + return 0 + ;; + esac + + COMPREPLY=($(compgen -W "$commands" -- "$cur")) + +} && +complete -F _phalcon phalcon diff --git a/src/BuiltIn/Resources/templates/auto-complete-scripts.tpl b/src/BuiltIn/Resources/templates/auto-complete-scripts.tpl new file mode 100644 index 0000000..e69de29 diff --git a/src/Components/AutoCompletion.php b/src/Components/AutoComplete/AutoCompletion.php similarity index 90% rename from src/Components/AutoCompletion.php rename to src/Components/AutoComplete/AutoCompletion.php index 4f64c0b..fc543ed 100644 --- a/src/Components/AutoCompletion.php +++ b/src/Components/AutoComplete/AutoCompletion.php @@ -6,13 +6,13 @@ * Time: 17:56 */ -namespace Inhere\Console\Components; +namespace Inhere\Console\Components\AutoComplete; /** * Class AutoCompletion - a simple command auto-completion tool * * @todo not available - * @package Inhere\Console\Components + * @package Inhere\Console\Components\AutoComplete */ class AutoCompletion { @@ -57,9 +57,9 @@ public function register() */ public function completionHandler($input, $index) { - $info = readline_info(); - $line = substr($info['line_buffer'], 0, $info['end']); - $tokens = token_get_all('type; + } + + /** + * @param int $type + */ + public function setType(int $type) + { + if (\in_array($type, self::typeList(), 1)) { + $this->type = $type; + } + } + + /** + * @return int + */ + public function getMode(): int + { + return $this->mode; + } + + /** + * @param int $mode + */ + public function setMode(int $mode) + { + if (\in_array($mode, self::modeList(), 1)) { + $this->mode = $mode; + } + } +} diff --git a/src/Components/CodeExecComparator.php b/src/Components/ExecComparator.php similarity index 86% rename from src/Components/CodeExecComparator.php rename to src/Components/ExecComparator.php index 36b18d2..37585cb 100644 --- a/src/Components/CodeExecComparator.php +++ b/src/Components/ExecComparator.php @@ -9,10 +9,10 @@ namespace Inhere\Console\Components; /** - * Class CodeExecComparator - PHP code exec speed comparator + * Class ExecComparator - PHP code exec speed comparator * @package Inhere\Console\Components */ -class CodeExecComparator +class ExecComparator { /** * @var array @@ -39,4 +39,4 @@ public function setVars(array $vars) { $this->vars = $vars; } -} \ No newline at end of file +} diff --git a/src/Components/Formatter/Formatter.php b/src/Components/Formatter/Formatter.php new file mode 100644 index 0000000..9c57d38 --- /dev/null +++ b/src/Components/Formatter/Formatter.php @@ -0,0 +1,18 @@ +speed; + } + + /** + * @param int $speed + */ + public function setSpeed($speed) + { + $this->speed = (int)$speed; + } + +} diff --git a/src/Components/TextTemplate.php b/src/Components/TextTemplate.php new file mode 100644 index 0000000..faae6be --- /dev/null +++ b/src/Components/TextTemplate.php @@ -0,0 +1,140 @@ +openChar)) { + return $template; + } + + if ($this->vars) { + $vars = array_merge($this->vars, $vars); + } + + $pairs = []; + + foreach ($vars as $name => $value) { + $key = $this->openChar . $name . $this->closeChar; + $pairs[$key] = $value; + } + + return strtr($template, $pairs); + } + + /** + * @param string $name + * @param null $default + * @return mixed + */ + public function getVar(string $name, $default = null) + { + return $this->vars[$name] ?? $default; + } + + /** + * @param string $name + * @param mixed $value + */ + public function addVar(string $name, $value) + { + if (!isset($this->vars[$name])) { + $this->vars[$name] = $value; + } + } + + /** + * @param string $name + * @param mixed $value + */ + public function setVar(string $name, $value) + { + $this->vars[$name] = $value; + } + + /** + * @param array $vars + */ + public function addVars(array $vars) + { + $this->vars = array_merge($this->vars, $vars); + } + + /** + * @return array + */ + public function getVars(): array + { + return $this->vars; + } + + /** + * @param array $vars + */ + public function setVars(array $vars) + { + $this->vars = $vars; + } + + /** + * @return string + */ + public function getOpenChar(): string + { + return $this->openChar; + } + + /** + * @param string $openChar + */ + public function setOpenChar(string $openChar) + { + if ($openChar) { + $this->openChar = $openChar; + } + } + + /** + * @return string + */ + public function getCloseChar(): string + { + return $this->closeChar; + } + + /** + * @param string $closeChar + */ + public function setCloseChar(string $closeChar) + { + if ($closeChar) { + $this->closeChar = $closeChar; + } + } +} diff --git a/src/Utils/Show.php b/src/Utils/Show.php index 60710a7..e8341cc 100644 --- a/src/Utils/Show.php +++ b/src/Utils/Show.php @@ -589,6 +589,7 @@ public static function panel($data, $title = 'Information Panel', array $opts = $border = null; $panelWidth = $labelMaxWidth + $valueMaxWidth; + self::startBuffer(); // output title if ($title) { @@ -621,6 +622,7 @@ public static function panel($data, $title = 'Information Panel', array $opts = self::write(" $border\n"); } + self::flushBuffer(); unset($panelData); return 0;