diff --git a/LICENSE b/LICENSE index 6d91be2..b5c7e1b 100644 --- a/LICENSE +++ b/LICENSE @@ -125,3 +125,32 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------ +dealnews.com, Inc. - Inline ProgressBar CLI + +Copyright (c) 2010, dealnews.com, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of dealnews.com, Inc. nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index 48a977e..131e4fe 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ a PPM extension may be built in the future to allow for backwards compatibility. ## Copyright - Copyright (c) 2022-2022, Nosial - All Rights Reserved - Copyright (c) 2004-2022, Fabien Potencier + - Copyright (c) 2010, dealnews.com, Inc. All rights reserved. # Licenses diff --git a/src/ncc/Abstracts/ConsoleColors.php b/src/ncc/Abstracts/ConsoleColors.php new file mode 100644 index 0000000..0fd9ca7 --- /dev/null +++ b/src/ncc/Abstracts/ConsoleColors.php @@ -0,0 +1,40 @@ +toString($options_padding) . PHP_EOL); + Console::out(' ' . $option->toString($options_padding) . PHP_EOL); } print(PHP_EOL); } @@ -75,10 +76,10 @@ ]; $commands_padding = \ncc\Utilities\Functions::detectParametersPadding($commands) + 2; - print('Management Commands:' . PHP_EOL); + Console::out('Management Commands:' . PHP_EOL); foreach($commands as $command) { - print(' ' . $command->toString($commands_padding) . PHP_EOL); + Console::out(' ' . $command->toString($commands_padding) . PHP_EOL); } print(PHP_EOL); } @@ -96,10 +97,10 @@ ]; $commands_padding = \ncc\Utilities\Functions::detectParametersPadding($commands) + 2; - print('Commands:' . PHP_EOL); + Console::out('Commands:' . PHP_EOL); foreach($commands as $command) { - print(' ' . $command->toString($commands_padding) . PHP_EOL); + Console::out(' ' . $command->toString($commands_padding) . PHP_EOL); } print(PHP_EOL); } diff --git a/src/ncc/CLI/Main.php b/src/ncc/CLI/Main.php index 174de8b..b58d33e 100644 --- a/src/ncc/CLI/Main.php +++ b/src/ncc/CLI/Main.php @@ -4,6 +4,7 @@ use Exception; use ncc\ncc; + use ncc\Utilities\Console; use ncc\Utilities\Resolver; class Main @@ -28,7 +29,7 @@ switch(strtolower($args['ncc-cli'])) { default: - print('Unknown command ' . strtolower($args['ncc-cli']) . PHP_EOL); + Console::out('Unknown command ' . strtolower($args['ncc-cli']) . PHP_EOL); exit(1); case 'credential': @@ -43,7 +44,7 @@ } catch(Exception $e) { - print('Error: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ')' . PHP_EOL); + Console::out('Error: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ')' . PHP_EOL); exit(1); } diff --git a/src/ncc/CLI/ProjectMenu.php b/src/ncc/CLI/ProjectMenu.php new file mode 100644 index 0000000..e08dd20 --- /dev/null +++ b/src/ncc/CLI/ProjectMenu.php @@ -0,0 +1,65 @@ +toString($options_padding) . PHP_EOL); + } + print(PHP_EOL); + } + } \ No newline at end of file diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index e6e1dd1..1634685 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -126,6 +126,21 @@ // Finally create project.json $Project->toFile($this->ProjectPath . DIRECTORY_SEPARATOR . 'project.json'); + // And create the project directory for additional assets/resources + $Folders = [ + $this->ProjectPath . DIRECTORY_SEPARATOR . 'ncc', + $this->ProjectPath . DIRECTORY_SEPARATOR . 'ncc' . DIRECTORY_SEPARATOR . 'cache', + $this->ProjectPath . DIRECTORY_SEPARATOR . 'ncc' . DIRECTORY_SEPARATOR . 'config', + ]; + + foreach($Folders as $folder) + { + if(file_exists($folder) == false) + { + mkdir($folder); + } + } + // Process options foreach($options as $option) { diff --git a/src/ncc/Objects/CliHelpSection.php b/src/ncc/Objects/CliHelpSection.php index 6be789a..1effeff 100644 --- a/src/ncc/Objects/CliHelpSection.php +++ b/src/ncc/Objects/CliHelpSection.php @@ -2,6 +2,9 @@ namespace ncc\Objects; + use ncc\Abstracts\ConsoleColors; + use ncc\Utilities\Console; + class CliHelpSection { /** @@ -80,7 +83,7 @@ * * @return string */ - public function toString(int $param_padding=0) + public function toString(int $param_padding=0, bool $basic=false) { $out = []; @@ -88,11 +91,25 @@ { if($param_padding > 0) { - $out[] .= str_pad(implode(' ', $this->Parameters), $param_padding, ' ', STR_PAD_RIGHT); + $result = str_pad(implode(' ', $this->Parameters), $param_padding, ' ', STR_PAD_RIGHT); + + if($basic == false) + { + $result = Console::formatColor($result, ConsoleColors::Green); + } + + $out[] .= $result; } else { - $out[] .= implode(' ', $this->Parameters); + if($basic) + { + $out[] .= implode(' ', $this->Parameters); + } + else + { + $out[] .= Console::formatColor(implode(' ', $this->Parameters), ConsoleColors::Green); + } } } diff --git a/src/ncc/Utilities/Console.php b/src/ncc/Utilities/Console.php new file mode 100644 index 0000000..99757d7 --- /dev/null +++ b/src/ncc/Utilities/Console.php @@ -0,0 +1,112 @@ + $total) return; + + if(empty($start_time)) $start_time=time(); + $now = time(); + + $perc=(double)($value/$total); + + $bar=floor($perc*$size); + + $status_bar="\r[ "; + $status_bar.=str_repeat("=", $bar); + if($bar<$size){ + $status_bar.=">"; + $status_bar.=str_repeat(" ", $size-$bar); + } else { + $status_bar.="="; + } + + $disp=number_format($perc*100, 0); + + $status_bar.=" ] $disp% $value/$total"; + + $rate = ($now-$start_time)/$value; + $left = $total - $value; + $eta = round($rate * $left, 2); + + $elapsed = $now - $start_time; + + $status_bar.= " remaining: ".number_format($eta)." sec. elapsed: ".number_format($elapsed)." sec."; + + echo "$status_bar "; + + flush(); + + // when done, send a newline + if($value == $total) { + echo "\n"; + } + } + + /** + * Simple output function + * + * @param string $message + * @param bool $newline + * @return void + */ + public static function out(string $message, bool $newline=true) + { + if($newline) + { + print($message . PHP_EOL); + return; + } + + print($message); + } + + /** + * Formats the text to have a different color and returns the formatted value + * + * @param string $input The input of the text value + * @param string $color_code The color code of the escaped character (\e[91m) + * @param bool $persist If true, the formatting will terminate in the default color + * @return string + */ + public static function formatColor(string $input, string $color_code, bool $persist=true): string + { + if($persist) + { + return $color_code . $input . ConsoleColors::Default; + } + + return $color_code . $input; + } + + /** + * Prints out a warning output + * + * @param string $message + * @param bool $newline + * @return void + */ + public static function outWarning(string $message, bool $newline=true) + { + self::out(self::formatColor(ConsoleColors::Yellow, 'Warning: ') . $message, $newline); + } + } \ No newline at end of file