15
15
from prompt_toolkit .formatted_text import HTML , FormattedText , StyleAndTextTuples
16
16
from prompt_toolkit .input import create_input
17
17
from prompt_toolkit .key_binding import KeyBindings
18
+ from prompt_toolkit .key_binding .key_processor import KeyPressEvent
18
19
from prompt_toolkit .keys import Keys
19
20
from prompt_toolkit .layout .containers import HSplit , Window
20
21
from prompt_toolkit .layout .controls import FormattedTextControl
70
71
71
72
72
73
class UsageMetrics :
73
- def __init__ (self ):
74
+ def __init__ (self ) -> None :
74
75
self .metrics : Metrics = Metrics ()
75
76
self .session_init_time : float = time .time ()
76
77
77
78
78
79
class CustomDiffLexer (Lexer ):
79
80
"""Custom lexer for the specific diff format."""
80
81
81
- def lex_document (self , document ) -> StyleAndTextTuples :
82
+ def lex_document (self , document : Document ) -> StyleAndTextTuples :
82
83
lines = document .lines
83
84
84
85
def get_line (lineno : int ) -> StyleAndTextTuples :
@@ -427,7 +428,7 @@ def display_agent_state_change_message(agent_state: str) -> None:
427
428
class CommandCompleter (Completer ):
428
429
"""Custom completer for commands."""
429
430
430
- def __init__ (self , agent_state : str ):
431
+ def __init__ (self , agent_state : str ) -> None :
431
432
super ().__init__ ()
432
433
self .agent_state = agent_state
433
434
@@ -450,7 +451,7 @@ def get_completions(
450
451
)
451
452
452
453
453
- def create_prompt_session () -> PromptSession :
454
+ def create_prompt_session () -> PromptSession [ str ] :
454
455
return PromptSession (style = DEFAULT_STYLE )
455
456
456
457
@@ -465,7 +466,7 @@ async def read_prompt_input(agent_state: str, multiline: bool = False) -> str:
465
466
kb = KeyBindings ()
466
467
467
468
@kb .add ('c-d' )
468
- def _ (event ) -> None :
469
+ def _ (event : KeyPressEvent ) -> None :
469
470
event .current_buffer .validate_and_handle ()
470
471
471
472
with patch_stdout ():
@@ -538,11 +539,10 @@ def keys_ready() -> None:
538
539
def cli_confirm (
539
540
question : str = 'Are you sure?' , choices : list [str ] | None = None
540
541
) -> int :
541
- """
542
- Display a confirmation prompt with the given question and choices.
542
+ """Display a confirmation prompt with the given question and choices.
543
+
543
544
Returns the index of the selected choice.
544
545
"""
545
-
546
546
if choices is None :
547
547
choices = ['Yes' , 'No' ]
548
548
selected = [0 ] # Using list to allow modification in closure
@@ -561,15 +561,15 @@ def get_choice_text() -> list:
561
561
kb = KeyBindings ()
562
562
563
563
@kb .add ('up' )
564
- def _ (event ) -> None :
564
+ def _ (event : KeyPressEvent ) -> None :
565
565
selected [0 ] = (selected [0 ] - 1 ) % len (choices )
566
566
567
567
@kb .add ('down' )
568
- def _ (event ) -> None :
568
+ def _ (event : KeyPressEvent ) -> None :
569
569
selected [0 ] = (selected [0 ] + 1 ) % len (choices )
570
570
571
571
@kb .add ('enter' )
572
- def _ (event ) -> None :
572
+ def _ (event : KeyPressEvent ) -> None :
573
573
event .app .exit (result = selected [0 ])
574
574
575
575
style = Style .from_dict ({'selected' : COLOR_GOLD , 'unselected' : '' })
@@ -601,7 +601,7 @@ def kb_cancel() -> KeyBindings:
601
601
bindings = KeyBindings ()
602
602
603
603
@bindings .add ('escape' )
604
- def _ (event ) -> None :
604
+ def _ (event : KeyPressEvent ) -> None :
605
605
event .app .exit (exception = UserCancelledError , style = 'class:aborting' )
606
606
607
607
return bindings
0 commit comments