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