+
Skip to content

read inputs silently #102

@ja0x01

Description

@ja0x01

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载