feta:优化UI
This commit is contained in:
@@ -74,13 +74,29 @@ def _parse_choices(comment_text: str) -> dict[str, str] | None:
|
||||
return None
|
||||
|
||||
choices: dict[str, str] = {}
|
||||
for line in comment_text.splitlines():
|
||||
m = re.match(r"^\s*(\d+)\s*=\s*(.+?)\s*$", line)
|
||||
if not m:
|
||||
continue
|
||||
choices[m.group(1)] = m.group(2)
|
||||
token_re = re.compile(r"(\d+)\s*=\s*")
|
||||
|
||||
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:
|
||||
@@ -284,4 +300,3 @@ def parse_sandboxvars_lua(filepath: str, translations_json: str | None = None) -
|
||||
fixed_settings.append(s)
|
||||
|
||||
return ParsedConfig(source="lua", filepath=str(path), lines=lines, settings=fixed_settings)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user