Giter VIP home page Giter VIP logo

console's Introduction

Hoa


Build status Code coverage Packagist License

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\Console

Help on IRC Help on Gitter Documentation Board

This library allows to interact easily with a terminal: getoption, cursor, window, processus, readline etc.

Learn more.

Installation

With Composer, to include this library into your dependencies, you need to require hoa/console:

$ composer require hoa/console '~3.0'

For more installation procedures, please read the Source page.

Testing

Before running the test suites, the development dependencies must be installed:

$ composer install

Then, to run all the test suites:

$ vendor/bin/hoa test:run

For more information, please read the contributor guide.

Quick usage

We propose a quick overview of some features: cursor, window, readline, processus and finally getoption.

Cursor

The Hoa\Console\Cursor class allows to manipulate the cursor. Here is a list of some operations:

  • move,
  • moveTo,
  • save,
  • restore,
  • clear,
  • hide,
  • show,
  • getPosition,
  • colorize,
  • etc.

The API is very straightforward. For example, we can use l, left or to move the cursor on the left column. Thus we move the cursor to the left 3 times and then to the top 2 times:

Hoa\Console\Cursor::move('left left left up up');

… or with Unicode symbols:

Hoa\Console\Cursor::move('← ← ← ↑ ↑');

This method moves the cursor relatively from its current position, but we are able to move the cursor to absolute coordinates:

Hoa\Console\Cursor::moveTo(13, 42);

We are also able to save the current cursor position, to move, clear etc., and then to restore the saved position:

Hoa\Console\Cursor::save();     // save
Hoa\Console\Cursor::move('');  // move below
Hoa\Console\Cursor::clear(''); // clear the line
echo 'Something below…';        // write something
Hoa\Console\Cursor::restore();  // restore

Another example with colors:

Hoa\Console\Cursor::colorize(
    'underlined foreground(yellow) background(#932e2e)'
);

Please, read the API documentation for more informations.

Mouse

The Hoa\Console\Mouse class allows to listen the mouse actions and provides the following listeners: mouseup, mousedown, wheelup and wheeldown. Example:

$mouse = Hoa\Console\Mouse::getInstance();
$mouse->on('mousedown', function ($bucket) {
    print_r($bucket->getData());
});

$mouse::track();

And then, when we left-click, we will see:

Array
(
    [x] => 69
    [y] => 30
    [button] => left
    [shift] =>
    [meta] =>
    [ctrl] =>
)

When we left-click while hiting the shift key, we will see:

Array
(
    [x] => 71
    [y] => 32
    [button] => left
    [shift] => 1
    [meta] =>
    [ctrl] =>
)

This is an experimental API.

Window

The Hoa\Console\Window class allows to manipulate the window. Here is a list of some operations:

  • setSize,
  • getSize,
  • moveTo,
  • getPosition,
  • scroll,
  • minimize,
  • restore,
  • raise,
  • setTitle,
  • getTitle,
  • copy,
  • etc.

Furthermore, we have the hoa://Event/Console/Window:resize event channel to listen when the window has been resized.

For example, we resize the window to 40 lines and 80 columns, and then we move the window to 400px horizontally and 100px vertically:

Hoa\Console\Window::setSize(40, 80);
Hoa\Console\Window::moveTo(400, 100);

If we do not like our user, we are able to minimize its window:

Hoa\Console\Window::minimize();
sleep(2);
Hoa\Console\Window::restore();

We are also able to set or get the title of the window:

Hoa\Console\Window::setTitle('My awesome application');

Finally, if we have a complex application layout, we can repaint it when the window is resized by listening the hoa://Event/Console/Window:resize event channel:

Hoa\Event\Event::getEvent('hoa://Event/Console/Window:resize')
    ->attach(function (Hoa\Event\Bucket $bucket) {
        $data = $bucket->getData();
        $size = $data['size'];

        echo
            'New dimensions: ', $size['x'], ' lines x ',
            $size['y'], ' columns.', "\n";
    });

Please, read the API documentation for more informations

Readline

The Hoa\Console\Readline\Readline class provides an advanced readline which allows the following operations:

  • edition,
  • history,
  • autocompletion.

