diff --git a/bullet/client.py b/bullet/client.py index be3b061..68f06ab 100644 --- a/bullet/client.py +++ b/bullet/client.py @@ -9,12 +9,12 @@ # Reusable private utility class class myInput: - def __init__(self, - word_color: str = colors.foreground["default"], - password: bool = False, + def __init__(self, + word_color: str = colors.foreground["default"], + password: bool = False, hidden: str = '*' ): - ''' Constructor for myInput + ''' Constructor for myInput Args: word_color: color of input characters. password: Whether input is password. @@ -97,8 +97,8 @@ def input(self): self.deleteChar() elif i == ARROW_RIGHT_KEY: self.moveCursor(self.pos + 1) - elif i == ARROW_LEFT_KEY: - self.moveCursor(self.pos - 1) + elif i == INTERRUPT_KEY: + raise KeyboardInterrupt else: if self.password: if c != ' ': @@ -109,10 +109,10 @@ def input(self): @keyhandler.init class Bullet: def __init__( - self, + self, prompt: str = "", - choices: list = [], - bullet: str = "●", + choices: list = [], + bullet: str = "●", bullet_color: str = colors.foreground["default"], word_color: str = colors.foreground["default"], word_on_switch: str = colors.REVERSE, @@ -153,12 +153,12 @@ def __init__( self.max_width = len(max(self.choices, key = len)) + self.pad_right self.return_index = return_index - + def renderBullets(self): for i in range(len(self.choices)): self.printBullet(i) utils.forceWrite('\n') - + def printBullet(self, idx): utils.forceWrite(' ' * (self.indent + self.align)) back_color = self.background_on_switch if idx == self.pos else self.background_color @@ -230,10 +230,10 @@ def launch(self, default = None): @keyhandler.init class Check: def __init__( - self, + self, prompt: str = "", - choices: list = [], - check: str = "√", + choices: list = [], + check: str = "√", check_color: str = colors.foreground["default"], check_on_switch: str = colors.REVERSE, word_color: str = colors.foreground["default"], @@ -277,12 +277,12 @@ def __init__( self.max_width = len(max(self.choices, key = len)) + self.pad_right self.return_index = return_index - + def renderRows(self): for i in range(len(self.choices)): self.printRow(i) utils.forceWrite('\n') - + def printRow(self, idx): utils.forceWrite(' ' * (self.indent + self.align)) back_color = self.background_on_switch if idx == self.pos else self.background_color @@ -408,10 +408,10 @@ def launch(self): class Input: def __init__( - self, + self, prompt, default = "", - indent = 0, + indent = 0, word_color = colors.foreground["default"], strip = False, pattern = "" @@ -424,7 +424,7 @@ def __init__( self.word_color = word_color self.strip = strip self.pattern = pattern - + def valid(self, ans): if ans is None: return False @@ -461,10 +461,10 @@ def launch(self): class Password: def __init__( - self, - prompt, - indent = 0, - hidden = '*', + self, + prompt, + indent = 0, + hidden = '*', word_color = colors.foreground["default"] ): self.indent = indent @@ -473,16 +473,16 @@ def __init__( self.prompt = prompt self.hidden = hidden self.word_color = word_color - + def launch(self): utils.forceWrite(' ' * self.indent + self.prompt) return myInput(password = True, hidden = self.hidden, word_color = self.word_color).input() class Numbers: def __init__( - self, - prompt, - indent = 0, + self, + prompt, + indent = 0, word_color = colors.foreground["default"], type = float ): @@ -492,7 +492,7 @@ def __init__( self.prompt = prompt self.word_color = word_color self.type = type - + def valid(self, ans): try: self.type(ans) @@ -503,7 +503,7 @@ def valid(self, ans): utils.forceWrite(' ' * len(ans)) utils.forceWrite('\b' * len(ans)) return False - + def launch(self, default = None): if default is not None: try: @@ -523,9 +523,9 @@ def launch(self, default = None): class VerticalPrompt: def __init__( - self, - components, - spacing = 1, + self, + components, + spacing = 1, separator = "", separator_color = colors.foreground["default"] ): @@ -542,7 +542,7 @@ def __init__( def summarize(self): for prompt, answer in self.result: print(prompt, answer) - + def launch(self): for ui in self.components: self.result.append((ui.prompt, ui.launch())) @@ -555,9 +555,9 @@ def launch(self): @keyhandler.init class ScrollBar: def __init__( - self, + self, prompt: str = "", - choices: list = [], + choices: list = [], pointer = "→", up_indicator: str = "↑", down_indicator: str = "↓", @@ -613,7 +613,7 @@ def __init__( # scrollbar moves down if pos > top + height - 1 self.return_index = return_index - + def renderRows(self): self.printRow(self.top, indicator = self.up_indicator if self.top != 0 else '') utils.forceWrite('\n') @@ -626,7 +626,7 @@ def renderRows(self): if i < len(self.choices) - 1: self.printRow(i + 1, indicator= self.down_indicator if self.top + self.height != len(self.choices) else '') utils.forceWrite('\n') - + def printRow(self, idx, indicator=''): utils.forceWrite(' ' * (self.indent + self.align)) back_color = self.background_on_switch if idx == self.pos else self.background_color @@ -711,7 +711,7 @@ def launch(self): class SlidePrompt: def __init__( - self, + self, components ): self.idx = 0