From c2c703aec4c83bd0933dd9312377501818fe0420 Mon Sep 17 00:00:00 2001 From: q Date: Mon, 13 Oct 2025 10:04:42 +0300 Subject: [PATCH] more subtle visual aid --- shell/qaskpass | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/shell/qaskpass b/shell/qaskpass index c246b87..9a3ba30 100755 --- a/shell/qaskpass +++ b/shell/qaskpass @@ -10,7 +10,7 @@ import sys import termios import tty -__version__ = "20250724.a" +__version__ = "20251013.a" class bc: @@ -51,6 +51,9 @@ class QAsk: self.user_input = "" 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.no_pw = "•" + self.is_correct = "♥" + self.rand_chr = "■" # "╩╦═╬╧╤╪" def get_opts(self): 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." ) 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( "--expect-sha256", action="store", @@ -115,16 +119,25 @@ class QAsk: return clr + self.eq[int(rheight + (i / self.opts.w)) % 14] else: # no measure + if self.opts.eq: + if len(self.user_input) == 0: + rheight = random.randint(0, 1) + height = 0 + clr = self.limits[0][0] + 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.eq[int(rheight + height) % 14] if len(self.user_input) == 0: - rheight = random.randint(0, 1) - height = 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.eq[int(rheight + height) % 14] + return clr + self.rand_chr[int(rheight + height) % len(self.rand_chr)] def pquit(self, s="", e=0): print(self.c.blink, file=sys.stderr, end="") @@ -138,7 +151,7 @@ class QAsk: if self.opts.expect_sha256: if self.sha256 == self.opts.expect_sha256: self.dot_color = self.c.G - self.dot = "♥" + self.dot = self.is_correct self.enter_exitcode = 0 else: self.enter_exitcode = 10 @@ -156,7 +169,7 @@ class QAsk: def ask(self): print(self.c.noblink, file=sys.stderr, end="") - self.dot = "•" + self.dot = self.no_pw if self.opts.title: title = self.c.format(self.opts.title) print(f"{self.c.Y}{title}{self.c.z}", file=sys.stderr) @@ -166,7 +179,7 @@ class QAsk: self.enter_exitcode = 0 if self.opts.w > 0: self.dot_color = self.c.m - self.dot = "•" + self.dot = self.no_pw self.check_sha256() display = "".join( [ @@ -178,7 +191,6 @@ class QAsk: print(display, file=sys.stderr, end="") sys.stderr.flush() key = self.get_chr() - # ~ print(f'-{key}{key}{key}{key}{key}///{ord(key)}///{len(key)}-',file=sys.stderr) if ord(key) == 3: # ctrl-c self.pquit(e=1) elif ord(key) == 13: # enter