It supports UTF-8. It is based on bindings, and here are some:

  • arrow up and arrow down: move in the history,
  • arrow left and arrow right: move the cursor left and right,
  • Ctrl-A: move to the beginning of the line,
  • Ctrl-E: move to the end of the line,
  • Ctrl-B: move backward of one word,
  • Ctrl-F: move forward of one word,
  • Ctrl-W: delete first backard word,
  • Backspace: delete first backward character,
  • Enter: submit the line,
  • Tab: autocomplete.

Thus, to read one line:

$readline = new Hoa\Console\Readline\Readline();
$line     = $readline->readLine('> '); // “> ” is the prefix of the line.

The Hoa\Console\Readline\Password allows the same operations but without printing on STDOUT.

$password = new Hoa\Console\Readline\Password();
$line     = $password->readLine('password: ');

We are able to add a mapping with the help of the Hoa\Console\Readline\Readline::addMapping method. We use \e[… for \033[, \C-… for Ctrl-… and a character for the rest. We can associate a character or a callable:

$readline->addMapping('a', 'z'); // crazy, we replace “a” by “z”.
$readline->addMapping('\C-R', function ($readline) {
    // do something when pressing Ctrl-R.
});

We are also able to manipulate the history, thanks to the addHistory, clearHistory, getHistory, previousHistory and nextHistory methods on the Hoa\Console\Readline\Readline class.

Finally, we have autocompleters that are enabled on Tab. If one solution is proposed, it will be inserted directly. If many solutions are proposed, we are able to navigate in a menu to select the solution (with the help of keyboard arrows, Enter, Esc etc.). Also, we are able to combine autocompleters. The following example combine the Word and Path autocompleters:

$functions = get_defined_functions();
$readline->setAutocompleter(
    new Hoa\Console\Readline\Autocompleter\Aggregate([
        new Hoa\Console\Readline\Autocompleter\Path(),
        new Hoa\Console\Readline\Autocompleter\Word($functions['internal'])
    ])
);

Here is an example of the result:

Autocompleters in action

On Windows, a readline is equivalent to a simple fgets(STDIN).

Processus

The Hoa\Console\Processus class allows to manipulate processus as a stream which implements Hoa\Stream\IStream\In, Hoa\Stream\IStream\Out and Hoa\Stream\IStream\Pathable interfaces (please, see the Hoa\Stream library).

Basically, we can read STDOUT like this:

$processus = new Hoa\Console\Processus('ls');
$processus->open();
echo $processus->readAll();

And we can write on STDIN like this:

$processus->writeAll('foobar');

etc. This is very classical.

Hoa\Console\Processus also proposes many events: start, stop, input, output and timeout. Thus:

$processus = new Hoa\Console\Processus('ls');
$processus->on('output', function (Hoa\Event\Bucket $bucket) {
    $data = $bucket->getData();
    echo '> ', $data['line'], "\n";
});
$processus->run();

We are also able to read and write on more pipes than 0 (STDOUT), 1 (STDIN) and 2 (STDERR). In the same way, we can set the current working directory of the processus and its environment.

We can quickly execute a processus without using a stream with the help of the Hoa\Console\Processus::execute method.

GetOption

The Hoa\Console\Parser and Hoa\Console\GetOption classes allow to parse a command-line and get options and inputs values easily.

First, we need to parse a command-line, such as:

$parser = new Hoa\Console\Parser();
$parser->parse('-s --long=value input');

Second, we need to define our options:

$options = new Hoa\Console\GetOption(
    [
        // long name              type                  short name
        //  ↓                      ↓                         ↓
        ['short', Hoa\Console\GetOption::NO_ARGUMENT,       's'],
        ['long',  Hoa\Console\GetOption::REQUIRED_ARGUMENT, 'l']
    ],
    $parser
);

And finally, we iterate over options:

$short = false;
$long  = null;

//          short name                  value
//               ↓                        ↓
while (false !== $c = $options->getOption($v)) {
    switch ($c) {
        case 's':
            $short = true;

            break;

        case 'l':
            $long = $v;

            break;
    }
}

var_dump($short, $long); // bool(true) and string(5) "value".

Please, see API documentation of Hoa\Console\Parser to see all supported forms of options (flags or switches, long or short ones, inputs etc.).

It also support typos in options. In this case, we have to add:

    case '__ambiguous':
        $options->resolveOptionAmbiguity($v);

        break;

If one solution is found, it will select this one automatically, else it will raise an exception. This exception is caught by Hoa\Console\Dispatcher\Kit when using the hoa script and a prompt is proposed.

Thanks to the Hoa\Router library and the Hoa\Dispatcher library (with its dedicated kit Hoa\Console\Dispatcher\Kit), we are able to build commands easily. Please, see all Bin/ directories in different libraries (for example Hoa\Cli\Bin\Resolve) and Hoa/Cli/Bin/Hoa.php to learn more.

Awecode

The following awecodes show this library in action:

  • Hoa\Console\Readline: why and how to use Hoa\Console\Readline? Simple examples will help us to use default shortcuts and we will even see the auto-completion,
  • Hoa\Websocket: why and how to use Hoa\Websocket\Server and Hoa\Websocket\Client? A simple example will illustrate the WebSocket protocol.

Documentation

The hack book of Hoa\Console contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project's website: hoa-project.net.

Getting help

There are mainly two ways to get help:

Contribution

Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details.

Related projects

The following projects are using this library:

  • PsySH, A runtime developer console, interactive debugger and REPL for PHP.

console's People

Contributors

grummfy avatar hywan avatar jubianchi avatar metalaka avatar shulard avatar stephpy avatar vonglasow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

console's Issues

Namespace conflit with library not yet updated

The recent change on commit add3edb for remove from_import have break Bin of library still continue to use namespace declaration with bracketed.

$ hoa worker:start -h
PHP Fatal error:  Cannot mix bracketed namespace declarations with unbracketed namespace declarations in /usr/local/lib/Hoa.central/Hoa/Console/Dispatcher/Kit.php on line 37

A few library are impacted :

  • Hoa\HTTP
  • Hoa\Praspel
  • Hoa\Realdom
  • Hoa\Worker
  • Hoa\Xml

Process: Async API

Hello !

As discussed in the #72, I create an issue for this new feature. The goal here is to use Process class to run multiple scripts from the same script.

Example code here :

$procs = [];
$count = 10;
$script = "date";
while(--$count > 0)
{
    $proc = new Processus(
        $script,
        null,
        [1 => ['file', 'php://stdout', 'a']]
    );
    $proc->open();
    $procs[] = $proc;
}

while(true) {
    foreach($procs as $key => $proc) {
        $status = $proc->getStatus();
        if(false === $status['running']) {
            finishProcess($proc, $status);
            unset($procs[$key]);
        }
    }

    if(0 === count($procs)) {
        break;
    }
}

For the moment the same PID is shared by all the Process instances. As @Hywan said in the mentioned issue, there is a solution by using &.

Thanks for your help !


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Readline doesn't working on Windows

The "Basic usage" example of Readline in official manual called Hack book of Hoa\Console doesn't working as expected. Here's this example:

$rl = new Hoa\Console\Readline\Readline();

do {
    $line = $rl->readLine('> ');
    echo '< ', $line, "\n\n";
} while (false !== $line && 'quit' !== $line);

It works fine on Linux. But on Windows (tested on 7 and 10) it doesn't prints a readline prompt prior user input. It prints it after user enter something end pressed Enter. I.e. user should enter some answer and only afterwards can see the question.

Additionally this script do not reacts on "quit" command because on Windows readline() returns user input with CR (ASCII 0x0D) symbol at the end.

Due to this issue this library cannot be used as universal cross-platform solution for console interaction with user.

Why the `GetOption::REQUIRED_ARGUMENT` does not throw `Exception` when an argument is missing ?

I started to write a cli script with the code :

#!/usr/bin/env php
<?php

require_once __DIR__.'/vendor/autoload.php';

$parser = new Hoa\Console\Parser();
$parser->parse(implode(' ', $argv));

$options = new Hoa\Console\GetOption(
    [
        ['long',  Hoa\Console\GetOption::REQUIRED_ARGUMENT, 'l']
    ],
    $parser
);

while(false !== $c = $options->getOption($v)) {
    switch($c) {
        case 'l':
            $long = $v;

            break;
    }
}

I specified that the long argument is required.

When I ran the script without any argument, no exception : ./script
When I ran the script with the argument but no value, exception : ./script -l

I've checked in the code and it seems that the exception is thrown only when the parameter is checked through the getOption method.

Don't you think that the GetOption::REQUIRED_ARGUMENT flag must throw an Exception when the argument is missing ?

Maybe a new flag GetOption::REQUIRED_VALUE is more suitable for the current behaviour ?

Hoa\Console\Window::copy does not work on tmux

And this is complicated… I asked on #tmux (IRC, Freenode) and here is the answer:

2015-09-29 09:10:22     Nei     I think tmux simply doesn't support it
2015-09-29 09:11:06     Nei     there is an obscure undocumented sequence you can use to pass things "through tmux" to whatever it is running on
2015-09-29 09:13:24     Nei     something like \ePtmux;\e\e]52;; ... \e\e\\\e\\
2015-09-29 09:13:32     Nei     note the doubling of \e
2015-09-29 09:13:48     Nei     http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324
2015-09-29 09:18:45     Hywan   Wow
2015-09-29 09:19:12     Hywan   And how can I detect whether I am running inside tmux?
2015-09-29 09:19:20     Hywan   Or should we implement this feature in tmux?
2015-09-29 09:19:30     Hywan   (the clipboard escape sequence)
2015-09-29 09:19:53     dmnc    Check $TMUX
2015-09-29 09:20:03     dmnc    That is how tmux decides if it's running inside tmux or not afaik.

Now we have to try :-).

