(stdscr, prompt, default='')
| 256 | |
| 257 | |
| 258 | def curses_input(stdscr, prompt, default=''): |
| 259 | curses.curs_set(1) |
| 260 | h,w = stdscr.getmaxyx() |
| 261 | inp = list(default) |
| 262 | pos = len(inp) |
| 263 | while True: |
| 264 | stdscr.erase() |
| 265 | centered_addstr(stdscr, h//2 - 2, prompt) |
| 266 | disp = ''.join(inp) |
| 267 | x = max(0, (w - len(disp)) // 2) |
| 268 | try: |
| 269 | stdscr.addstr(h//2, x, disp[:w-2]) |
| 270 | except Exception: |
| 271 | pass |
| 272 | stdscr.move(h//2, x + pos) |
| 273 | stdscr.refresh() |
| 274 | ch = stdscr.getch() |
| 275 | if ch in (10,13): |
| 276 | curses.curs_set(0) |
| 277 | return disp |
| 278 | elif ch in (27,): |
| 279 | curses.curs_set(0) |
| 280 | return None |
| 281 | elif ch in (curses.KEY_BACKSPACE, 127, 8): |
| 282 | if pos > 0: |
| 283 | inp.pop(pos-1) |
| 284 | pos -= 1 |
| 285 | elif ch == curses.KEY_LEFT: |
| 286 | pos = max(0, pos-1) |
| 287 | elif ch == curses.KEY_RIGHT: |
| 288 | pos = min(len(inp), pos+1) |
| 289 | elif 0 <= ch <= 255: |
| 290 | inp.insert(pos, chr(ch)) |
| 291 | pos += 1 |
| 292 | |
| 293 | |
| 294 | def curses_select_from_list(stdscr, title, options, start_index=0): |
no test coverage detected