bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

[Query] Validator for Input #72

Open Ccortina opened 3 years ago

Ccortina commented 3 years ago

Hi , im trying to extend the "Input" class to add a simple folder path validator, but the code seems to be ignoring my accept and valid methods. What am I doing wrong?

from bullet import Input, keyhandler, styles
from bullet.charDef import NEWLINE_KEY
import os.path

class FolderPathCheck(Input):

    @keyhandler.register(NEWLINE_KEY)
    def accept(self):
        if self.valid():
            return super.accept()

    def valid(self, ans):
        return os.path.isdir(self.ans)

Thanks.

a-luna commented 3 years ago

super is a function, so accept should return super().accept() NOT super.accept() (notice the parentheses after both super and accept.

Hope that helps!