Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def layout_u2f():
if appid in knownapps.knownapps:
appname = knownapps.knownapps[appid]
appicon = res.load('apps/fido_u2f/res/u2f_%s.toif' %
appname.lower().replace(' ', '_'))
else:
appname = hexlify(appid[:4]) + '...' + hexlify(appid[-4:])
appicon = res.load('apps/fido_u2f/res/u2f_unknown.toif')
# paint background black
ui.display.bar(0, 0, 240, 240, ui.BLACK)
# top header bar
ui.display.text(10, 28, 'U2F Login', ui.BOLD, ui.WHITE, ui.BLACK)
# content
ui.display.text_center(120, 70, '%s:' % action, ui.BOLD, ui.GREY, ui.BLACK)
ui.display.image((240 - 64) // 2, 90, appicon)
ui.display.text_center(120, 185, appname, ui.MONO, ui.WHITE, ui.BLACK)
yield loop.Wait([])
ty = ay + ah // 2 + 8 # y-offset of the content
maxlen = const(14) # maximum text length
# input content
if len(t) > maxlen:
t = "<" + t[-maxlen:] # too long, align to the right
width = display.text_width(t, text_style)
display.text(tx, ty, t, text_style, fg_color, bg_color)
if p: # pending marker
pw = display.text_width(t[-1:], text_style)
px = tx + width - pw
display.bar(px, ty + 2, pw + 1, 3, fg_color)
else: # cursor
cx = tx + width + 1
display.bar(cx, ty - 18, 2, 22, fg_color)
t = self.text # input content
tx = ax + 24 # x-offset of the content
ty = ay + ah // 2 + 8 # y-offset of the content
maxlen = const(14) # maximum text length
# input content
if len(t) > maxlen:
t = "<" + t[-maxlen:] # too long, align to the right
width = display.text_width(t, text_style)
display.text(tx, ty, t, text_style, fg_color, bg_color)
if p: # pending marker
pw = display.text_width(t[-1:], text_style)
px = tx + width - pw
display.bar(px, ty + 2, pw + 1, 3, fg_color)
else: # cursor
cx = tx + width + 1
display.bar(cx, ty - 18, 2, 22, fg_color)
def test_bar(self):
display.bar(0, 0, 10, 10, 0xFFFF)
def func_middle(foreground):
ui.display.bar(106, 222, 28, 4, foreground, ui.BLACK, 2)
def layout_homescreen():
ui.display.bar(0, 0, 240, 48 * 4, ui.BLACK)
ui.display.bar(0, 48 * 4, 240, 48, c, ui.BLACK)
ui.display.text_center(120, 240 - 18, 'Hold to confirm', ui.BOLD, ui.WHITE, c)
p = 0
def func(foreground):
ui.display.loader(p, c, 0, res.load('apps/playground_stick/res/fingerprint.toig'), foreground)
p = (p + 10) % 1000
animation = ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
yield from animation
def render(self):
if self.input.content:
# content button and backspace
self.input.render()
self.back.render()
else:
# prompt
display.bar(0, 8, ui.WIDTH, 60, ui.BG)
display.text(20, 40, self.prompt, ui.BOLD, ui.GREY, ui.BG)
# key buttons
for btn in self.keys:
btn.render()