New feature: CLI-like autocompleter

Is it possible to provide a context to autocompleter in order to suggest word depending on current string.
An exemple of what I am talking about

git br
would suggest "branch"
exec br
would suggest "break"

Words would be suggested depending on the whole string


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

unset Autocompleter

We can't unset an autocompleter.

If I do $rl->setAutocompleter(null);, I obtain:

Fatal error: Uncaught TypeError: Argument 1 passed to Hoa\Console\Readline\Readline::setAutocompleter() must implement interface Hoa\Console\Readline\Autocompleter\Autocompleter, null given

Can you add the unsetAutocompleter() method?

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for hoa/file dev-master -> satisfiable by hoa/file[dev-master].
    - hoa/file dev-master requires hoa/iterator dev-master -> satisfiable by hoa/iterator[dev-master] but these conflict with your requirements or minimum-stability.
  Problem 2
    - Installation request for hoa/test dev-master -> satisfiable by hoa/test[dev-master].
    - hoa/test dev-master requires hoa/cli dev-master -> satisfiable by hoa/cli[dev-master] but these conflict with your requirements or minimum-stability.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

You can mention @dependabot in the comments below to contact the Dependabot team.

Setting the cursor position doesn't change anything

Hi. My os is Lubuntu.

Setting the cursor position doesn't change anything, echo is still printed, in a continuous stream where anything printed is printed following each other.

