File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 55
66from commitizen import defaults
77from commitizen .cz .base import BaseCommitizen
8- from commitizen .cz .utils import multiple_line_breaker , required_validator
8+ from commitizen .cz .utils import (
9+ get_multiline_key_bindings ,
10+ multiple_line_breaker ,
11+ required_validator ,
12+ )
913
1014if TYPE_CHECKING :
1115 from commitizen .question import CzQuestion
@@ -133,6 +137,8 @@ def questions(self) -> list[CzQuestion]:
133137 "Provide additional contextual information about the code changes: (press [enter] to skip)\n "
134138 ),
135139 "filter" : multiple_line_breaker ,
140+ "multiline" : True ,
141+ "key_bindings" : get_multiline_key_bindings (),
136142 },
137143 {
138144 "type" : "confirm" ,
Original file line number Diff line number Diff line change 11import os
22import re
33import tempfile
4+ from functools import lru_cache
45from pathlib import Path
56
7+ from prompt_toolkit .key_binding import KeyBindings , KeyPressEvent
8+
69from commitizen import git
710from commitizen .cz import exceptions
811
912_RE_LOCAL_VERSION = re .compile (r"\+.+" )
1013
1114
15+ @lru_cache (maxsize = 1 )
16+ def get_multiline_key_bindings () -> KeyBindings :
17+ kb = KeyBindings ()
18+
19+ @kb .add ("enter" )
20+ def handle_enter (event : KeyPressEvent ) -> None :
21+ buff = event .app .current_buffer
22+ if buff .text == "" :
23+ buff .validate_and_handle ()
24+ else :
25+ buff .insert_text ("\n " )
26+
27+ return kb
28+
29+
1230def required_validator (answer : str , msg : object = None ) -> str :
1331 if not answer :
1432 raise exceptions .AnswerRequiredError (msg )
Original file line number Diff line number Diff line change 11from collections .abc import Callable
22from typing import Literal , TypedDict
33
4+ from prompt_toolkit .key_binding import KeyBindings
5+
46
57class Choice (TypedDict , total = False ):
68 value : str
@@ -21,6 +23,8 @@ class InputQuestion(TypedDict, total=False):
2123 name : str
2224 message : str
2325 filter : Callable [[str ], str ]
26+ multiline : bool
27+ key_bindings : KeyBindings
2428
2529
2630class ConfirmQuestion (TypedDict ):
You can’t perform that action at this time.
0 commit comments