示例#1
0
def action_completer(
    draw,
    group_strategy: Optional[SearchStrategy[types.ActionGroup]] = None
) -> SearchStrategy[ActionCompleter]:
    """Composite strategy for quickly building :class:`~.completer.ActionCompleter`s."""

    return ActionCompleter(
        root=draw(group_strategy if group_strategy else action_group()))
示例#2
0
from prompt_toolkit.shortcuts import prompt

from action_completer import ActionCompleter

completer = ActionCompleter()


@completer.action("hello")
def _hello_action():
    print("Hello, World!")


prompt(">>> ", completer=completer)
示例#3
0
from prompt_toolkit.filters import Condition
from prompt_toolkit.shortcuts import prompt

from action_completer import ActionCompleter

completer = ActionCompleter()

ACTIVE: bool = False


def is_active() -> bool:
    return ACTIVE


def set_active(state: bool) -> bool:
    global ACTIVE
    ACTIVE = state
    return ACTIVE


@completer.action("activate", active=Condition(lambda: not is_active()))
def _activate_action():
    set_active(True)


@completer.action("deactivate", active=Condition(is_active))
def _deactivate_action():
    set_active(False)


@completer.action("hello", active=Condition(is_active))
from prompt_toolkit.shortcuts import prompt

from action_completer import ActionCompleter

completer = ActionCompleter()


@completer.action("hello")
@completer.param(["World", "Stephen"])
def _hello_action(name: str, *args):
    print(f"Hello, {name!s}!")
    print(f"Additional: {args!s}")


prompt_result = prompt(">>> ",
                       completer=completer,
                       validator=completer.get_validator())
action_partial = completer.get_partial_action(prompt_result)

print(action_partial)
action_partial("I'm something new")
from pathlib import Path

from prompt_toolkit.completion import PathCompleter
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit.validation import Validator

from action_completer import ActionCompleter

completer = ActionCompleter()

hello_group = completer.group("hello")


@hello_group.action("world")
def _hello_world():
    print("Hello, World!")


@hello_group.action("custom")
@completer.param(None)
def _hello_custom(name: str):
    print(f"Hello, {name!s}!")


prompt_result = prompt(">>> ",
                       completer=completer,
                       validator=completer.get_validator())
completer.run_action(prompt_result)
from prompt_toolkit.shortcuts import prompt

from action_completer import ActionCompleter

completer = ActionCompleter()


@completer.action("hello")
def _hello_action():
    print("Hello, World!")


prompt_result = prompt(">>> ", completer=completer)
completer.run_action(prompt_result)
示例#7
0
def ok(execution_time: float) -> None:
    print(
        f"{Back.LIGHTGREEN_EX + Fore.BLACK}  OK  {Back.RESET + Fore.LIGHTWHITE_EX} "
        f"The command finished in {Decimal(str(execution_time)).quantize(Decimal('0.0001'), rounding=ROUND_HALF_UP)}ms."
    )


def quote_check(args: str) -> bool:
    return " ".join(args).replace("\\\"", "").count("\"") % 2 != 0 or \
           " ".join(args).count("'") % 2 != 0 or \
           " ".join(args).count("`") % 2 != 0


pre_casts = pychromecast.get_chromecasts()
casts = []
cmd_completer: ActionCompleter = ActionCompleter()
cmd_auto_suggest: ThreadedAutoSuggest = ThreadedAutoSuggest(
    AutoSuggestFromHistory())
cmd_history: ThreadedHistory = ThreadedHistory(InMemoryHistory())
cmd_lexer: PygmentsLexer = PygmentsLexer(CommandLexer)
now_cast = None
now_id = 0
prefix = "> "


@cmd_completer.action("echo",
                      capture_all=True,
                      display_meta="Prints characters to the console")
@cmd_completer.param(None)
def _echo_action(*args) -> None:
    if " ".join(args) == "":
示例#8
0
from prompt_toolkit.shortcuts import prompt

from action_completer import ActionCompleter

completer = ActionCompleter()


@completer.action("hello")
def _hello_action():
    print("Hello, World!")


prompt_result = prompt(">>> ", completer=completer, validator=completer.get_validator())
completer.run_action(prompt_result)