(stdscr, key, notes)
| 435 | |
| 436 | # Actions for note |
| 437 | def action_for_note(stdscr, key, notes): |
| 438 | try: |
| 439 | h,w = stdscr.getmaxyx() |
| 440 | while True: |
| 441 | stdscr.erase() |
| 442 | centered_addstr(stdscr, 1, f' Note: {key} ') |
| 443 | content = notes.get(key, '') |
| 444 | if not isinstance(content, str): |
| 445 | try: |
| 446 | preview_text = json.dumps(content, indent=2, ensure_ascii=False) |
| 447 | except Exception: |
| 448 | preview_text = str(content) |
| 449 | else: |
| 450 | preview_text = content |
| 451 | preview = preview_text.split('\n')[:10] |
| 452 | for i,line in enumerate(preview): |
| 453 | try: |
| 454 | stdscr.addstr(3+i, 2, line[:w-4]) |
| 455 | except Exception: |
| 456 | pass |
| 457 | centered_addstr(stdscr, h-4, 'V: View E: Edit D: Delete B: Back') |
| 458 | stdscr.refresh() |
| 459 | ch = stdscr.getch() |
| 460 | if ch in (ord('v'), ord('V')): |
| 461 | view_note_curses(stdscr, key, content) |
| 462 | elif ch in (ord('e'), ord('E')): |
| 463 | initial = preview_text if isinstance(content, (dict, list)) else str(content) |
| 464 | new = curses_editor(stdscr, initial) |
| 465 | if new is not None: |
| 466 | notes[key] = new |
| 467 | save_notes(notes) |
| 468 | elif ch in (ord('d'), ord('D')): |
| 469 | confirmed = confirm_dialog(stdscr, f'Delete note "{key}"?') |
| 470 | if confirmed: |
| 471 | notes.pop(key, None) |
| 472 | save_notes(notes) |
| 473 | return |
| 474 | elif ch in (ord('b'), ord('B'), 27): |
| 475 | return |
| 476 | except Exception as e: |
| 477 | log_exception(e) |
| 478 | error_dialog(stdscr, 'Note action error', traceback.format_exc()) |
| 479 | |
| 480 | # Add note (curses) |
| 481 | def add_note_curses(stdscr): |
no test coverage detected