Tweak TLDR visual formatting, Fix applying RichText to prompts
This commit is contained in:
@ -88,6 +88,7 @@ flx.add_command(
|
||||
name="test_args",
|
||||
action=test_args,
|
||||
),
|
||||
style="bold blue",
|
||||
argument_config=default_config,
|
||||
)
|
||||
|
||||
|
@ -70,7 +70,7 @@ async def build_chain(dogs: list[Dog]) -> ChainedAction:
|
||||
),
|
||||
ConfirmAction(
|
||||
name="test_confirm",
|
||||
message="Do you want to process the dogs?",
|
||||
prompt_message="Do you want to process the dogs?",
|
||||
confirm_type="yes_no_cancel",
|
||||
return_last_result=True,
|
||||
inject_into="dogs",
|
||||
|
@ -22,7 +22,7 @@ chain = ChainedAction(
|
||||
"Name",
|
||||
UserInputAction(
|
||||
name="User Input",
|
||||
prompt_text="Enter your {last_result}: ",
|
||||
prompt_message="Enter your {last_result}: ",
|
||||
validator=validate_alpha(),
|
||||
),
|
||||
Action(
|
||||
|
@ -115,7 +115,7 @@ class ConfirmAction(BaseAction):
|
||||
inject_into=inject_into,
|
||||
never_prompt=never_prompt,
|
||||
)
|
||||
self.prompt_message = rich_text_to_prompt_text(prompt_message)
|
||||
self.prompt_message = prompt_message
|
||||
self.confirm_type = ConfirmType(confirm_type)
|
||||
self.prompt_session = prompt_session or PromptSession(
|
||||
interrupt_exception=CancelSignal
|
||||
@ -128,15 +128,21 @@ class ConfirmAction(BaseAction):
|
||||
match self.confirm_type:
|
||||
case ConfirmType.YES_NO:
|
||||
return await confirm_async(
|
||||
self.prompt_message,
|
||||
prefix="❓ ",
|
||||
suffix=" [Y/n] > ",
|
||||
rich_text_to_prompt_text(self.prompt_message),
|
||||
suffix=rich_text_to_prompt_text(
|
||||
f" [[{OneColors.GREEN_b}]Y[/]]es, "
|
||||
f"[[{OneColors.DARK_RED_b}]N[/]]o > "
|
||||
),
|
||||
session=self.prompt_session,
|
||||
)
|
||||
case ConfirmType.YES_NO_CANCEL:
|
||||
error_message = "Enter 'Y', 'y' to confirm, 'N', 'n' to decline, or 'C', 'c' to abort."
|
||||
answer = await self.prompt_session.prompt_async(
|
||||
f"❓ {self.prompt_message} [Y]es, [N]o, or [C]ancel to abort > ",
|
||||
rich_text_to_prompt_text(
|
||||
f"❓ {self.prompt_message} [[{OneColors.GREEN_b}]Y[/]]es, "
|
||||
f"[[{OneColors.DARK_YELLOW_b}]N[/]]o, "
|
||||
f"or [[{OneColors.DARK_RED_b}]C[/]]ancel to abort > "
|
||||
),
|
||||
validator=words_validator(
|
||||
["Y", "N", "C"], error_message=error_message
|
||||
),
|
||||
@ -146,13 +152,19 @@ class ConfirmAction(BaseAction):
|
||||
return answer.upper() == "Y"
|
||||
case ConfirmType.TYPE_WORD:
|
||||
answer = await self.prompt_session.prompt_async(
|
||||
f"❓ {self.prompt_message} [{self.word}] to confirm or [N/n] > ",
|
||||
rich_text_to_prompt_text(
|
||||
f"❓ {self.prompt_message} [[{OneColors.GREEN_b}]{self.word.upper()}[/]] "
|
||||
f"to confirm or [[{OneColors.DARK_RED}]N[/{OneColors.DARK_RED}]] > "
|
||||
),
|
||||
validator=word_validator(self.word),
|
||||
)
|
||||
return answer.upper().strip() != "N"
|
||||
case ConfirmType.TYPE_WORD_CANCEL:
|
||||
answer = await self.prompt_session.prompt_async(
|
||||
f"❓ {self.prompt_message} [{self.word}] to confirm or [N/n] > ",
|
||||
rich_text_to_prompt_text(
|
||||
f"❓ {self.prompt_message} [[{OneColors.GREEN_b}]{self.word.upper()}[/]] "
|
||||
f"to confirm or [[{OneColors.DARK_RED}]N[/{OneColors.DARK_RED}]] > "
|
||||
),
|
||||
validator=word_validator(self.word),
|
||||
)
|
||||
if answer.upper().strip() == "N":
|
||||
@ -160,9 +172,11 @@ class ConfirmAction(BaseAction):
|
||||
return answer.upper().strip() == self.word.upper().strip()
|
||||
case ConfirmType.YES_CANCEL:
|
||||
answer = await confirm_async(
|
||||
self.prompt_message,
|
||||
prefix="❓ ",
|
||||
suffix=" [Y/n] > ",
|
||||
rich_text_to_prompt_text(self.prompt_message),
|
||||
suffix=rich_text_to_prompt_text(
|
||||
f" [[{OneColors.GREEN_b}]Y[/]]es, "
|
||||
f"[[{OneColors.DARK_RED_b}]N[/]]o > "
|
||||
),
|
||||
session=self.prompt_session,
|
||||
)
|
||||
if not answer:
|
||||
@ -171,7 +185,10 @@ class ConfirmAction(BaseAction):
|
||||
case ConfirmType.OK_CANCEL:
|
||||
error_message = "Enter 'O', 'o' to confirm or 'C', 'c' to abort."
|
||||
answer = await self.prompt_session.prompt_async(
|
||||
f"❓ {self.prompt_message} [O]k to confirm, [C]ancel to abort > ",
|
||||
rich_text_to_prompt_text(
|
||||
f"❓ {self.prompt_message} [[{OneColors.GREEN_b}]O[/]]k to confirm, "
|
||||
f"[[{OneColors.DARK_RED}]C[/]]ancel to abort > "
|
||||
),
|
||||
validator=words_validator(["O", "C"], error_message=error_message),
|
||||
)
|
||||
if answer.upper() == "C":
|
||||
@ -179,7 +196,9 @@ class ConfirmAction(BaseAction):
|
||||
return answer.upper() == "O"
|
||||
case ConfirmType.ACKNOWLEDGE:
|
||||
answer = await self.prompt_session.prompt_async(
|
||||
f"❓ {self.prompt_message} [A]cknowledge > ",
|
||||
rich_text_to_prompt_text(
|
||||
f"❓ {self.prompt_message} [[{OneColors.CYAN_b}]A[/]]cknowledge > "
|
||||
),
|
||||
validator=word_validator("A"),
|
||||
)
|
||||
return answer.upper().strip() == "A"
|
||||
|
@ -71,7 +71,7 @@ class UserInputAction(BaseAction):
|
||||
name=name,
|
||||
inject_last_result=inject_last_result,
|
||||
)
|
||||
self.prompt_message = rich_text_to_prompt_text(prompt_message)
|
||||
self.prompt_message = prompt_message
|
||||
self.validator = validator
|
||||
self.prompt_session = prompt_session or PromptSession(
|
||||
interrupt_exception=CancelSignal
|
||||
@ -97,7 +97,7 @@ class UserInputAction(BaseAction):
|
||||
prompt_message = prompt_message.format(last_result=self.last_result)
|
||||
|
||||
answer = await self.prompt_session.prompt_async(
|
||||
prompt_message,
|
||||
rich_text_to_prompt_text(prompt_message),
|
||||
validator=self.validator,
|
||||
default=kwargs.get("default_text", self.default_text),
|
||||
)
|
||||
|
@ -478,6 +478,9 @@ class CommandArgumentParser:
|
||||
self._arguments.append(argument)
|
||||
if argument.positional:
|
||||
self._positional[argument.dest] = argument
|
||||
else:
|
||||
if argument.action == ArgumentAction.TLDR:
|
||||
self._keyword_list.insert(1, argument)
|
||||
else:
|
||||
self._keyword_list.append(argument)
|
||||
|
||||
@ -1302,7 +1305,10 @@ class CommandArgumentParser:
|
||||
program = self.program or "falyx"
|
||||
command = self.aliases[0] if self.aliases else self.command_key
|
||||
if is_cli_mode:
|
||||
command = f"{program} run {command}"
|
||||
command = (
|
||||
f"{program} run [{self.command_style}]{command}[/{self.command_style}]"
|
||||
)
|
||||
else:
|
||||
command = f"[{self.command_style}]{command}[/{self.command_style}]"
|
||||
|
||||
usage = self.get_usage()
|
||||
@ -1315,8 +1321,9 @@ class CommandArgumentParser:
|
||||
for example in self._tldr_examples:
|
||||
usage = f"{command} {example.usage.strip()}"
|
||||
description = example.description.strip()
|
||||
block = f"[bold]{usage}[/bold]\n{description}"
|
||||
block = f"[bold]{usage}[/bold]"
|
||||
self.console.print(Padding(Panel(block, expand=False), (0, 2)))
|
||||
self.console.print(f" {description}", style="dim")
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, CommandArgumentParser):
|
||||
|
@ -1 +1 @@
|
||||
__version__ = "0.1.69"
|
||||
__version__ = "0.1.70"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "falyx"
|
||||
version = "0.1.69"
|
||||
version = "0.1.70"
|
||||
description = "Reliable and introspectable async CLI action framework."
|
||||
authors = ["Roland Thomas Jr <roland@rtj.dev>"]
|
||||
license = "MIT"
|
||||
|
Reference in New Issue
Block a user