From 96077ec3228897e782ea4f8bf70449e658e6f76e Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt Date: Sun, 8 Dec 2024 15:24:01 +0800 Subject: [PATCH] :sparkles: version 1.8.35 lang item completion.prompt_arg --- CHANGELOG.md | 6 ++++++ exam1.py | 7 ++++--- pyproject.toml | 2 ++ src/arclet/alconna/__init__.py | 2 +- src/arclet/alconna/_internal/_handlers.py | 12 +++++++----- src/arclet/alconna/i18n/.lang.schema.json | 5 +++++ src/arclet/alconna/i18n/.template.json | 1 + src/arclet/alconna/i18n/en-US.json | 1 + src/arclet/alconna/i18n/zh-CN.json | 1 + 9 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cfbb376..136fa84f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +## 1.8.35 + +### 改进 + +- 补全时参数的自定义提示与参数名的组合方式现在可以通过 `lang.set("completion", "prompt_arg", xxx)` 来设置 + ## 1.8.34 ### 改进 diff --git a/exam1.py b/exam1.py index f6e83841..77c42805 100644 --- a/exam1.py +++ b/exam1.py @@ -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})), @@ -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(">>> ") diff --git a/pyproject.toml b/pyproject.toml index b7ce1ad7..be508d52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/src/arclet/alconna/__init__.py b/src/arclet/alconna/__init__.py index b3dae20d..401369c7 100644 --- a/src/arclet/alconna/__init__.py +++ b/src/arclet/alconna/__init__.py @@ -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 diff --git a/src/arclet/alconna/_internal/_handlers.py b/src/arclet/alconna/_internal/_handlers.py index f88d2082..48ea73c1 100644 --- a/src/arclet/alconna/_internal/_handlers.py +++ b/src/arclet/alconna/_internal/_handlers.py @@ -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): @@ -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, @@ -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, diff --git a/src/arclet/alconna/i18n/.lang.schema.json b/src/arclet/alconna/i18n/.lang.schema.json index 47afa90f..2cb19453 100644 --- a/src/arclet/alconna/i18n/.lang.schema.json +++ b/src/arclet/alconna/i18n/.lang.schema.json @@ -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'", diff --git a/src/arclet/alconna/i18n/.template.json b/src/arclet/alconna/i18n/.template.json index ddc5776a..aaefb8a0 100644 --- a/src/arclet/alconna/i18n/.template.json +++ b/src/arclet/alconna/i18n/.template.json @@ -13,6 +13,7 @@ "scope": "completion", "types": [ "node", + "prompt_arg", "prompt_select", "prompt_other", "prompt_empty", diff --git a/src/arclet/alconna/i18n/en-US.json b/src/arclet/alconna/i18n/en-US.json index c19fe197..6f72ab86 100644 --- a/src/arclet/alconna/i18n/en-US.json +++ b/src/arclet/alconna/i18n/en-US.json @@ -6,6 +6,7 @@ }, "completion": { "node": "suggest input follows:", + "prompt_arg": "{name}: {prompt}", "prompt_select": ">> ", "prompt_other": "* ", "prompt_empty": "No prompt available.", diff --git a/src/arclet/alconna/i18n/zh-CN.json b/src/arclet/alconna/i18n/zh-CN.json index 23376fec..af43953a 100644 --- a/src/arclet/alconna/i18n/zh-CN.json +++ b/src/arclet/alconna/i18n/zh-CN.json @@ -6,6 +6,7 @@ }, "completion": { "node": "以下是建议的输入:", + "prompt_arg": "{name}: {prompt}", "prompt_select": ">> ", "prompt_other": "* ", "prompt_empty": "没有可用的补全提示",