(stdscr, title, content)
| 401 | |
| 402 | # View note |
| 403 | def view_note_curses(stdscr, title, content): |
| 404 | try: |
| 405 | h,w = stdscr.getmaxyx() |
| 406 | stdscr.clear() |
| 407 | if not isinstance(content, str): |
| 408 | try: |
| 409 | content = json.dumps(content, indent=2, ensure_ascii=False) |
| 410 | except Exception: |
| 411 | content = str(content) |
| 412 | lines = content.split('\n') |
| 413 | pos = 0 |
| 414 | while True: |
| 415 | stdscr.erase() |
| 416 | centered_addstr(stdscr, 1, f' {title} ') |
| 417 | for i in range(min(h-6, len(lines)-pos)): |
| 418 | try: |
| 419 | stdscr.addstr(3+i, 2, lines[pos+i][:w-4]) |
| 420 | except Exception: |
| 421 | pass |
| 422 | centered_addstr(stdscr, h-2, 'Up/Down scroll, B for back') |
| 423 | stdscr.refresh() |
| 424 | ch = stdscr.getch() |
| 425 | if ch == curses.KEY_DOWN: |
| 426 | if pos + (h-6) < len(lines): |
| 427 | pos += 1 |
| 428 | elif ch == curses.KEY_UP: |
| 429 | pos = max(0, pos-1) |
| 430 | elif ch in (ord('b'), ord('B'), 27): |
| 431 | return |
| 432 | except Exception as e: |
| 433 | log_exception(e) |
| 434 | error_dialog(stdscr, 'View error', traceback.format_exc()) |
| 435 | |
| 436 | # Actions for note |
| 437 | def action_for_note(stdscr, key, notes): |
no test coverage detected