repl-toolkit 2.0.3__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {repl_toolkit-2.0.3/repl_toolkit.egg-info → repl_toolkit-2.2.0}/PKG-INFO +146 -2
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/README.md +145 -1
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/pyproject.toml +1 -1
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/__init__.py +15 -11
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/actions/registry.py +14 -30
- repl_toolkit-2.2.0/repl_toolkit/async_repl.py +434 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/headless_repl.py +5 -1
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/images.py +47 -1
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/ptypes.py +50 -19
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_async_repl.py +6 -6
- repl_toolkit-2.2.0/repl_toolkit/tests/test_cancellation.py +277 -0
- repl_toolkit-2.2.0/repl_toolkit/tests/test_output_handling.py +325 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0/repl_toolkit.egg-info}/PKG-INFO +146 -2
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit.egg-info/SOURCES.txt +2 -0
- repl_toolkit-2.0.3/repl_toolkit/async_repl.py +0 -514
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/LICENSE +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/actions/__init__.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/actions/action.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/completion/__init__.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/completion/prefix.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/completion/shell_expansion.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/formatting.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/__init__.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/conftest.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_actions.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_completion.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_ctrl_c_cancel.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_formatting.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_headless.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_image_utils.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_images.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit/tests/test_types.py +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit.egg-info/dependency_links.txt +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit.egg-info/requires.txt +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/repl_toolkit.egg-info/top_level.txt +0 -0
- {repl_toolkit-2.0.3 → repl_toolkit-2.2.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: repl-toolkit
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: A Python toolkit for building interactive REPL and headless interfaces with action support
|
|
5
5
|
Author-email: REPL Toolkit Contributors <martin.j.bartlett@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -404,11 +404,13 @@ registry.register_action(action)
|
|
|
404
404
|
|
|
405
405
|
Every REPL includes these by default:
|
|
406
406
|
|
|
407
|
-
|
|
407
|
+
| Command | Shortcut | Description |
|
|
408
|
+
|---------|----------|-------------|
|
|
408
409
|
| `/help [action]` | `F1` | Show help for all actions or a specific one |
|
|
409
410
|
| `/shortcuts` | - | List all keyboard shortcuts |
|
|
410
411
|
| `/exit` or `/quit` | - | Exit the application |
|
|
411
412
|
| `/paste` | `F6` | Paste image or text from clipboard |
|
|
413
|
+
| - | `F7` or `Escape, Escape` | Clear the input buffer |
|
|
412
414
|
|
|
413
415
|
Commands execute immediately when you press Enter. For normal text messages, press Alt+Enter to send.
|
|
414
416
|
|
|
@@ -622,6 +624,148 @@ python examples/image_paste_demo.py
|
|
|
622
624
|
python examples/completion_demo.py
|
|
623
625
|
```
|
|
624
626
|
|
|
627
|
+
## Implementing Cancellable Backends
|
|
628
|
+
|
|
629
|
+
Backends can optionally implement cooperative cancellation to gracefully handle cancellation of long-running operations, especially those involving blocking I/O like subprocess calls or HTTP requests.
|
|
630
|
+
|
|
631
|
+
### Basic Implementation
|
|
632
|
+
|
|
633
|
+
```python
|
|
634
|
+
from typing import Optional
|
|
635
|
+
|
|
636
|
+
class CancellableBackend:
|
|
637
|
+
def __init__(self):
|
|
638
|
+
self._cancel_requested = False
|
|
639
|
+
|
|
640
|
+
def cancel(self, message: Optional[str] = None) -> None:
|
|
641
|
+
"""Optional method to support cooperative cancellation."""
|
|
642
|
+
self._cancel_requested = True
|
|
643
|
+
if message:
|
|
644
|
+
print(f"Cancellation: {message}")
|
|
645
|
+
|
|
646
|
+
async def handle_input(self, user_input: str, **kwargs) -> bool:
|
|
647
|
+
"""Process input with cancellation checkpoints."""
|
|
648
|
+
# Reset flag at start of each operation
|
|
649
|
+
self._cancel_requested = False
|
|
650
|
+
|
|
651
|
+
# Process in steps with cancellation checkpoints
|
|
652
|
+
for step in self._get_processing_steps(user_input):
|
|
653
|
+
# Check for cancellation at safe points
|
|
654
|
+
if self._cancel_requested:
|
|
655
|
+
print("Operation cancelled.")
|
|
656
|
+
return False
|
|
657
|
+
|
|
658
|
+
# Do work
|
|
659
|
+
await self._process_step(step)
|
|
660
|
+
|
|
661
|
+
return True
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
### When cancel() is Called
|
|
665
|
+
|
|
666
|
+
The REPL automatically calls `backend.cancel()` (if implemented) when:
|
|
667
|
+
- User presses **Alt+C** during operation
|
|
668
|
+
- User presses **Ctrl+C** during operation
|
|
669
|
+
- Exception occurs during processing
|
|
670
|
+
|
|
671
|
+
**Note**: The `cancel()` method is optional. Backends without it will fall back to async task cancellation only (via `asyncio.Task.cancel()`), which may not work for blocking operations.
|
|
672
|
+
|
|
673
|
+
### Example: Cancelling Subprocess
|
|
674
|
+
|
|
675
|
+
```python
|
|
676
|
+
import asyncio
|
|
677
|
+
import subprocess
|
|
678
|
+
from typing import Optional
|
|
679
|
+
|
|
680
|
+
class SubprocessBackend:
|
|
681
|
+
def __init__(self):
|
|
682
|
+
self._cancel_requested = False
|
|
683
|
+
self._current_process = None
|
|
684
|
+
|
|
685
|
+
def cancel(self, message: Optional[str] = None) -> None:
|
|
686
|
+
"""Cancel current subprocess."""
|
|
687
|
+
self._cancel_requested = True
|
|
688
|
+
if self._current_process:
|
|
689
|
+
self._current_process.terminate() # Stop the subprocess
|
|
690
|
+
|
|
691
|
+
async def handle_input(self, user_input: str, **kwargs) -> bool:
|
|
692
|
+
"""Run command with cancellation support."""
|
|
693
|
+
self._cancel_requested = False
|
|
694
|
+
|
|
695
|
+
try:
|
|
696
|
+
# Run subprocess in executor to avoid blocking
|
|
697
|
+
loop = asyncio.get_event_loop()
|
|
698
|
+
|
|
699
|
+
def run_command():
|
|
700
|
+
if self._cancel_requested:
|
|
701
|
+
return None
|
|
702
|
+
self._current_process = subprocess.Popen(
|
|
703
|
+
user_input.split(),
|
|
704
|
+
stdout=subprocess.PIPE,
|
|
705
|
+
stderr=subprocess.PIPE
|
|
706
|
+
)
|
|
707
|
+
stdout, stderr = self._current_process.communicate()
|
|
708
|
+
return stdout.decode()
|
|
709
|
+
|
|
710
|
+
result = await loop.run_in_executor(None, run_command)
|
|
711
|
+
|
|
712
|
+
if result is None:
|
|
713
|
+
print("Command cancelled.")
|
|
714
|
+
return False
|
|
715
|
+
|
|
716
|
+
print(result)
|
|
717
|
+
return True
|
|
718
|
+
|
|
719
|
+
finally:
|
|
720
|
+
self._current_process = None
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
### Guidelines for cancel() Implementation
|
|
724
|
+
|
|
725
|
+
1. **Non-blocking**: Method must return immediately
|
|
726
|
+
2. **Set flag**: Use internal flag that handle_input() checks
|
|
727
|
+
3. **Reset flag**: Clear at start of each operation
|
|
728
|
+
4. **Safe checkpoints**: Only check flag at safe cancellation points
|
|
729
|
+
5. **Cleanup**: Release resources when cancellation detected
|
|
730
|
+
|
|
731
|
+
## Action Output Best Practices
|
|
732
|
+
|
|
733
|
+
Actions in **interactive mode** automatically use prompt_toolkit's output functions to maintain clean prompt display. You don't need to do anything special - just use `context.printer`:
|
|
734
|
+
|
|
735
|
+
```python
|
|
736
|
+
def my_action(context: ActionContext):
|
|
737
|
+
# Recommended: Use context.printer
|
|
738
|
+
context.printer("This output maintains clean prompt display")
|
|
739
|
+
context.printer("Multiple lines work correctly")
|
|
740
|
+
|
|
741
|
+
# Also works: Standard print() is automatically patched
|
|
742
|
+
print("This also works and maintains prompt")
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
**Why this matters**: In interactive mode, standard `print()` can corrupt the prompt display. The toolkit automatically handles this by:
|
|
746
|
+
- Using `print_formatted_text()` for action output
|
|
747
|
+
- Wrapping the prompt in `patch_stdout()` to catch any print() calls
|
|
748
|
+
|
|
749
|
+
**Headless mode**: Continues to use standard `print()` (correct for logs/pipes).
|
|
750
|
+
|
|
751
|
+
### Formatted Output
|
|
752
|
+
|
|
753
|
+
Interactive mode supports rich formatting:
|
|
754
|
+
|
|
755
|
+
```python
|
|
756
|
+
from prompt_toolkit import HTML, ANSI
|
|
757
|
+
|
|
758
|
+
def formatted_action(context: ActionContext):
|
|
759
|
+
# HTML-style formatting
|
|
760
|
+
context.printer(HTML('<b>Bold</b> <green>Green</green>'))
|
|
761
|
+
|
|
762
|
+
# ANSI codes
|
|
763
|
+
context.printer(ANSI('\x1b[1mBold text\x1b[0m'))
|
|
764
|
+
|
|
765
|
+
# Plain text (always works)
|
|
766
|
+
context.printer('Plain text')
|
|
767
|
+
```
|
|
768
|
+
|
|
625
769
|
## Advanced Features
|
|
626
770
|
|
|
627
771
|
### Custom Action Context
|
|
@@ -359,11 +359,13 @@ registry.register_action(action)
|
|
|
359
359
|
|
|
360
360
|
Every REPL includes these by default:
|
|
361
361
|
|
|
362
|
-
|
|
362
|
+
| Command | Shortcut | Description |
|
|
363
|
+
|---------|----------|-------------|
|
|
363
364
|
| `/help [action]` | `F1` | Show help for all actions or a specific one |
|
|
364
365
|
| `/shortcuts` | - | List all keyboard shortcuts |
|
|
365
366
|
| `/exit` or `/quit` | - | Exit the application |
|
|
366
367
|
| `/paste` | `F6` | Paste image or text from clipboard |
|
|
368
|
+
| - | `F7` or `Escape, Escape` | Clear the input buffer |
|
|
367
369
|
|
|
368
370
|
Commands execute immediately when you press Enter. For normal text messages, press Alt+Enter to send.
|
|
369
371
|
|
|
@@ -577,6 +579,148 @@ python examples/image_paste_demo.py
|
|
|
577
579
|
python examples/completion_demo.py
|
|
578
580
|
```
|
|
579
581
|
|
|
582
|
+
## Implementing Cancellable Backends
|
|
583
|
+
|
|
584
|
+
Backends can optionally implement cooperative cancellation to gracefully handle cancellation of long-running operations, especially those involving blocking I/O like subprocess calls or HTTP requests.
|
|
585
|
+
|
|
586
|
+
### Basic Implementation
|
|
587
|
+
|
|
588
|
+
```python
|
|
589
|
+
from typing import Optional
|
|
590
|
+
|
|
591
|
+
class CancellableBackend:
|
|
592
|
+
def __init__(self):
|
|
593
|
+
self._cancel_requested = False
|
|
594
|
+
|
|
595
|
+
def cancel(self, message: Optional[str] = None) -> None:
|
|
596
|
+
"""Optional method to support cooperative cancellation."""
|
|
597
|
+
self._cancel_requested = True
|
|
598
|
+
if message:
|
|
599
|
+
print(f"Cancellation: {message}")
|
|
600
|
+
|
|
601
|
+
async def handle_input(self, user_input: str, **kwargs) -> bool:
|
|
602
|
+
"""Process input with cancellation checkpoints."""
|
|
603
|
+
# Reset flag at start of each operation
|
|
604
|
+
self._cancel_requested = False
|
|
605
|
+
|
|
606
|
+
# Process in steps with cancellation checkpoints
|
|
607
|
+
for step in self._get_processing_steps(user_input):
|
|
608
|
+
# Check for cancellation at safe points
|
|
609
|
+
if self._cancel_requested:
|
|
610
|
+
print("Operation cancelled.")
|
|
611
|
+
return False
|
|
612
|
+
|
|
613
|
+
# Do work
|
|
614
|
+
await self._process_step(step)
|
|
615
|
+
|
|
616
|
+
return True
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### When cancel() is Called
|
|
620
|
+
|
|
621
|
+
The REPL automatically calls `backend.cancel()` (if implemented) when:
|
|
622
|
+
- User presses **Alt+C** during operation
|
|
623
|
+
- User presses **Ctrl+C** during operation
|
|
624
|
+
- Exception occurs during processing
|
|
625
|
+
|
|
626
|
+
**Note**: The `cancel()` method is optional. Backends without it will fall back to async task cancellation only (via `asyncio.Task.cancel()`), which may not work for blocking operations.
|
|
627
|
+
|
|
628
|
+
### Example: Cancelling Subprocess
|
|
629
|
+
|
|
630
|
+
```python
|
|
631
|
+
import asyncio
|
|
632
|
+
import subprocess
|
|
633
|
+
from typing import Optional
|
|
634
|
+
|
|
635
|
+
class SubprocessBackend:
|
|
636
|
+
def __init__(self):
|
|
637
|
+
self._cancel_requested = False
|
|
638
|
+
self._current_process = None
|
|
639
|
+
|
|
640
|
+
def cancel(self, message: Optional[str] = None) -> None:
|
|
641
|
+
"""Cancel current subprocess."""
|
|
642
|
+
self._cancel_requested = True
|
|
643
|
+
if self._current_process:
|
|
644
|
+
self._current_process.terminate() # Stop the subprocess
|
|
645
|
+
|
|
646
|
+
async def handle_input(self, user_input: str, **kwargs) -> bool:
|
|
647
|
+
"""Run command with cancellation support."""
|
|
648
|
+
self._cancel_requested = False
|
|
649
|
+
|
|
650
|
+
try:
|
|
651
|
+
# Run subprocess in executor to avoid blocking
|
|
652
|
+
loop = asyncio.get_event_loop()
|
|
653
|
+
|
|
654
|
+
def run_command():
|
|
655
|
+
if self._cancel_requested:
|
|
656
|
+
return None
|
|
657
|
+
self._current_process = subprocess.Popen(
|
|
658
|
+
user_input.split(),
|
|
659
|
+
stdout=subprocess.PIPE,
|
|
660
|
+
stderr=subprocess.PIPE
|
|
661
|
+
)
|
|
662
|
+
stdout, stderr = self._current_process.communicate()
|
|
663
|
+
return stdout.decode()
|
|
664
|
+
|
|
665
|
+
result = await loop.run_in_executor(None, run_command)
|
|
666
|
+
|
|
667
|
+
if result is None:
|
|
668
|
+
print("Command cancelled.")
|
|
669
|
+
return False
|
|
670
|
+
|
|
671
|
+
print(result)
|
|
672
|
+
return True
|
|
673
|
+
|
|
674
|
+
finally:
|
|
675
|
+
self._current_process = None
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
### Guidelines for cancel() Implementation
|
|
679
|
+
|
|
680
|
+
1. **Non-blocking**: Method must return immediately
|
|
681
|
+
2. **Set flag**: Use internal flag that handle_input() checks
|
|
682
|
+
3. **Reset flag**: Clear at start of each operation
|
|
683
|
+
4. **Safe checkpoints**: Only check flag at safe cancellation points
|
|
684
|
+
5. **Cleanup**: Release resources when cancellation detected
|
|
685
|
+
|
|
686
|
+
## Action Output Best Practices
|
|
687
|
+
|
|
688
|
+
Actions in **interactive mode** automatically use prompt_toolkit's output functions to maintain clean prompt display. You don't need to do anything special - just use `context.printer`:
|
|
689
|
+
|
|
690
|
+
```python
|
|
691
|
+
def my_action(context: ActionContext):
|
|
692
|
+
# Recommended: Use context.printer
|
|
693
|
+
context.printer("This output maintains clean prompt display")
|
|
694
|
+
context.printer("Multiple lines work correctly")
|
|
695
|
+
|
|
696
|
+
# Also works: Standard print() is automatically patched
|
|
697
|
+
print("This also works and maintains prompt")
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
**Why this matters**: In interactive mode, standard `print()` can corrupt the prompt display. The toolkit automatically handles this by:
|
|
701
|
+
- Using `print_formatted_text()` for action output
|
|
702
|
+
- Wrapping the prompt in `patch_stdout()` to catch any print() calls
|
|
703
|
+
|
|
704
|
+
**Headless mode**: Continues to use standard `print()` (correct for logs/pipes).
|
|
705
|
+
|
|
706
|
+
### Formatted Output
|
|
707
|
+
|
|
708
|
+
Interactive mode supports rich formatting:
|
|
709
|
+
|
|
710
|
+
```python
|
|
711
|
+
from prompt_toolkit import HTML, ANSI
|
|
712
|
+
|
|
713
|
+
def formatted_action(context: ActionContext):
|
|
714
|
+
# HTML-style formatting
|
|
715
|
+
context.printer(HTML('<b>Bold</b> <green>Green</green>'))
|
|
716
|
+
|
|
717
|
+
# ANSI codes
|
|
718
|
+
context.printer(ANSI('\x1b[1mBold text\x1b[0m'))
|
|
719
|
+
|
|
720
|
+
# Plain text (always works)
|
|
721
|
+
context.printer('Plain text')
|
|
722
|
+
```
|
|
723
|
+
|
|
580
724
|
## Advanced Features
|
|
581
725
|
|
|
582
726
|
### Custom Action Context
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "repl-toolkit"
|
|
7
|
-
version = "2.0
|
|
7
|
+
version = "2.2.0"
|
|
8
8
|
description = "A Python toolkit for building interactive REPL and headless interfaces with action support"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -16,25 +16,28 @@ Basic usage:
|
|
|
16
16
|
>>> repl = AsyncREPL()
|
|
17
17
|
>>> await repl.run(MyBackend())
|
|
18
18
|
|
|
19
|
-
With
|
|
20
|
-
>>>
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
With cancellation support:
|
|
20
|
+
>>> from repl_toolkit import CancellableBackend
|
|
21
|
+
>>>
|
|
22
|
+
>>> class MyCancellableBackend:
|
|
23
|
+
... def __init__(self):
|
|
24
|
+
... self._cancelled = False
|
|
23
25
|
...
|
|
24
|
-
...
|
|
25
|
-
...
|
|
26
|
-
...
|
|
27
|
-
... # Process image: img_data.data, img_data.media_type
|
|
26
|
+
... async def handle_input(self, user_input: str, **kwargs) -> bool:
|
|
27
|
+
... self._cancelled = False
|
|
28
|
+
... # ... processing with cancellation checkpoints ...
|
|
28
29
|
... return True
|
|
30
|
+
...
|
|
31
|
+
... def cancel(self, message: str = None) -> None:
|
|
32
|
+
... self._cancelled = True
|
|
29
33
|
"""
|
|
30
34
|
|
|
31
35
|
import logging
|
|
32
36
|
|
|
33
37
|
# Add NullHandler to prevent "No handler found" warnings
|
|
34
|
-
# Applications using this library should configure their own handlers
|
|
35
38
|
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
36
39
|
|
|
37
|
-
__version__ = "2.0
|
|
40
|
+
__version__ = "2.2.0"
|
|
38
41
|
|
|
39
42
|
from .actions import Action, ActionContext, ActionRegistry
|
|
40
43
|
from .async_repl import AsyncREPL, run_async_repl
|
|
@@ -55,7 +58,7 @@ from .images import (
|
|
|
55
58
|
parse_image_references,
|
|
56
59
|
reconstruct_message,
|
|
57
60
|
)
|
|
58
|
-
from .ptypes import ActionHandler, AsyncBackend, Completer
|
|
61
|
+
from .ptypes import ActionHandler, AsyncBackend, CancellableBackend, Completer
|
|
59
62
|
|
|
60
63
|
__all__ = [
|
|
61
64
|
# Core REPL
|
|
@@ -86,5 +89,6 @@ __all__ = [
|
|
|
86
89
|
# Protocols
|
|
87
90
|
"ActionHandler",
|
|
88
91
|
"AsyncBackend",
|
|
92
|
+
"CancellableBackend",
|
|
89
93
|
"Completer",
|
|
90
94
|
]
|
|
@@ -79,7 +79,6 @@ class ActionRegistry(ActionHandler):
|
|
|
79
79
|
@property
|
|
80
80
|
def backend(self):
|
|
81
81
|
"""The backend property getter."""
|
|
82
|
-
logger.debug("ActionRegistry.backend getter")
|
|
83
82
|
return self._backend
|
|
84
83
|
|
|
85
84
|
@backend.setter
|
|
@@ -320,7 +319,7 @@ class ActionRegistry(ActionHandler):
|
|
|
320
319
|
f"Failed to execute action '{action_name}': {e}", action_name
|
|
321
320
|
) # pragma: no cover
|
|
322
321
|
|
|
323
|
-
def handle_command(self, command_string: str, **kwargs) -> None:
|
|
322
|
+
def handle_command(self, command_string: str, **kwargs: Any) -> None:
|
|
324
323
|
"""
|
|
325
324
|
Handle a command string by mapping to appropriate action.
|
|
326
325
|
|
|
@@ -373,7 +372,7 @@ class ActionRegistry(ActionHandler):
|
|
|
373
372
|
logger.exception(f"Unexpected error handling command '{command_string}'")
|
|
374
373
|
logger.debug("ActionRegistry.handle_command() exit - unexpected error")
|
|
375
374
|
|
|
376
|
-
def handle_shortcut(self, key_combo: str, event: Any, **kwargs) -> None:
|
|
375
|
+
def handle_shortcut(self, key_combo: str, event: Any, **kwargs: Any) -> None:
|
|
377
376
|
"""
|
|
378
377
|
Handle a keyboard shortcut by mapping to appropriate action.
|
|
379
378
|
|
|
@@ -415,22 +414,18 @@ class ActionRegistry(ActionHandler):
|
|
|
415
414
|
# ActionHandler protocol implementation
|
|
416
415
|
def validate_action(self, action_name: str) -> bool:
|
|
417
416
|
"""Validate if an action is supported."""
|
|
418
|
-
logger.debug("ActionRegistry.validate_action() entry/exit")
|
|
419
417
|
return action_name in self.actions
|
|
420
418
|
|
|
421
419
|
def list_actions(self) -> List[str]:
|
|
422
420
|
"""Return a list of all available action names."""
|
|
423
|
-
logger.debug("ActionRegistry.list_actions() entry/exit")
|
|
424
421
|
return list(self.actions.keys())
|
|
425
422
|
|
|
426
423
|
def list_commands(self) -> List[str]:
|
|
427
424
|
"""Return a list of all available commands."""
|
|
428
|
-
logger.debug("ActionRegistry.list_commands() entry/exit")
|
|
429
425
|
return list(self.command_map.keys())
|
|
430
426
|
|
|
431
427
|
def list_shortcuts(self) -> List[str]:
|
|
432
428
|
"""Return a list of all available keyboard shortcuts."""
|
|
433
|
-
logger.debug("ActionRegistry.list_shortcuts() entry/exit")
|
|
434
429
|
return list(self.key_map.keys())
|
|
435
430
|
|
|
436
431
|
def is_registered_command(self, text: str) -> bool:
|
|
@@ -509,7 +504,7 @@ class ActionRegistry(ActionHandler):
|
|
|
509
504
|
|
|
510
505
|
if action:
|
|
511
506
|
self._show_action_help(action, context)
|
|
512
|
-
else:
|
|
507
|
+
else:
|
|
513
508
|
context.printer(f"No help available for: {context.args[0]}")
|
|
514
509
|
else:
|
|
515
510
|
# Show general help
|
|
@@ -520,22 +515,19 @@ class ActionRegistry(ActionHandler):
|
|
|
520
515
|
def _show_action_help(self, action: Action, context: ActionContext) -> None:
|
|
521
516
|
"""Show detailed help for a specific action."""
|
|
522
517
|
logger.debug("ActionRegistry._show_action_help() entry")
|
|
523
|
-
|
|
524
|
-
context.printer(f"\n{action.description}") # pragma: no cover
|
|
518
|
+
context.printer(f"\n{action.description}")
|
|
525
519
|
context.printer(f"Category: {action.category}")
|
|
526
520
|
|
|
527
|
-
if action.command:
|
|
521
|
+
if action.command:
|
|
528
522
|
context.printer(f"Command: {action.command_usage or action.command}")
|
|
529
523
|
|
|
530
524
|
if action.keys:
|
|
531
525
|
keys_str = ", ".join(action.get_keys_list())
|
|
532
|
-
desc =
|
|
533
|
-
f" - {action.keys_description}" if action.keys_description else ""
|
|
534
|
-
) # pragma: no cover
|
|
526
|
+
desc = f" - {action.keys_description}" if action.keys_description else ""
|
|
535
527
|
context.printer(f"Shortcut: {keys_str}{desc}")
|
|
536
528
|
|
|
537
|
-
if not action.enabled:
|
|
538
|
-
context.printer("Status: Disabled")
|
|
529
|
+
if not action.enabled:
|
|
530
|
+
context.printer("Status: Disabled")
|
|
539
531
|
context.printer("")
|
|
540
532
|
|
|
541
533
|
logger.debug("ActionRegistry._show_action_help() exit")
|
|
@@ -543,13 +535,12 @@ class ActionRegistry(ActionHandler):
|
|
|
543
535
|
def _show_general_help(self, context: ActionContext) -> None:
|
|
544
536
|
"""Show general help with all actions organized by category."""
|
|
545
537
|
logger.debug("ActionRegistry._show_general_help() entry")
|
|
546
|
-
|
|
547
|
-
context.printer("\nAvailable Actions:") # pragma: no cover
|
|
538
|
+
context.printer("\nAvailable Actions:")
|
|
548
539
|
context.printer("=" * 50)
|
|
549
540
|
|
|
550
541
|
categories = self.get_actions_by_category()
|
|
551
542
|
|
|
552
|
-
for category, actions in sorted(categories.items()):
|
|
543
|
+
for category, actions in sorted(categories.items()):
|
|
553
544
|
context.printer(f"\n{category}:")
|
|
554
545
|
for action in sorted(actions, key=lambda a: a.name):
|
|
555
546
|
# Format display line
|
|
@@ -567,13 +558,9 @@ class ActionRegistry(ActionHandler):
|
|
|
567
558
|
parts.append(" " * 15)
|
|
568
559
|
|
|
569
560
|
parts.append(action.description)
|
|
570
|
-
# pragma: no cover
|
|
571
561
|
context.printer(" " + "".join(parts))
|
|
572
|
-
|
|
573
|
-
context.printer(
|
|
574
|
-
"\nUse '/help <command>' for detailed information about a specific action."
|
|
575
|
-
) # pragma: no cover
|
|
576
|
-
context.printer("Use '/shortcuts' to see only keyboard shortcuts.") # pragma: no cover
|
|
562
|
+
context.printer("\nUse '/help <command>' for detailed information about a specific action.")
|
|
563
|
+
context.printer("Use '/shortcuts' to see only keyboard shortcuts.")
|
|
577
564
|
context.printer("")
|
|
578
565
|
|
|
579
566
|
logger.debug("ActionRegistry._show_general_help() exit")
|
|
@@ -581,8 +568,7 @@ class ActionRegistry(ActionHandler):
|
|
|
581
568
|
def _list_shortcuts(self, context: ActionContext) -> None:
|
|
582
569
|
"""List all keyboard shortcuts."""
|
|
583
570
|
logger.debug("ActionRegistry._list_shortcuts() entry")
|
|
584
|
-
|
|
585
|
-
context.printer("\nKeyboard Shortcuts:") # pragma: no cover
|
|
571
|
+
context.printer("\nKeyboard Shortcuts:")
|
|
586
572
|
context.printer("=" * 50)
|
|
587
573
|
|
|
588
574
|
categories = self.get_actions_by_category()
|
|
@@ -591,13 +577,11 @@ class ActionRegistry(ActionHandler):
|
|
|
591
577
|
shortcuts_in_category = [a for a in actions if a.keys]
|
|
592
578
|
if not shortcuts_in_category:
|
|
593
579
|
continue
|
|
594
|
-
# pragma: no cover
|
|
595
580
|
context.printer(f"\n{category}:")
|
|
596
581
|
for action in sorted(shortcuts_in_category, key=lambda a: a.name):
|
|
597
582
|
keys_str = ", ".join(action.get_keys_list())
|
|
598
|
-
desc = action.keys_description or action.description
|
|
583
|
+
desc = action.keys_description or action.description
|
|
599
584
|
context.printer(f" {keys_str:<15} {desc}")
|
|
600
|
-
# pragma: no cover
|
|
601
585
|
context.printer("")
|
|
602
586
|
|
|
603
587
|
logger.debug("ActionRegistry._list_shortcuts() exit")
|