本文整理汇总了Python中prompt_toolkit.contrib.completers.WordCompleter方法的典型用法代码示例。如果您正苦于以下问题:Python completers.WordCompleter方法的具体用法?Python completers.WordCompleter怎么用?Python completers.WordCompleter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.contrib.completers
的用法示例。
在下文中一共展示了completers.WordCompleter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_message
# 需要导入模块: from prompt_toolkit.contrib import completers [as 别名]
# 或者: from prompt_toolkit.contrib.completers import WordCompleter [as 别名]
def post_message(self, channel_name):
# self.channels_history(channel_name)
os.system("echo '\u001b[1m\u001b[31m To mention a user write @ while chatting \u001b[0m'")
text = prompt("your message > ", completer=WordCompleter(users))
channel_id = self.find_channel_id(channel_name)
url = "https://slack.com/api/chat.postMessage?token={token}&channel={channel_id}&text={text}&as_user=true&link_names=1".format(
token=settings.token,
text=text,
channel_id=channel_id)
response = requests.get(url).json()
# TODO : retrieve message history and print to screen while chatting
if response["ok"]:
os.system("figlet 'Sent' | lolcat")
time.sleep(2)
os.system("clear")
else:
print "something goes wrong :( (\u001b[1m\u001b[31m " + response["error"] + "\u001b[0m)"
示例2: channels_invite
# 需要导入模块: from prompt_toolkit.contrib import completers [as 别名]
# 或者: from prompt_toolkit.contrib.completers import WordCompleter [as 别名]
def channels_invite(self, channel_name):
channel_id = self.find_channel_id(channel_name)
invites = prompt("send invites -> ", completer=WordCompleter(users),
style=DocumentStyle)
for i in invites.split(" "):
user_id = self.find_user_id(i.strip("@"))
url = "https://slack.com/api/channels.invite?token={token}&channel={channel_id}&user={user}".format(
token=settings.token,
channel_id=channel_id,
user=user_id)
response = requests.get(url).json()
if response["ok"]:
os.system("figlet 'Invited " + i + "' | lolcat")
time.sleep(2)
os.system("clear")
else:
print "something goes wrong :( (\u001b[1m\u001b[31m " + response["error"] + "\u001b[0m)"
示例3: channels_create
# 需要导入模块: from prompt_toolkit.contrib import completers [as 别名]
# 或者: from prompt_toolkit.contrib.completers import WordCompleter [as 别名]
def channels_create(self):
os.system("clear")
fields = ["name", "purpose(OPTINAL)", "send invite"]
for i in fields:
if i == "name":
name = raw_input("\u001b[1m\u001b[31m channel name -> \u001b[0m")
elif i == "purpose(OPTINAL)":
purpose = raw_input("\u001b[1m\u001b[31m purpose of the channel(OPTINAL) : \u001b[0m")
else:
invites = prompt("send invites -> ", completer=WordCompleter(users),
style=DocumentStyle)
url = "https://slack.com/api/channels.create?token={token}&name={name}&purpose={purpose}".format(
token=settings.token,
name=name,
purpose=purpose)
response = requests.get(url).json()
# TODO : send channel and user_id to channels_invite
if response["ok"]:
os.system("figlet 'Created' | lolcat")
time.sleep(2)
os.system("clear")
示例4: completers
# 需要导入模块: from prompt_toolkit.contrib import completers [as 别名]
# 或者: from prompt_toolkit.contrib.completers import WordCompleter [as 别名]
def completers(self):
completers = {}
completers["nym"] = WordCompleter([])
completers["role"] = WordCompleter(["SPONSOR", "STEWARD"])
completers["send_nym"] = WordCompleter(["send", "NYM"])
completers["send_get_nym"] = WordCompleter(["send", "GET_NYM"])
completers["send_attrib"] = WordCompleter(["send", "ATTRIB"])
completers["send_cred_def"] = WordCompleter(["send", "CLAIM_DEF"])
completers["send_isr_key"] = WordCompleter(["send", "ISSUER_KEY"])
completers["send_node"] = WordCompleter(["send", "NODE"])
completers["send_pool_upg"] = WordCompleter(["send", "POOL_UPGRADE"])
completers["add_genesis"] = WordCompleter(
["add", "genesis", "transaction"])
completers["show_file"] = WordCompleter(["show"])
completers["load_file"] = WordCompleter(["load"])
completers["show_link"] = WordCompleter(["show", "link"])
completers["conn"] = WordCompleter(["connect"])
completers["env_name"] = WordCompleter(list(self.config.ENVS.keys()))
completers["sync_link"] = WordCompleter(["sync"])
completers["ping_target"] = WordCompleter(["ping"])
completers["show_claim"] = WordCompleter(["show", "claim"])
completers["show_claim_req"] = WordCompleter(["show",
"claim", "request"])
completers["req_claim"] = WordCompleter(["request", "claim"])
completers["accept_link_invite"] = WordCompleter(["accept",
"invitation", "from"])
completers["set_attr"] = WordCompleter(["set"])
completers["send_claim"] = WordCompleter(["send", "claim"])
return {**super().completers, **completers}
示例5: completers
# 需要导入模块: from prompt_toolkit.contrib import completers [as 别名]
# 或者: from prompt_toolkit.contrib.completers import WordCompleter [as 别名]
def completers(self):
completers = {}
completers["nym"] = WordCompleter([])
completers["role"] = WordCompleter([Roles.TRUST_ANCHOR.name, Roles.STEWARD.name])
completers["send_nym"] = PhraseWordCompleter(sendNymCmd.id)
completers["send_get_nym"] = PhraseWordCompleter(sendGetNymCmd.id)
completers["send_attrib"] = PhraseWordCompleter(sendAttribCmd.id)
completers["send_schema"] = PhraseWordCompleter(sendSchemaCmd.id)
completers["send_claim_def"] = PhraseWordCompleter(sendClaimDefCmd.id)
completers["send_node"] = PhraseWordCompleter(sendNodeCmd.id)
completers["send_pool_upg"] = PhraseWordCompleter(sendPoolUpgCmd.id)
completers["add_genesis"] = PhraseWordCompleter(
addGenesisTxnCmd.id)
completers["show_file"] = WordCompleter([showFileCmd.id])
completers["load_file"] = WordCompleter([loadFileCmd.id])
completers["show_link"] = PhraseWordCompleter(showLinkCmd.id)
completers["conn"] = WordCompleter([connectToCmd.id])
completers["disconn"] = WordCompleter([disconnectCmd.id])
completers["env_name"] = WordCompleter(list(self.config.ENVS.keys()))
completers["sync_link"] = WordCompleter([syncLinkCmd.id])
completers["ping_target"] = WordCompleter([pingTargetCmd.id])
completers["show_claim"] = PhraseWordCompleter(showClaimCmd.id)
completers["req_claim"] = PhraseWordCompleter(reqClaimCmd.id)
completers["accept_link_invite"] = PhraseWordCompleter(acceptLinkCmd.id)
completers["set_attr"] = WordCompleter([setAttrCmd.id])
completers["new_id"] = PhraseWordCompleter(newIdentifierCmd.id)
completers["list_claims"] = PhraseWordCompleter(listClaimsCmd.id)
completers["list_links"] = PhraseWordCompleter(listLinksCmd.id)
completers["show_proof_req"] = PhraseWordCompleter(
showProofRequestCmd.id)
completers["send_proof_request"] = PhraseWordCompleter(
sendProofRequestCmd.id)
completers["send_proof"] = PhraseWordCompleter(sendProofCmd.id)
completers["req_avail_claims"] = PhraseWordCompleter(reqAvailClaimsCmd.id)
return {**super().completers, **completers}
示例6: file_upload
# 需要导入模块: from prompt_toolkit.contrib import completers [as 别名]
# 或者: from prompt_toolkit.contrib.completers import WordCompleter [as 别名]
def file_upload(self, channel_name):
os.system("clear")
channel_id = self.find_channel_id(channel_name)
fields = ["file", "content", "filename", "title", "initial_comment"]
for i in fields:
if i == "file":
os.system("echo 'opening the file dialog. wait...' ")
file = subprocess.check_output(['zenity', '--file-selection'])
os.system("echo '\u001b[1m\u001b[31m file : \u001b[0m'" + file + "'")
elif i == "content":
content = raw_input("\u001b[1m\u001b[31m content : \u001b[0m")
elif i == "filename":
filename = raw_input("\u001b[1m\u001b[31m filename : \u001b[0m")
elif i == "title":
title = raw_input("\u001b[1m\u001b[31m title : \u001b[0m")
else:
initial_comment = prompt("add comment : ", completer=WordCompleter(users),
style=DocumentStyle)
url = "https://slack.com/api/files.upload?token={token}&content={content}&filename={filename}&channels={channel_id}&title={title}&initial_comment={initial_comment}".format(
token=settings.token,
content=content,
filename=filename,
channel_id=channel_id,
title=title,
initial_comment=initial_comment)
response = requests.get(url).json()
if response["ok"]:
os.system("figlet 'Uploaded!' | lolcat")
time.sleep(2)
os.system("clear")
else:
print "something goes wrong :( (\u001b[1m\u001b[31m " + response["error"] + "\u001b[0m)"
示例7: do_repl
# 需要导入模块: from prompt_toolkit.contrib import completers [as 别名]
# 或者: from prompt_toolkit.contrib.completers import WordCompleter [as 别名]
def do_repl(self):
"""REPL for rTorrent XMLRPC commands."""
from prompt_toolkit import prompt
from prompt_toolkit.history import FileHistory
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.contrib.completers import WordCompleter
self.options.quiet = False
proxy = self.open()
ps1 = proxy.session.name() + u'> '
words = ['help', 'stats', 'exit']
words += [x + '=' for x in proxy.system.listMethods()]
history_file = os.path.join(config.config_dir, '.rtxmlrpc_history')
while True:
try:
try:
cmd = prompt(ps1, completer=WordCompleter(words),
auto_suggest=AutoSuggestFromHistory(),
history=FileHistory(history_file))
except KeyboardInterrupt:
cmd = ''
if not cmd:
print("Enter '?' or 'help' for usage information, 'Ctrl-D' to exit.")
if cmd in {'?', 'help'}:
self.repl_usage()
continue
elif cmd in {'', 'stats'}:
print(repr(proxy).split(None, 1)[1])
continue
elif cmd in {'exit'}:
raise EOFError()
try:
method, raw_args = cmd.split('=', 1)
except ValueError:
print("ERROR: '=' not found")
continue
raw_args = raw_args.split(',')
args = self.cooked(raw_args)
self.execute(proxy, method, args)
except EOFError:
print('Bye from {!r}'.format(proxy))
break