Hoa\Console\Cursor::moveTo(0, 0);
echo "hi" ;
Hoa\Console\Cursor::moveTo(10,10);
echo "ho" ;
Hoa\Console\Cursor::moveTo(20, 20);
echo "hu" ;

will echo :
hihohu

I would be happy to help debugging.

Escape command, options and line builder in Processus

Hello :-),

Hoa\Console\Processus automatically escape command and options. Moreover, when building the command line, it adds a = between the option name and the option value. See

Console/Processus.php

Lines 963 to 1035 in 26092d3

/**
* Set command name.
*
* @access protected
* @param string $command Command name.
* @return string
*/
protected function setCommand ( $command ) {
$old = $this->_command;
$this->_command = escapeshellcmd($command);
return $old;
}
/**
* Get command name.
*
* @access public
* @return string
*/
public function getCommand ( ) {
return $this->_command;
}
/**
* Set command options.
*
* @access protected
* @param array $options Options (option => value, or input).
* @return array
*/
protected function setOptions ( Array $options ) {
foreach($options as &$option)
$option = escapeshellarg($option);
$old = $this->_options;
$this->_options = $options;
return $old;
}
/**
* Get options.
*
* @access public
* @return array
*/
public function getOptions ( ) {
return $this->_options;
}
/**
* Get command-line.
*
* @access public
* @return string
*/
public function getCommandLine ( ) {
$out = $this->getCommand();
foreach($this->getOptions() as $key => $value)
if(!is_int($key))
$out .= ' ' . $key . '=' . $value;
else
$out .= ' ' . $value;
return $out;
}
.

In some case, this behavior is not desired. For instance, with atoum, when we build the command, we don't use the $options because = will be inserted and atoum does not support them. The solution is to pass the whole command line in $command, with the options. It's fine, this is how to deal with it.
However, because Processus automatically escape the command, sometimes, it is not what we expect because escaping can create invalid command. Example: --filter 'class = "foo"' becomes --filter 'class = \"foo\"'.

