Skip to content

Commit

Permalink
✨ version 1.8.35
Browse files Browse the repository at this point in the history
lang item completion.prompt_arg
  • Loading branch information
RF-Tar-Railt committed Dec 8, 2024
1 parent ff6b9b4 commit 96077ec
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## 1.8.35

### 改进

- 补全时参数的自定义提示与参数名的组合方式现在可以通过 `lang.set("completion", "prompt_arg", xxx)` 来设置

## 1.8.34

### 改进
Expand Down
7 changes: 4 additions & 3 deletions exam1.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from tarina import lang

from arclet.alconna import Alconna, Arg, Args, CommandMeta, CompSession, Option, OptionResult
from arclet.alconna import Alconna, Arg, Args, Field, CommandMeta, CompSession, Option, OptionResult

lang.set("completion", "node", "")
lang.set("completion", "prompt_arg", "{name} - {prompt}")
lang.set("completion", "prompt_select", "")


api_list = ["saucenao", "ascii2d", "ehentai", "iqdb", "tracemoe"]
alc = Alconna(
"setu",
Args['content', str],
Args['content', str, Field(completion=lambda: "Image url or file path")],
Option("use", Args['api', api_list], help_text="选择搜图使用的 API"),
Option("count", Args(Arg("num", int)), help_text="设置每次搜图展示的最多数量"),
Option("--similarity|-s", Args["val", float], help_text="设置相似度过滤的值", default=OptionResult(args={"val": 0.5})),
Expand All @@ -28,7 +29,7 @@
print("---------------------------------------------------")
print(interface)
print("---------------------------------------------------")
print(".enter to confirm, .tab to switch, ctrl+c to cancel")
print(".enter to confirm, .tab to switch, .exit/.q to cancel")
print("---------------------------------------------------")
while True:
cmd = input(">>> ")
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ classifiers=[
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: OS Independent",
]
[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from .typing import Up as Up
from .typing import StrMulti as StrMulti

__version__ = "1.8.34"
__version__ = "1.8.35"

# backward compatibility
AnyOne = ANY
12 changes: 7 additions & 5 deletions src/arclet/alconna/_internal/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,15 @@ def _handle_shortcut_reg(argv: Argv, groups: tuple[str, ...], gdict: dict[str, s


def _prompt_unit(analyser: Analyser, argv: Argv, trig: Arg):
template = lang.require("completion", "prompt_arg")
if not (comp := trig.field.get_completion()):
return [Prompt(analyser.command.formatter.param(trig), False)]
if isinstance(comp, str):
return [Prompt(f"{trig.name}: {comp}", False)]
return [Prompt(template.format(name=trig.name, prompt=comp), False)]
releases = argv.release(recover=True)
target = str(releases[-1]) or str(releases[-2])
o = list(filter(lambda x: target in x, comp)) or comp
return [Prompt(f"{trig.name}: {i}", False, target) for i in o]
return [Prompt(template.format(name=trig.name, prompt=i), False, target) for i in o]


def _prompt_sentence(analyser: Analyser):
Expand All @@ -801,12 +802,13 @@ def _prompt_none(analyser: Analyser, argv: Argv, got: list[str]):
res: list[Prompt] = []
if not analyser.args_result and analyser.self_args.argument:
unit = analyser.self_args.argument[0]
template = lang.require("completion", "prompt_arg")
if not (comp := unit.field.get_completion()):
res.append(Prompt(analyser.command.formatter.param(unit), False))
elif isinstance(comp, str):
res.append(Prompt(f"{unit.name}: {comp}", False))
res.append(Prompt(template.format(name=unit.name, prompt=comp), False))
else:
res.extend(Prompt(f"{unit.name}: {i}", False) for i in comp)
res.extend(Prompt(template.format(name=unit.name, prompt=i), False) for i in comp)
for opt in filter(
lambda x: x.name not in (argv.special if len(analyser.command.options) > 3 else argv.completion_names),
analyser.command.options,
Expand Down Expand Up @@ -846,7 +848,7 @@ def handle_completion(analyser: Analyser, argv: Argv, trigger: str | None = None
if comp_ctx.get(None):
raise PauseTriggered(res, trigger, argv)
prompt_other = lang.require("completion", "prompt_other")
node = lang.require('completion', 'node')
node = lang.require("completion", "node")
node = f"{node}\n" if node else ""
output_manager.send(
analyser.command.name,
Expand Down
5 changes: 5 additions & 0 deletions src/arclet/alconna/i18n/.lang.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"description": "value of lang item type 'node'",
"type": "string"
},
"prompt_arg": {
"title": "prompt_arg",
"description": "value of lang item type 'prompt_arg'",
"type": "string"
},
"prompt_select": {
"title": "prompt_select",
"description": "value of lang item type 'prompt_select'",
Expand Down
1 change: 1 addition & 0 deletions src/arclet/alconna/i18n/.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scope": "completion",
"types": [
"node",
"prompt_arg",
"prompt_select",
"prompt_other",
"prompt_empty",
Expand Down
1 change: 1 addition & 0 deletions src/arclet/alconna/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"completion": {
"node": "suggest input follows:",
"prompt_arg": "{name}: {prompt}",
"prompt_select": ">> ",
"prompt_other": "* ",
"prompt_empty": "No prompt available.",
Expand Down
1 change: 1 addition & 0 deletions src/arclet/alconna/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"completion": {
"node": "以下是建议的输入:",
"prompt_arg": "{name}: {prompt}",
"prompt_select": ">> ",
"prompt_other": "* ",
"prompt_empty": "没有可用的补全提示",
Expand Down

0 comments on commit 96077ec

Please sign in to comment.