more subtle visual aid

This commit is contained in:
q
2025-10-13 10:04:42 +03:00
parent 0a1ff91b35
commit c2c703aec4

View File

@@ -10,7 +10,7 @@ import sys
import termios import termios
import tty import tty
__version__ = "20250724.a" __version__ = "20251013.a"
class bc: class bc:
@@ -51,6 +51,9 @@ class QAsk:
self.user_input = "" self.user_input = ""
self.eq = "▁▂▃▄▅▆▇█▇▆▅▄▃▂" self.eq = "▁▂▃▄▅▆▇█▇▆▅▄▃▂"
self.limits = ((self.c.r, 2), (self.c.y, 4), (self.c.B, 7), (self.c.c, 9), (self.c.g, 12), (self.c.G, 15)) self.limits = ((self.c.r, 2), (self.c.y, 4), (self.c.B, 7), (self.c.c, 9), (self.c.g, 12), (self.c.G, 15))
self.no_pw = "•"
self.is_correct = "♥"
self.rand_chr = "■" # "╩╦═╬╧╤╪"
def get_opts(self): def get_opts(self):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@@ -69,7 +72,8 @@ class QAsk:
"-w", action="store", type=int, default=3, help="Width of display area. 0 to disable display." "-w", action="store", type=int, default=3, help="Width of display area. 0 to disable display."
) )
parser.add_argument("--no-color", action="store_true", default=False, help="Disable colors") parser.add_argument("--no-color", action="store_true", default=False, help="Disable colors")
parser.add_argument("--measure", action="store_true", default=False, help="Also measure password goodness") parser.add_argument("--measure", action="store_true", default=False, help="Measure password goodness")
parser.add_argument("--eq", action="store_true", default=False, help="Visual aid EQ mode.")
parser.add_argument( parser.add_argument(
"--expect-sha256", "--expect-sha256",
action="store", action="store",
@@ -115,6 +119,7 @@ class QAsk:
return clr + self.eq[int(rheight + (i / self.opts.w)) % 14] return clr + self.eq[int(rheight + (i / self.opts.w)) % 14]
else: # no measure else: # no measure
if self.opts.eq:
if len(self.user_input) == 0: if len(self.user_input) == 0:
rheight = random.randint(0, 1) rheight = random.randint(0, 1)
height = 0 height = 0
@@ -125,6 +130,14 @@ class QAsk:
clr = self.limits[int(self.sha256[(1 + i * 2) % len(self.sha256)], 16) % len(self.limits)][0] clr = self.limits[int(self.sha256[(1 + i * 2) % len(self.sha256)], 16) % len(self.limits)][0]
return clr + self.eq[int(rheight + height) % 14] return clr + self.eq[int(rheight + height) % 14]
if len(self.user_input) == 0:
clr = self.limits[0][0]
return clr + self.no_pw
else:
rheight = random.randint(-1, 1)
height = int(self.sha256[i * 2 % len(self.sha256)], 16) / 2
clr = self.limits[int(self.sha256[(1 + i * 2) % len(self.sha256)], 16) % len(self.limits)][0]
return clr + self.rand_chr[int(rheight + height) % len(self.rand_chr)]
def pquit(self, s="", e=0): def pquit(self, s="", e=0):
print(self.c.blink, file=sys.stderr, end="") print(self.c.blink, file=sys.stderr, end="")
@@ -138,7 +151,7 @@ class QAsk:
if self.opts.expect_sha256: if self.opts.expect_sha256:
if self.sha256 == self.opts.expect_sha256: if self.sha256 == self.opts.expect_sha256:
self.dot_color = self.c.G self.dot_color = self.c.G
self.dot = "♥" self.dot = self.is_correct
self.enter_exitcode = 0 self.enter_exitcode = 0
else: else:
self.enter_exitcode = 10 self.enter_exitcode = 10
@@ -156,7 +169,7 @@ class QAsk:
def ask(self): def ask(self):
print(self.c.noblink, file=sys.stderr, end="") print(self.c.noblink, file=sys.stderr, end="")
self.dot = "•" self.dot = self.no_pw
if self.opts.title: if self.opts.title:
title = self.c.format(self.opts.title) title = self.c.format(self.opts.title)
print(f"{self.c.Y}{title}{self.c.z}", file=sys.stderr) print(f"{self.c.Y}{title}{self.c.z}", file=sys.stderr)
@@ -166,7 +179,7 @@ class QAsk:
self.enter_exitcode = 0 self.enter_exitcode = 0
if self.opts.w > 0: if self.opts.w > 0:
self.dot_color = self.c.m self.dot_color = self.c.m
self.dot = "•" self.dot = self.no_pw
self.check_sha256() self.check_sha256()
display = "".join( display = "".join(
[ [
@@ -178,7 +191,6 @@ class QAsk:
print(display, file=sys.stderr, end="") print(display, file=sys.stderr, end="")
sys.stderr.flush() sys.stderr.flush()
key = self.get_chr() key = self.get_chr()
# ~ print(f'-{key}{key}{key}{key}{key}///{ord(key)}///{len(key)}-',file=sys.stderr)
if ord(key) == 3: # ctrl-c if ord(key) == 3: # ctrl-c
self.pquit(e=1) self.pquit(e=1)
elif ord(key) == 13: # enter elif ord(key) == 13: # enter