Renamed package to laravel-console-writer and fixed namespaces.

This commit is contained in:
fristi 2019-09-24 15:46:29 +02:00
parent c5842b4f55
commit 914488bec2
No known key found for this signature in database
GPG key ID: D5ACA407EBF4B713
12 changed files with 151 additions and 145 deletions

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2019 Marvin Schreurs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -1,3 +1,6 @@
# laravel-output-writer
# Laravel Console Writer
Console output interface for laravel.
Console input/output writer for Laravel. Features a dedicated class for console
interactivity for use with the Laravel Framework 5.8 and higher, allowing
easier styling through proper class inheritance while providing a simple and
non-obstructive interface for use in your console commands.

View file

@ -0,0 +1,33 @@
{
"name": "danmaku/laravel-console-writer",
"type": "library",
"description": "Easily adaptable console input/output writer for Laravel.",
"authors": [
{
"name": "Marvin Schreurs",
"email": "fristi@danmaku.moe",
"homepage": "https://fristi.danmaku.moe",
"role": "Developer"
}
],
"support": {
"email": "fristi@danmaku.moe"
},
"keywords": [
"laravel",
"console",
"symfony"
],
"license": "MIT",
"minimum-stability": "dev",
"require": {
"php": ">=7.2.0",
"illuminate/console": "^5.8",
"symfony/console": "^4.2"
},
"autoload": {
"psr-4": {
"Danmaku\\LaravelConsoleWriter\\": "src/"
}
}
}

View file

