package net.rubygrapefruit.platform.prompts;

class YesNoListener extends AbstractListener {
    private final boolean defaultValue;
    private Boolean selected;
    private boolean finished;

    YesNoListener(boolean defaultValue) {
        this.defaultValue = defaultValue;
    }

    public boolean isFinished() {
        return finished;
    }

    public Boolean getSelected() {
        return selected;
    }

    @Override
    public void character(char ch) {
        if (ch == 'y') {
            selected = true;
            finished = true;
        } else if (ch == 'n') {
            selected = false;
            finished = true;
        }
    }

    @Override
    public void controlKey(Key key) {
        if (key == Key.Enter) {
            selected = defaultValue;
            finished = true;
        }
    }

    @Override
    public void endInput() {
        finished = true;
    }
}

@@ -483,16 +483,29 @@
 h == 'y'
+ %7C%7C ch == 'Y'
 ) %7B%0A    
@@ -586,16 +586,29 @@
 h == 'n'
+ %7C%7C ch == 'N'
 ) %7B%0A    

Allow 'Y' and 'N' (upper case) as a response for a yes/no question.