Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 6717d85

Browse files
committed
feat(ui): Visually improve prompt continuation
Prompt continuation on multiple lines is visually more indicative. Resolve #38
1 parent 7d800b0 commit 6717d85

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

gitcommit/ansi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class bg:
5050
bright_cyan = "\033[106m"
5151
bright_white = "\033[107m"
5252

53+
@classmethod
54+
def colour(cls, *args):
55+
"""Combines all args into string. Should pass colour modifiers in first followed by the string. Does not need reset sequence at the end."""
56+
return "".join(args) + cls.reset
57+
5358
@classmethod
5459
def b_green(cls, content):
5560
return cls.fg.bright_green + cls.bold + str(content) + cls.reset

gitcommit/gitcommit.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,16 @@ def add_description(commit_msg):
228228
return commit_msg
229229

230230

231+
def custom_prompt_continuation(width, line_number, is_soft_wrap):
232+
text_continuation = " " * (width - 2) + "┃ "
233+
return ANSI(Ansi.colour(Ansi.fg.bright_green, text_continuation))
234+
235+
231236
def add_body(commit_msg):
232237
if IS_BREAKING_CHANGE is None:
233238
raise ValueError("Global variable `IS_BREAKING_CHANGE` has not been set.")
234239

235-
session = PromptSession()
240+
session = PromptSession(prompt_continuation=custom_prompt_continuation)
236241
body_validator = BodyValidator(session, IS_BREAKING_CHANGE)
237242

238243
if IS_BREAKING_CHANGE:
@@ -242,7 +247,7 @@ def add_body(commit_msg):
242247
"Press Esc before Enter to submit."
243248
)
244249
)
245-
text = Ansi.b_green("Body (required): ")
250+
text = Ansi.b_green("Body (required) ")
246251
else:
247252
Ansi.print_info(
248253
wrap_width(
@@ -252,7 +257,7 @@ def add_body(commit_msg):
252257
]
253258
)
254259
)
255-
text = Ansi.b_green("Body (optional): ")
260+
text = Ansi.b_green("Body (optional) ")
256261

257262
c_body = session.prompt(ANSI(text), validator=body_validator)
258263
c_body = c_body.strip() # remove leading/trailing whitespace
@@ -305,14 +310,11 @@ def add_footer(commit_msg):
305310
)
306311
)
307312

308-
def footer_prompt_continuation(width, line_number, is_soft_wrap):
309-
return " " * (width - 2) + "| "
310-
311-
text = Ansi.b_green("Footer (optional): ")
313+
text = Ansi.b_green("Footer (optional) ┃ ")
312314
session = PromptSession(
313315
completer=FooterCompleter(),
314316
multiline=False,
315-
prompt_continuation=footer_prompt_continuation,
317+
prompt_continuation=custom_prompt_continuation,
316318
)
317319
c_footer = session.prompt(ANSI(text), validator=FooterValidator(session)).strip()
318320

0 commit comments

Comments
 (0)