mirror of
https://github.com/9001/copyparty.git
synced 2025-09-28 20:52:26 -06:00
fix --help on non-utf8 consoles
This commit is contained in:
parent
9c9e4057e0
commit
3f45492725
|
@ -1738,7 +1738,7 @@ def add_og(ap):
|
||||||
ap2.add_argument("--uqe", action="store_true", help="query-string parceling; translate a request for \033[33m/foo/.uqe/BASE64\033[0m into \033[33m/foo?TEXT\033[0m, or \033[33m/foo/?TEXT\033[0m if the first character in \033[33mTEXT\033[0m is a slash. Automatically enabled for \033[33m--og\033[0m")
|
ap2.add_argument("--uqe", action="store_true", help="query-string parceling; translate a request for \033[33m/foo/.uqe/BASE64\033[0m into \033[33m/foo?TEXT\033[0m, or \033[33m/foo/?TEXT\033[0m if the first character in \033[33mTEXT\033[0m is a slash. Automatically enabled for \033[33m--og\033[0m")
|
||||||
|
|
||||||
|
|
||||||
def add_ui(ap, retry):
|
def add_ui(ap, retry: int):
|
||||||
THEMES = 10
|
THEMES = 10
|
||||||
ap2 = ap.add_argument_group("ui options")
|
ap2 = ap.add_argument_group("ui options")
|
||||||
ap2.add_argument("--grid", action="store_true", help="show grid/thumbnails by default (volflag=grid)")
|
ap2.add_argument("--grid", action="store_true", help="show grid/thumbnails by default (volflag=grid)")
|
||||||
|
@ -1813,7 +1813,7 @@ def add_debug(ap):
|
||||||
|
|
||||||
|
|
||||||
def run_argparse(
|
def run_argparse(
|
||||||
argv: list[str], formatter: Any, retry: bool, nc: int, verbose=True
|
argv: list[str], formatter: Any, retry: int, nc: int, verbose=True
|
||||||
) -> argparse.Namespace:
|
) -> argparse.Namespace:
|
||||||
ap = argparse.ArgumentParser(
|
ap = argparse.ArgumentParser(
|
||||||
formatter_class=formatter,
|
formatter_class=formatter,
|
||||||
|
@ -1880,18 +1880,21 @@ def run_argparse(
|
||||||
for k, h, _ in sects:
|
for k, h, _ in sects:
|
||||||
ap2.add_argument("--help-" + k, action="store_true", help=h)
|
ap2.add_argument("--help-" + k, action="store_true", help=h)
|
||||||
|
|
||||||
try:
|
if retry:
|
||||||
if not retry:
|
a = ["ascii", "replace"]
|
||||||
raise Exception()
|
|
||||||
|
|
||||||
for x in ap._actions:
|
for x in ap._actions:
|
||||||
if not x.help:
|
try:
|
||||||
continue
|
x.default = x.default.encode(*a).decode(*a)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
a = ["ascii", "replace"]
|
try:
|
||||||
x.help = x.help.encode(*a).decode(*a) + "\033[0m"
|
if x.help and x.help is not argparse.SUPPRESS:
|
||||||
except:
|
x.help = x.help.replace("└─", "`-").encode(*a).decode(*a)
|
||||||
pass
|
if retry > 2:
|
||||||
|
x.help = RE_ANSI.sub("", x.help)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
ret = ap.parse_args(args=argv[1:])
|
ret = ap.parse_args(args=argv[1:])
|
||||||
for k, h, t in sects:
|
for k, h, t in sects:
|
||||||
|
@ -2001,7 +2004,7 @@ def main(argv: Optional[list[str]] = None) -> None:
|
||||||
except:
|
except:
|
||||||
nc = 486 # mdns/ssdp restart headroom; select() maxfd is 512 on windows
|
nc = 486 # mdns/ssdp restart headroom; select() maxfd is 512 on windows
|
||||||
|
|
||||||
retry = False
|
retry = 0
|
||||||
for fmtr in [RiceFormatter, RiceFormatter, Dodge11874, BasicDodge11874]:
|
for fmtr in [RiceFormatter, RiceFormatter, Dodge11874, BasicDodge11874]:
|
||||||
try:
|
try:
|
||||||
al = run_argparse(argv, fmtr, retry, nc)
|
al = run_argparse(argv, fmtr, retry, nc)
|
||||||
|
@ -2010,8 +2013,9 @@ def main(argv: Optional[list[str]] = None) -> None:
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
retry = True
|
retry += 1
|
||||||
lprint("\n[ {} ]:\n{}\n".format(fmtr, min_ex()))
|
t = "WARNING: due to limitations in your terminal and/or OS, the helptext cannot be displayed correctly. Will show a simplified version due to the following error:\n[ %s ]:\n%s\n"
|
||||||
|
lprint(t % (fmtr, min_ex()))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert al # type: ignore
|
assert al # type: ignore
|
||||||
|
|
Loading…
Reference in a new issue