Skip to content

Commit

Permalink
sync: lang item completion.prompt_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Dec 8, 2024
1 parent 10645e9 commit 068e520
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 100 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
- Sistana (及其上游库)仅支持 Python 3.9 及以上版本。
- Sistana 对各种特性的兼容性尚未完全测试。

## 1.8.35

### 改进

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

## 1.8.34

### 改进
Expand Down
9 changes: 5 additions & 4 deletions exam1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

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

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


api_list = ["saucenao", "ascii2d", "ehentai", "iqdb", "tracemoe"]
alc = Alconna(
"setu",
Args.content(str),
Args.content(str, completion=lambda: "Image url or file path"),
Option("use", Args.api(api_list), help_text="选择搜图使用的 API"),
Option("count", 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
164 changes: 82 additions & 82 deletions pdm.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [
dependencies = [
"typing-extensions>=4.5.0",
"nepattern<1.1.0,>=1.0.1",
"tarina<0.7.0,>=0.6.1",
"tarina<0.7.0,>=0.6.8",
"elaina-segment>=0.4.0",
"elaina-flywheel>=0.6.0",
]
Expand All @@ -37,6 +37,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 @@ -39,4 +39,4 @@
from .shortcut import ShortcutArgs as ShortcutArgs
from .manager import command_manager as command_manager

__version__ = "1.8.34"
__version__ = "1.8.35"
2 changes: 1 addition & 1 deletion src/arclet/alconna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _(command: Alconna, arp: Arparma):
trigger
):
prompt_other = i18n.require("completion.prompt_other")
node = i18n.require('completion', 'node')
node = i18n.require("completion.node")
node = f"{node}\n" if node else ""
arp.output = f"{node}{prompt_other}" + f"\n{prompt_other}".join([i.text for i in res])
return True
Expand Down
16 changes: 10 additions & 6 deletions src/arclet/alconna/i18n/.config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"default": "zh-CN",
"frozen": [
"alconna.builtin"
],
"require": [
"alconna.builtin"
]
"frozen": {
"alconna": [
"builtin"
]
},
"require": {
"alconna": [
"builtin"
]
}
}
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 @@ -38,6 +38,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 @@ -16,6 +16,7 @@
"subtype": "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 @@ -7,6 +7,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 @@ -7,6 +7,7 @@
},
"completion": {
"node": "以下是建议的输入:",
"prompt_arg": "{name}: {prompt}",
"prompt_select": ">> ",
"prompt_other": "* ",
"prompt_empty": "没有可用的补全提示",
Expand Down
1 change: 0 additions & 1 deletion src/arclet/alconna/ingedia/_argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import InitVar, dataclass, field, fields
from typing import Any, Callable, ClassVar, Generic, Iterable, Literal
from typing_extensions import Self
from contextvars import ContextVar
from tarina import split, split_once

from ..i18n import i18n
Expand Down
11 changes: 7 additions & 4 deletions src/arclet/alconna/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .arparma import Arparma
from .base import Subcommand, SPECIAL_OPTIONS, Option
from .args import Arg
from .i18n import i18n

if TYPE_CHECKING:
from .core import Alconna
Expand All @@ -27,12 +28,13 @@ class EnterResult:
def _prompt_none(command: Alconna, args_got: list[str], opts_got: list[tuple[str, ...]]):
res: list[Prompt] = []
if unit := next((arg for arg in command.args if arg.name not in args_got), None):
template = i18n.require("completion.prompt_arg")
if not (comp := unit.field.get_completion()):
res.append(Prompt(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 command.options:
if isinstance(opt, SPECIAL_OPTIONS):
continue
Expand All @@ -47,12 +49,13 @@ def prompt(command: Alconna, buffer: list, args_got: list[str], opts_got: list[t
if isinstance(buffer[-1], str) and buffer[-1] in command.config.builtin_option_name["completion"]:
target = str(buffer[-2])
if isinstance(trigger, Arg):
template = i18n.require("completion.prompt_arg")
if not (comp := trigger.field.get_completion()):
return [Prompt(command.formatter.param(trigger), False)]
if isinstance(comp, str):
return [Prompt(f"{trigger.name}: {comp}", False)]
return [Prompt(template.format(name=trigger.name, prompt=comp), False)]
o = list(filter(lambda x: target in x, comp)) or comp
return [Prompt(f"{trigger.name}: {i}", False, target) for i in o]
return [Prompt(template.format(name=trigger.name, prompt=i), False, target) for i in o]
elif isinstance(trigger, Subcommand):
return [Prompt(i, True) for i in trigger._lookup_map if target in i]
if isinstance(trigger, str):
Expand Down

0 comments on commit 068e520

Please sign in to comment.