| 273 | |
| 274 | |
| 275 | class ReorderBullet(Bullet): |
| 276 | |
| 277 | def __init__(self, prompt: str = "", choices: list = None, choices_id: list = None, bullet: str = "●", |
| 278 | bullet_color: str = colors.foreground["default"], word_color: str = colors.foreground["default"], |
| 279 | word_on_switch: str = colors.REVERSE, background_color: str = colors.background["default"], |
| 280 | background_on_switch: str = colors.REVERSE, pad_right=0, indent: int = 0, align=0, margin: int = 0, |
| 281 | shift: int = 0, required: bool = False): |
| 282 | if choices is None: |
| 283 | choices = [] |
| 284 | if choices_id is None: |
| 285 | choices_id = [] |
| 286 | prompt += "\n" + _( |
| 287 | "[ =: Shift up; -: Shift down; Backspace: Remove ]" |
| 288 | ) |
| 289 | choices.extend(( |
| 290 | _("+ Add"), |
| 291 | _("✓ Submit") |
| 292 | )) |
| 293 | super().__init__(prompt, choices, bullet, bullet_color, word_color, word_on_switch, background_color, |
| 294 | background_on_switch, pad_right, indent, align, margin, shift) |
| 295 | self.choices_id = choices_id |
| 296 | self.choices_id.extend(( |
| 297 | "add", |
| 298 | "submit" |
| 299 | )) |
| 300 | self._key_handler: Dict[int, Callable] = self._key_handler.copy() |
| 301 | self._key_handler[NEWLINE_KEY] = self.__class__.accept_fork |
| 302 | self.required = required |
| 303 | |
| 304 | @keyhandler.register(ord('-')) |
| 305 | def shift_up(self): |
| 306 | choices = len(self.choices) |
| 307 | if self.pos - 1 < 0 or self.pos >= choices - 2: |
| 308 | return |
| 309 | else: |
| 310 | self.choices[self.pos - 1], self.choices[self.pos] = self.choices[self.pos], self.choices[self.pos - 1] |
| 311 | bullet.utils.clearLine() |
| 312 | old_pos = self.pos |
| 313 | self.pos -= 1 |
| 314 | self.printBullet(old_pos) |
| 315 | bullet.utils.moveCursorUp(1) |
| 316 | bullet.utils.clearLine() |
| 317 | self.printBullet(self.pos) |
| 318 | |
| 319 | @keyhandler.register(ord('=')) |
| 320 | def shift_down(self): |
| 321 | choices = len(self.choices) |
| 322 | if self.pos >= choices - 3: |
| 323 | return |
| 324 | else: |
| 325 | self.choices[self.pos + 1], self.choices[self.pos] = self.choices[self.pos], self.choices[self.pos + 1] |
| 326 | bullet.utils.clearLine() |
| 327 | old_pos = self.pos |
| 328 | self.pos += 1 |
| 329 | self.printBullet(old_pos) |
| 330 | bullet.utils.moveCursorDown(1) |
| 331 | bullet.utils.clearLine() |
| 332 | self.printBullet(self.pos) |
no outgoing calls
no test coverage detected