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

Support for confirmation lines? #709

Open
jhtgiles opened this issue Sep 14, 2020 · 2 comments
Open

Support for confirmation lines? #709

jhtgiles opened this issue Sep 14, 2020 · 2 comments
Labels
feature request Requested feature

Comments

@jhtgiles
Copy link

I've looked through the docs and so far as I can tell there isn't something like:

terminal.pushToStdoutWithResponse('Would you like to play a game? [Y/N]: ').

Is this something that's available that I've just missed or would this need to be a code change to accomodate?

@linuswillner
Copy link
Owner

No, currently there's no support for something like readline.question() from Node. I'll consider implementing something like this in the future though, if it's feasible to do so.

@linuswillner linuswillner added the feature request Requested feature label Feb 12, 2021
@Aivean
Copy link

Aivean commented Jun 25, 2021

I was about to open the similar feature request, but I found a workaround. The idea is to have terminal commands as the part of the parent component's state, and override it as necessary.

Here is an example:

class TerminalWrapper extends React.Component {
    constructor(props) {
        super(props);
        this.commands = {
            prompt: {
                fn: () => {
                    this.setState({
                        prompt: {
                            welcomeMessage: 'Prompt Y/n',
                            commands: {
                                'Y': {
                                    fn: () => {
                                        // ...
                                        this.setState({prompt: false})
                                        return "Y"
                                    }
                                },
                                'n': {
                                    fn: () => {
                                        // ...
                                        this.setState({prompt: false})
                                        return "n"
                                    }
                                }
                            }
                        }
                    })
                    return "Prompt Y/n"
                }
            }
        }
    }

    render() {
        return (
            <Terminal
                commands={this.state.prompt ? this.state.prompt.commands : this.commands}
                welcomeMessage={this.state.prompt ? this.state.prompt.welcomeMessage : 'Default welcome message'}
            />
        )
    }
}

By carefully managing the parent component's state, interactions of arbitrary complexity can be programmed. Hope this helps.

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

No branches or pull requests

3 participants