2 solutions:

  1. we tell the users of this behavior in the documentation and we advice to extend Processus and override the setCommand method,
  2. we add one or more arguments in the constructor to disable the escaping.

Thoughts? /cc @hoaproject/hoackers


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Not installable with composer

$ composer require hoa/websocket:dev-master
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for hoa/websocket dev-master -> satisfiable by hoa/websocket[dev-master].
    - hoa/websocket dev-master requires hoa/core dev-master -> no matching package found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Root composer.json requires hoa/file dev-master -> satisfiable by hoa/file[dev-master].
    - hoa/file dev-master requires hoa/iterator dev-master -> found hoa/iterator[dev-master, 2.x-dev (alias of dev-master)] but it does not match your minimum-stability.
  Problem 2
    - Root composer.json requires hoa/test dev-master -> satisfiable by hoa/test[dev-master].
    - hoa/test dev-master requires hoa/cli dev-master -> found hoa/cli[dev-master, 3.x-dev (alias of dev-master)] but it does not match your minimum-stability.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Table component

Are there any plans in to include a table renderer in this library? The Symfony one is good for most use cases, but is limited if you want to do anything advanced. For example, the following features would be useful:

  • Colspan.
  • Border formatting (on cells, rows, columns or the table).
  • Padding.
  • Specify widths in percentages (on cells, columns, or the table).
  • Auto wrap text OR truncate text depending on cell size.

Console and Windows

Hi guys :-D

I am here to explain my problem on windows with use Hoa\Console.
In introduction I use two console application, the basic cmd.exe and cmder and i run same script on each console application.

Cmd

Cmd output

In addition the command

C:\www\launchee-cli>C:\cmder\php\php.exe vendor\hoa\core\Bin\hoa console:termcap --count max_color
0

Cmder

Cmder output

for avoid this error I need to use this code unset($_SERVER['TERM'])

Cmder output

In addition the command (with unset $_SERVER['term'] ofc)

λ php vendor\hoa\core\Bin\hoa console:termcap --count max_color
0

IMHO forget console windows are not an good idea 👍 and other do this (like composer, or sf2) => and its not an troll unleashing 💃

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Root composer.json requires hoa/file dev-master -> satisfiable by hoa/file[dev-master].
    - hoa/file dev-master requires hoa/iterator dev-master -> found hoa/iterator[dev-master, 2.x-dev (alias of dev-master)] but it does not match your minimum-stability.
  Problem 2
    - Root composer.json requires hoa/test dev-master -> satisfiable by hoa/test[dev-master].
    - hoa/test dev-master requires hoa/cli dev-master -> found hoa/cli[dev-master, 3.x-dev (alias of dev-master)] but it does not match your minimum-stability.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Autocompletion forgets counting extra spaces

The autocompletion is OK while I'm typing a word. My word is completed, then I continue at the end.
I always add a space if my command has some words.

But if I typed a first word and the following space (or more) then I type "tab": my extra space is remove.
If I type again on "tab" the first letter of the previous word will be duplicate.

I guess LineLength is not updated when the autocompleter remove the ending space chars.
Moreover I would like one extra space after the autocompleted word ;)

Features not Windows compatible

I've tested Console/Cursor & Console/Window under Windows 7 64 bits with PHP 5.4.5 and Hoa master (hoaproject/Central@d247435).

Here is the list of methods that doesn't work :

Hoa\Console\Cursor::move
Hoa\Console\Cursor::moveTo
Hoa\Console\Cursor::clear
Hoa\Console\Cursor::scroll
Hoa\Console\Cursor::hide
Hoa\Console\Cursor::show
Hoa\Console\Cursor::getPosition
Hoa\Console\Cursor::setStyle

so the only method working is bip() for Hoa\Console\Cursor !!

Hoa\Console\Window::setSize
Hoa\Console\Window::moveTo
Hoa\Console\Window::getPosition
Hoa\Console\Window::minimize
Hoa\Console\Window::setTitle
Hoa\Console\Window::getTitle
Hoa\Console\Window::getLabel
Hoa\Console\Window:resize (event)

so the only method working is getSize() for Hoa\Console\Window !!

Processus::run does not work on Windows

See hoaproject/Test#83 (comment).

For the records, my message:

Can you test those two examples and tell me which one works or not.

Example 1:

$processus = new Hoa\Console\Processus('ls');
$processus->open();
echo $processus->readAll();

Example 2:

