support old linux consoles

This commit is contained in:
ed 2022-11-06 16:58:00 +00:00
parent c72753c5da
commit fc0a941508
2 changed files with 26 additions and 7 deletions

View file

@ -429,6 +429,8 @@ def run_argparse(
hcores = min(CORES, 3) # 4% faster than 4+ on py3.9 @ r5-4500U
tty = os.environ.get("TERM", "").lower() == "linux"
sects = [
[
"accounts",
@ -590,10 +592,10 @@ def run_argparse(
ap2.add_argument("--qrs", action="store_true", help="show https:// QR-code on startup")
ap2.add_argument("--qrl", metavar="PATH", type=u, default="", help="location to include in the url, for example [\033[32mpriv/?pw=hunter2\033[0m]")
ap2.add_argument("--qri", metavar="PREFIX", type=u, default="", help="select IP which starts with PREFIX")
ap2.add_argument("--qr-fg", metavar="COLOR", type=int, default=16, help="foreground")
ap2.add_argument("--qr-fg", metavar="COLOR", type=int, default=0 if tty else 16, help="foreground; try [\033[32m0\033[0m] if the qr-code is unreadable")
ap2.add_argument("--qr-bg", metavar="COLOR", type=int, default=229, help="background (white=255)")
ap2.add_argument("--qrp", metavar="CELLS", type=int, default=4, help="padding (spec says 4 or more, but 1 is usually fine)")
ap2.add_argument("--qrz", metavar="N", type=int, default=0, help="[\033[32m1\033[0m]=1x, [\033[32m2\033[0m]=2x, [\033[32m0\033[0m]=auto (try 2 on broken fonts)")
ap2.add_argument("--qrz", metavar="N", type=int, default=0, help="[\033[32m1\033[0m]=1x, [\033[32m2\033[0m]=2x, [\033[32m0\033[0m]=auto (try [\033[32m2\033[0m] on broken fonts)")
ap2 = ap.add_argument_group('upload options')
ap2.add_argument("--dotpart", action="store_true", help="dotfile incomplete uploads, hiding them from clients unless -ed")
@ -795,6 +797,19 @@ def run_argparse(
for k, h, _ in sects:
ap2.add_argument("--help-" + k, action="store_true", help=h)
try:
if not retry:
raise Exception()
for x in ap._actions:
if not x.help:
continue
a = ["ascii", "replace"]
x.help = x.help.encode(*a).decode(*a) + "\033[0m"
except:
pass
ret = ap.parse_args(args=argv[1:])
for k, h, t in sects:
k2 = "help_" + k.replace("-", "_")

View file

@ -473,7 +473,7 @@ class TcpSrv(object):
title += "{} ".format(p)
print("\033]0;{}\033\\".format(title), file=sys.stderr, end="")
print("\033]0;{}\033\\\n".format(title), file=sys.stderr, end="")
sys.stderr.flush()
def _qr(self, t1: dict[str, list[int]], t2: dict[str, list[int]]) -> str:
@ -526,13 +526,17 @@ class TcpSrv(object):
if not VT100:
return "{}\n{}".format(txt, qr)
halfc = "\033[40;48;5;{0}m{1}\033[47;48;5;{2}m"
if not fg:
halfc = "\033[0;40m{1}\033[0;47m"
def ansify(m: re.Match) -> str:
t = "\033[40;48;5;{}m{}\033[47;48;5;{}m"
return t.format(fg, " " * len(m.group(1)), bg)
return halfc.format(fg, " " * len(m.group(1)), bg)
if zoom > 1:
qr = re.sub("(█+)", ansify, qr)
qr = qr.replace("\n", "\033[K\n") + "\033[K" # win10do
t = "{} \033[0;38;5;{};48;5;{}m\n{}\033[999G\033[0m\033[J"
return t.format(txt, fg, bg, qr)
cc = " \033[0;38;5;{0};47;48;5;{1}m" if fg else " \033[0;30;47m"
t = cc + "\n{2}\033[999G\033[0m\033[J"
return txt + t.format(fg, bg, qr)