Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read inputs silently #102

Open
joaomarcelogomes opened this issue Nov 1, 2023 · 0 comments
Open

read inputs silently #102

joaomarcelogomes opened this issue Nov 1, 2023 · 0 comments

Comments

@joaomarcelogomes
Copy link

joaomarcelogomes commented Nov 1, 2023

I am using minicli to develop a proof of concept, and I came across the need to read an input silently, as it is used to capture a password value. I had the idea of having a way to enable silent input reading in the framework. I imagine the implementation will be extremely straightforward and would like to bring this topic for discussion.
I believe we may only need a new method to read inputs without outputting what's being typed, where we can run a 'stty -echo' before getting the input and a 'stty echo' after getting the input.
Something like this:

    // ON Input.php
    public function read(bool $silently = false): string
    {
        $input = (string) $silently ? $this->readInputSilently() : readline($this->getPrompt());

        $this->inputHistory[] = $input;

        return $input;
    }

    private function readInputSilently(): string
    {
        echo $this->getPrompt();

        system('stty -echo');
        $input = trim(fgets(STDIN));
        system('stty echo');

        return $input;
    }

If it is approved for implementation, may I proceed with it?

P.S. I apologize if this is not the correct way to open an issue seeking improvement; I am relatively new to contributing to the community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant