rewrite coloring
This commit is contained in:
@@ -10,7 +10,7 @@ import sys
|
||||
import termios
|
||||
import tty
|
||||
|
||||
__version__ = "20251013.a"
|
||||
__version__ = "20251126.a"
|
||||
|
||||
|
||||
class bc:
|
||||
@@ -50,7 +50,15 @@ class QAsk:
|
||||
self.c.disable()
|
||||
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.limits = (
|
||||
(self.c.r, 2, "r"),
|
||||
(self.c.y, 4, "y"),
|
||||
(self.c.B, 7, "B"),
|
||||
(self.c.c, 9, "c"),
|
||||
(self.c.g, 12, "g"),
|
||||
(self.c.G, 15, "G"),
|
||||
)
|
||||
self.color_hash = ((self.c.r, "r"), (self.c.g, "g"), (self.c.B, "B"), (self.c.c, "c"), (self.c.y, "y"))
|
||||
self.no_pw = "•"
|
||||
self.is_correct = "♥"
|
||||
self.rand_chr = "■" # "╩╦═╬╧╤╪"
|
||||
@@ -74,6 +82,12 @@ class QAsk:
|
||||
parser.add_argument("--no-color", action="store_true", default=False, help="Disable colors")
|
||||
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(
|
||||
"--export",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="output the --title to be used with given password, instead of the password",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--expect-sha256",
|
||||
action="store",
|
||||
@@ -102,6 +116,9 @@ class QAsk:
|
||||
score *= 2
|
||||
return score
|
||||
|
||||
def get_color_hash(self, i):
|
||||
return self.color_hash[int(self.sha256[(1 + i * 2) % len(self.sha256)], 16) % len(self.color_hash)]
|
||||
|
||||
def animchar(self, pos):
|
||||
"""Returns one character, based on pwscore or pw hash"""
|
||||
i = len(self.user_input) - pos
|
||||
@@ -119,26 +136,37 @@ class QAsk:
|
||||
return clr + self.eq[int(rheight + (i / self.opts.w)) % 14]
|
||||
|
||||
else: # no measure
|
||||
rheight = random.randint(-1, 1)
|
||||
height = int(self.sha256[i * 2 % len(self.sha256)], 16) / 2
|
||||
clr = self.get_color_hash(i)[0]
|
||||
if self.opts.eq:
|
||||
if len(self.user_input) == 0:
|
||||
rheight = random.randint(0, 1)
|
||||
height = 0
|
||||
clr = self.limits[0][0]
|
||||
clr = self.color_hash[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]
|
||||
pass
|
||||
return clr + self.eq[int(rheight + height) % len(self.eq)]
|
||||
if len(self.user_input) == 0:
|
||||
clr = self.limits[0][0]
|
||||
clr = self.color_hash[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 get_export(self):
|
||||
title = ["-t 'Password hint: "]
|
||||
for pos in range(self.opts.w):
|
||||
i = len(self.user_input) - pos
|
||||
animchar = self.animchar(i)
|
||||
if self.opts.eq:
|
||||
pass
|
||||
else:
|
||||
a = self.get_color_hash(i)[1]
|
||||
title.append("{" + a + "}" + animchar[-1])
|
||||
title.append("'\n")
|
||||
|
||||
return "".join(title)
|
||||
|
||||
def pquit(self, s="", e=0):
|
||||
print(self.c.blink, file=sys.stderr, end="")
|
||||
print(self.c.z, file=sys.stderr)
|
||||
@@ -194,7 +222,11 @@ class QAsk:
|
||||
if ord(key) == 3: # ctrl-c
|
||||
self.pquit(e=1)
|
||||
elif ord(key) == 13: # enter
|
||||
self.pquit(self.user_input, e=self.enter_exitcode)
|
||||
if self.opts.export:
|
||||
msg = self.get_export()
|
||||
else:
|
||||
msg = self.user_input
|
||||
self.pquit(msg, e=self.enter_exitcode)
|
||||
elif ord(key) == 27: # esc (also starts control characters
|
||||
key = self.get_chr()
|
||||
if ord(key) == 27:
|
||||
|
||||
Reference in New Issue
Block a user