$processus = new Hoa\Console\Processus('ls');
$processus->on('output', function (Hoa\Event\Bucket $bucket) {
    $data = $bucket->getData();
    echo '> ', $data['line'], "\n";
});
$processus->run();

Thanks!

The reply:

Test Nr.1:

CHANGELOG.md
Client.php
Connection
Exception
Node.php
Processus.php
README.md
Server.php
Socket.php
Test
Transport.php
composer.json
composer.lock
test.sh
vendor

Test Nr.2:

PHP Warning:  Invalid argument supplied for foreach() in D:\lukas\Coding\PhpstormProjects\Hoaproject\Socket\vendor\hoa\console\Processus.php on line 460

Warning: Invalid argument supplied for foreach() in D:\lukas\Coding\PhpstormProjects\Hoaproject\Socket\vendor\hoa\console\Processus.php on line 460

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Window::getSize() => tput: unknown terminfo capability 'cols\nlines'

Hello,

I have the error :

tput: unknown terminfo capability 'cols\nlines'

Here is the code to reproduce the error :

<?php
require 'vendor/autoload.php';
var_dump(Hoa\Console\Window::getSize());

I use the package php5-cli on debian 7.5. The PHP Version => 5.4.4-14+deb7u9

I use a local tmux -> ssh -> zsh 4.3.17

The fallowing command is working :

$ echo "cols\nlines" | tput -S
272
91

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for hoa/file dev-master -> satisfiable by hoa/file[dev-master].
    - hoa/file dev-master requires hoa/iterator dev-master -> satisfiable by hoa/iterator[dev-master] but these conflict with your requirements or minimum-stability.
  Problem 2
    - Installation request for hoa/test dev-master -> satisfiable by hoa/test[dev-master].
    - hoa/test dev-master requires hoa/cli dev-master -> satisfiable by hoa/cli[dev-master] but these conflict with your requirements or minimum-stability.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

You can mention @dependabot in the comments below to contact the Dependabot team.

Enhancements

Hoa\Console\Cursor::move('← ← ← ↑ ↑');
Hoa\Console\Cursor::move('↓'); // move below
Hoa\Console\Cursor::clear('↔'); // clear the line

Can you guys please change (←,↑,↔) to use words than using symbols. There is no way i can find those keys in my keyboard. I dont use a Mac.

Edit: My mistake, didnt check "For example, we can use l, left or ← to move the cursor on the left column. Thus we move the cursor to the left 3 times and then to the top 2 times:"

Detect when we are running in screen

I don't actually know if screen may cause similar bugs as tmux but perhaps it might be useful to check if we are running in it.

Just like we did for tmux with Console::isTmuxRunning I think we should introduce Console::isScreenRunning.

Even if adapting escape sequences is not required when we are in screen I think this method will still be useful for developers to know from their code if the users is inside a multiplexer.

See here for the original discussion: #53 (comment)


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Proposal: Introduce an `Output` class

Now

We use echo to print strings on the output of the current program.

Issue

Sometimes we don't want to echo but get the output, compute it somewhere with something and delegate the output. For instance, with the Symfony console bridge official contribution, we plug to the Symfony console output object (/cc @jubianchi).

Another issue happens recently with #52. TMUX(1) has some issues with specific control sequences. There is a solution to by-pass TMUX(1) and send control sequences to the upper terminal directly, see #53 for more explanation.

Proposal

We must introduce an output object. How though? This is a coding design discussion.

Output class and object

I would go for a static Output class and use it everywhere instead of echo but this is no easily extensible, nor testable. So we should for an object instead of a class. We do not want to create one instance each time we call the cursor or window API, this would increase memory. Since #51 introduces Console::getStdin, we can imagine introducing Console::getStdout and compute an instance of Output. To be able to extend Hoa\Console to delegate outputs, we can imagine Console::setStdout(Output $output).

What interface Output implements?

Thus, all echos could be replaced by Console::getStdout()->writeAll(). Why writeAll? This is the typical naming from Hoa\Stream interfaces. But I am not likely to implement the Hoa\Stream\IStream\Out interface right now. Or maybe I would be likely. This is one more dependency and it requires to implement write, writeLine etc. It makes a lot of sense!

However, what is the impact of adding a new dependency? Hoa\Stream is almost always a dependency, except if our program does not need any external resources (like files, sockets & co.), which is very rare. So I would argue that adding this dependency will not hurt anyone.

