feta:优化UI

This commit is contained in:
2025-12-26 18:49:28 +08:00
parent fd15f9eb8f
commit 1e9108bee5
2 changed files with 22 additions and 7 deletions

View File

@@ -74,13 +74,29 @@ def _parse_choices(comment_text: str) -> dict[str, str] | None:
return None return None
choices: dict[str, str] = {} choices: dict[str, str] = {}
for line in comment_text.splitlines(): token_re = re.compile(r"(\d+)\s*=\s*")
m = re.match(r"^\s*(\d+)\s*=\s*(.+?)\s*$", line)
if not m:
continue
choices[m.group(1)] = m.group(2)
return choices or None for line in comment_text.splitlines():
s = line.lstrip()
matches = list(token_re.finditer(s))
if not matches:
continue
if len(matches) == 1 and matches[0].start() != 0:
# Avoid false positives such as "... (0=无限制)" inside a sentence.
continue
for i, m in enumerate(matches):
key = m.group(1)
start = m.end()
end = matches[i + 1].start() if i + 1 < len(matches) else len(s)
label = s[start:end].strip().strip(",;|/、").strip()
if not label:
continue
choices[key] = label
# Single "0=Disabled" style hints are common in server.ini, but they are not real enums.
# Only treat it as an enum when there are at least 2 options.
return choices if len(choices) >= 2 else None
def parse_server_ini(filepath: str) -> ParsedConfig: def parse_server_ini(filepath: str) -> ParsedConfig:
@@ -284,4 +300,3 @@ def parse_sandboxvars_lua(filepath: str, translations_json: str | None = None) -
fixed_settings.append(s) fixed_settings.append(s)
return ParsedConfig(source="lua", filepath=str(path), lines=lines, settings=fixed_settings) return ParsedConfig(source="lua", filepath=str(path), lines=lines, settings=fixed_settings)