@ -6,15 +6,15 @@
*
* PHP version 7.2
*
* @package Arc\Base\Console\Command
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Command
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Command;
namespace Danmaku\LaravelConsoleWriter\Console\Command;
use Arc\Base\Console\Output\BaseOutputWriter;
use Arc\Base\Console\Output\OutputWriterInterface;
use Danmaku\LaravelConsoleWriter\Console\Output\BaseOutputWriter;
use Danmaku\LaravelConsoleWriter\Console\Output\OutputWriterInterface;
use Illuminate\Console\Command;
use Illuminate\Console\OutputStyle;
use Symfony\Component\Console\Input\InputInterface;
@ -23,8 +23,8 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* Class BaseCommand
*
* @package Arc\Base\Console\Command
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Command
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
abstract class BaseCommand extends Command
{

View file

@ -1,16 +1,16 @@
<?php
/**
* UnfuckedQuestionHelper class source file.
* InheritableQuestionHelper class source file.
*
* Contains the source code of the UnfuckedQuestionHelper class.
* Contains the source code of the InheritableQuestionHelper class.
*
* PHP version 7.2
*
* @package Arc\Base\Console\Helper
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Helper
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Helper;
namespace Danmaku\LaravelConsoleWriter\Console\Helper;
use Symfony\Component\Console\Exception\RuntimeException;
@ -25,12 +25,12 @@ use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;
/**
* Class UnfuckedQuestionHelper
* Class InheritableQuestionHelper
*
* @package Arc\Base\Console\Helper
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Helper
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
class UnfuckedQuestionHelper extends \Symfony\Component\Console\Helper\QuestionHelper
class InheritableQuestionHelper extends \Symfony\Component\Console\Helper\QuestionHelper
{
protected $inputStream;
protected static $shell;

View file

@ -6,11 +6,11 @@
*
* PHP version 7.2
*
* @package Arc\Base\Console\Helper
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Helper
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Helper;
namespace Danmaku\LaravelConsoleWriter\Console\Helper;
use Symfony\Component\Console\Exception\RuntimeException;
@ -28,10 +28,10 @@ use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Class QuestionHelper
*
* @package Arc\Base\Console\Helper
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Helper
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
class QuestionHelper extends UnfuckedQuestionHelper
class QuestionHelper extends InheritableQuestionHelper
{
public function ask(InputInterface $input, OutputInterface $output, Question $question)
{

View file

@ -6,17 +6,17 @@
*
* PHP version 7.2
*
* @package Arc\Base\Console\Output
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Output
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Output;
namespace Danmaku\LaravelConsoleWriter\Console\Output;
use Arc\Base\Console\Helper\QuestionHelper;
use Arc\Base\Console\Question\BaseChoiceQuestion;
use Arc\Base\Console\Question\BaseConfirmationQuestion;
use Arc\Base\Console\Question\BaseQuestion;
use Danmaku\LaravelConsoleWriter\Console\Helper\QuestionHelper;
use Danmaku\LaravelConsoleWriter\Console\Question\BaseChoiceQuestion;
use Danmaku\LaravelConsoleWriter\Console\Question\BaseConfirmationQuestion;
use Danmaku\LaravelConsoleWriter\Console\Question\BaseQuestion;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
@ -35,8 +35,8 @@ use Symfony\Component\Console\Terminal;
/**
* Class BaseOutputWriter
*
* @package Arc\Base\Console\Output
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Output
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
class BaseOutputWriter implements OutputWriterInterface
{
@ -93,11 +93,13 @@ class BaseOutputWriter implements OutputWriterInterface
'warning' => ['yellow', 'black'],
'danger' => ['red', 'black'],
'success' => ['green', 'black'],
'debug' => ['black', 'white'],
'comment-bg' => ['black', 'white'],
'info-bg' => ['black', 'cyan'],
'warning-bg' => ['black', 'yellow'],
'danger-bg' => ['white', 'red'],
'success-bg' => ['black', 'green'],
'debug-bg' => ['black', 'white'],
'title' => ['green', 'black'],
'section' => ['white', 'black'],
'question'=> ['green', 'black'],
@ -110,7 +112,7 @@ class BaseOutputWriter implements OutputWriterInterface
*
* @var int $maxLineLength
*/
protected $maxLineLength = 80;
protected $maxLineLength = 120;
/**
* BaseOutputStyler constructor.
@ -136,9 +138,6 @@ class BaseOutputWriter implements OutputWriterInterface
$this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), $this->maxLineLength);
}
/**
* {@inheritdoc}
*/
public function title(string $title): void
{
$this->autoPrependBlock();
@ -149,9 +148,6 @@ class BaseOutputWriter implements OutputWriterInterface
$this->newLine();
}
/**
* {@inheritdoc}
*/
public function section(string $heading): void
{
$this->autoPrependBlock();
@ -162,9 +158,6 @@ class BaseOutputWriter implements OutputWriterInterface
$this->newLine();
}
/**
* {@inheritdoc}
*/
public function table(array $headers, array $rows): void
{
$style = clone Table::getStyleDefinition('symfony-style-guide');
@ -179,9 +172,6 @@ class BaseOutputWriter implements OutputWriterInterface
$this->newLine();
}
/**
* {@inheritdoc}
*/
public function list(array $items, bool $dictionary = false): void
{
$this->autoPrependText();
@ -205,10 +195,7 @@ class BaseOutputWriter implements OutputWriterInterface
$this->newLine();
}
/**
* {@inheritdoc}
*/
public function text($message, string $style = null): void
public function text($message, string $style = null, $verbosity = OutputInterface::VERBOSITY_NORMAL): void
{
$this->autoPrependText();
@ -218,71 +205,67 @@ class BaseOutputWriter implements OutputWriterInterface
$message = sprintf(" <$style>%s</>", $message);
}
$this->writeln(sprintf(' %s', $message));
$this->writeln(sprintf(' %s', $message), $verbosity);
}
}
/**
* {@inheritdoc}
*/
public function success($message, bool $padding = false): void
{
if(!$this->output->isQuiet()) {
$style = $padding ? 'success-bg' : 'success';
$this->block($message, 'OK', $style, ' ', $padding);
}
}
/**
* {@inheritdoc}
*/
public function error($message, bool $padding = false): void
{
if(!$this->output->isQuiet()) {
$style = $padding ? 'danger-bg' : 'danger';
$this->block($message, 'ERROR', $style, ' ', $padding);
}
}
/**
* {@inheritdoc}
*/
public function warning($message, bool $padding = false): void
{
if(!$this->output->isQuiet()) {
$style = $padding ? 'warning-bg' : 'warning';
$this->block($message, 'WARN', $style, ' ', $padding);
}
}
/**
* {@inheritdoc}
*/
public function comment($message, bool $padding = false): void
{
if($this->output->isVeryVerbose()) {
$style = $padding ? 'comment-bg' : 'comment';
$this->block($message, null, $style, " // ", $padding, false);
}
}
/**
* {@inheritdoc}
*/
public function info($message, bool $padding = false): void
{
if($this->output->isVeryVerbose()) {
$style = $padding ? 'info-bg' : 'info';
$this->block($message, 'INFO', $style, ' ', $padding);
}
}
public function debug($message, bool $padding = false): void
{
if($this->output->isDebug()) {
$style = $padding ? 'debug-bg' : 'debug';
$this->block($message, 'DEBUG', $style, ' ', $padding);
}
}
/**
* {@inheritdoc}
*/
public function exception(\Throwable $throwable, string $message = null): void
{
$this->error([
$message ?? 'An exception has occurred!',
'',
sprintf('In %s on line %s:', $throwable->getFile(), $throwable->getLine()),
$throwable->getMessage()
], true);
}
/**
* {@inheritdoc}
*/
public function ask(string $question, $default = null, $validator = null)
{
$question = new BaseQuestion($question, $default);
@ -291,9 +274,6 @@ class BaseOutputWriter implements OutputWriterInterface
return $this->askQuestion($question);
}
/**
* {@inheritdoc}
*/
public function password(string $question, $validator = null)
{
$question = new BaseQuestion($question);
@ -304,42 +284,27 @@ class BaseOutputWriter implements OutputWriterInterface
return $this->askQuestion($question);
}
/**
* {@inheritdoc}
*/
public function confirm(string $question, $default = true): bool
{
return $this->askQuestion(new BaseConfirmationQuestion($question, $default));
}
/**
* {@inheritdoc}
*/
public function choice(string $question, array $choices, $default = null)
{
return $this->askQuestion(new BaseChoiceQuestion($question, $choices, $default));
}
/**
* {@inheritdoc}
*/
public function startProgress(int $max = 0): void
{
$this->progressBar = $this->createProgress($max);
$this->progressBar->start();
}
/**
* {@inheritdoc}
*/
public function advanceProgress(int $step = 1): void
{
$this->getProgressBar()->advance($step);
}
/**
* {@inheritdoc}
*/
public function finishProgress(): void
{
$this->getProgressBar()->finish();
@ -347,25 +312,21 @@ class BaseOutputWriter implements OutputWriterInterface
$this->progressBar = null;
}
/**
* {@inheritdoc}
*/
public function createProgress(int $max = 0): ProgressBar
{
$progressBar = new ProgressBar($this->output, $max);
if ('\\' !== \DIRECTORY_SEPARATOR || 'Hyper' === getenv('TERM_PROGRAM')) {
$progressBar->setEmptyBarCharacter('░'); // light shade character \u2591
$progressBar->setProgressCharacter('');
$progressBar->setBarCharacter('▓'); // dark shade character \u2593
}
$progressBar->setBarCharacter('<success>=</>');
$progressBar->setEmptyBarCharacter('<danger> </>');
$progressBar->setProgressCharacter('<warning>></>');
$progressBar->setBarWidth(60);
$progressBar->setFormat(
" %status%\n %current%/%max% [%bar%] %percent:3s%%\n 🏁 %estimated:-50s% %memory:20s%"
);
return $progressBar;
}
/**
* {@inheritdoc}
*/
public function newLine($count = 1): void
{
$this->output->write(str_repeat(PHP_EOL, $count));
@ -408,6 +369,7 @@ class BaseOutputWriter implements OutputWriterInterface
/**
* @param Question $question
* @return mixed
* @throws \Exception
*/
protected function askQuestion(Question $question)
{
@ -421,9 +383,6 @@ class BaseOutputWriter implements OutputWriterInterface
$answer = $this->questionHelper->ask($this->input, $this->output, $question);
if ($this->input->isInteractive()) {
$this->newLine();
$this->bufferedOutput->write("\n");
@ -485,8 +444,9 @@ class BaseOutputWriter implements OutputWriterInterface
* @param string $prefix The prefix for the block
* @param bool $padding Whether to add vertical padding
* @param bool $escape Whether to escape the message
* @param int $verbosity
*/
protected function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true)
protected function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true, $verbosity = OutputInterface::OUTPUT_NORMAL)
{
$messages = \is_array($messages) ? array_values($messages) : [$messages];
@ -496,7 +456,7 @@ class BaseOutputWriter implements OutputWriterInterface
$this->autoPrependText();
}
$this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape));
$this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape), $verbosity);
if($padding) {
$this->newLine();

View file

@ -6,11 +6,11 @@
*
* PHP version 7.2
*
* @package Arc\Base\Console\Output
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Output
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Output;
namespace Danmaku\LaravelConsoleWriter\Console\Output;
use Symfony\Component\Console\Helper\ProgressBar;
@ -19,8 +19,8 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* Interface OutputWriterInterface
*
* @package Arc\Base\Console\Output
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Output
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
interface OutputWriterInterface
{
@ -63,9 +63,10 @@ interface OutputWriterInterface
*
* @param string|array $message Message to display.
* @param string|null $style Style to apply to the message.
* @param int $verbosity Verbosity level at which this message should be printed.
* @return void
*/
public function text($message, string $style = null): void;
public function text($message, string $style = null, $verbosity = OutputInterface::VERBOSITY_NORMAL): void;
/**
* Formats a success message.
@ -112,6 +113,15 @@ interface OutputWriterInterface
*/
public function info($message, bool $padding = false): void;
/**
* Formats a debug message.
*
* @param string|array $message Message to display.
* @param bool $padding Render the message in a padded box.
* @return void
*/
public function debug($message, bool $padding = false): void;
/**
* Formats an exception.
*

View file

@ -6,11 +6,11 @@
*
* PHP version 7.2
*
* @package Arc\Base\Console\Question
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Question
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Question;
namespace Danmaku\LaravelConsoleWriter\Console\Question;
use Symfony\Component\Console\Exception\InvalidArgumentException;
@ -19,8 +19,8 @@ use Symfony\Component\Console\Question\ChoiceQuestion;
/**
* Class BaseChoiceQuestion
*
* @package Arc\Base\Console\Question
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Question
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
class BaseChoiceQuestion extends ChoiceQuestion
{

View file

@ -6,11 +6,11 @@
*
* PHP version 7.2
*
* @package Arc\Base\Console\Question
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Question
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Question;
namespace Danmaku\LaravelConsoleWriter\Console\Question;
use Symfony\Component\Console\Question\ConfirmationQuestion;
@ -18,8 +18,8 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
/**
* Class BaseConfirmationQuestion
*
* @package Arc\Base\Console\Question
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Question
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
class BaseConfirmationQuestion extends ConfirmationQuestion
{

View file

@ -6,11 +6,11 @@
*
* PHP version 7.2
*
* @package Arc\Base\Console\Question
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Question
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
namespace Arc\Base\Console\Question;
namespace Danmaku\LaravelConsoleWriter\Console\Question;
use Symfony\Component\Console\Question\Question;
@ -18,8 +18,8 @@ use Symfony\Component\Console\Question\Question;
/**
* Class BaseQuestion
*
* @package Arc\Base\Console\Question
* @author Marvin Schreurs <m.schreurs@archimedetrading.eu>
* @package Danmaku\LaravelConsoleWriter\Console\Question
* @author Marvin Schreurs <fristi@danmaku.moe>
*/
class BaseQuestion extends Question
{