Conclusion

I would like the opinion of several @hoaproject/hoackers please.

Appendix A

Here is a draft for the Output object:

use Hoa\Stream;

class Output implements Stream\IStream\Out
{
    public function write($string, $length)
    {
        echo $string;
    }

    public function writeAll($string)
    {
        return $this->write($string, strlen($length));
    }

    …
}

Here is a draft for the new Hoa\Console methods:

class Console
{
    …

    protected $_output = null;

    public static function setOutput(Output $output)
    {
        $old = static::$_output;
        static::$_output = $output;

        return $old;
    }

    public static function getOutput()
    {
        if (null === static::$_output) {
            static::$_output = new Output();
        }

        return static::$_output;
    }
}
Bonus with outputs and redirection

How to implement redirections (rhetorical question)? Either we add an argument to the Output class constructor representing a stream or a resource, or because we are using Hoa\Stream\IStream\Out, we can do this:

use Hoa\Stream;

class Console
{
    …

    public function setOutput(Stream\IStream\Out $output)
    {
        …
   }

    …
}

and then:

Hoa\Console::setOutput(new Hoa\File\Write('/tmp/a'));

to redirect all outputs to the /tmp/a file!

Tip: Using echo is strictly equivalent to Hoa\Console::setOutput(new Hoa\File\Write(1));, which is equivalent to Hoa\Console::setOutput(new Hoa\File\Write('php://fd/1'));, which is equivalent to Hoa\Console::setOutput(new Hoa\File\Write('php://output'));.

Next

  1. We must open an issue to add a new method on Output like enableDemultiplexerByPassing. This will re-solve #53 more elegantly.
  2. We can imagine introducing an Input class? Not sure. Need more grooming.

[Question] How to run a Hoa\Console\Processus in the background or in non blocking mode

Hello !

I'm currently trying to build a worker launcher. I already run the process using something like :

$processus = new Processus(
    $script,
    $options
);
$processus->run();

The latest instruction block execution. I want to be able to :

  • run multiple processus in a loop ;
  • then listen event on each ;
  • know when execution is done.

Do you think it's possible with Hoa\Console package ? Maybe I lack some knowledge around process execution 😄

Thanks for your help !

Can not install via composer?

Hey there, maybe I'm totaly stupid, but I can not install hoa/console via composer.
I tried the following plain composer.json files.

{
    "minimum-stability": "dev",
    "require": {
        "hoa/console": "dev-master"
    }   
}

and

{
    "minimum-stability": "dev",
    "require": {
        "hoa/console": "1.14.09.16"
    }   
}

and

{
    "require": {
        "hoa/console": "1.14.09.16"
    }   
}

and all are resulting in the same composer error output.

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: hoa/core[dev-master, 1.14.09.16].
    - hoa/string 1.14.09.16 requires hoa/core dev-master -> satisfiable by hoa/core[dev-master].
    - hoa/console dev-master requires hoa/core ~1.0 -> satisfiable by hoa/core[1.14.09.16].
    - hoa/console dev-master requires hoa/string ~1.0 -> satisfiable by hoa/string[1.14.09.16].
    - Installation request for hoa/console dev-master -> satisfiable by hoa/console[dev-master].

I'm sorry when I'm opening an issue which is none, but I've no idea what I'm doing wronge here :-(.

Console bug with suppr and Autocompleter

When we push 2 times tab to got the following list and push "suppr" we quit the list and the cursor don't move as expected.

bug reproduce :

require 'vendor/autoload.php';


 $read = new Hoa\Console\Readline\Readline();

 $read->setAutocompleter(new Hoa\Console\Readline\Autocompleter\Word(
     get_defined_functions()['internal']
 ));



 do {
     $line = $read->readLine('> ');
     echo $line.PHP_EOL;
 } while (false !== $line && 'quit' != $line);

We can even delete "> " with the keybord

bug in readline and ctrl + a

I test the code in http://hoa-project.net/Literature/Hack/Console.html#Usage_basique:

<?php

require 'vendor/autoload.php';

$rl = new Hoa\Console\Readline\Readline();

do {

    $line = $rl->readLine('> ');
    echo '< ', $line, "\n\n";

} while(false !== $line && 'quit' !== $line);

After the prompt, I type some characters then I press CTRL+a.
The cursor go just over ">".
From there, all I can press was written in first character and delete previous character

Unfortunately, I can't reproduce it...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.