def update(self, browse, head, quote, position, incorrect, author, title,
typed, wpm, average):
cols = curses.COLS
lengths = word_wrap(quote, cols - 1)
sx, sy = screen_coords(lengths, position)
h = len(lengths)
# Show header
self.window.addstr(0, 0, head + " "*(cols - len(head)),
curses.color_pair(2))
if browse:
# Display quote
color = curses.color_pair(4 if browse == 1 else 3)
for y, length in enumerate(lengths, 2):
self.window.addstr(y, 0, quote[:length], color)
quote = quote[1+length:]
# Show author
credit = u"— %s, %s" % (author, title)
self.cheight = 4 + h + self.column(3+h, cols - 10, cols//2, credit,
curses.color_pair(6), False)
if browse >= 2:
typed = "You scored %.1f wpm%s " % (wpm, "!" if wpm > average
else ".")
else:
typed = ""
typed += "Use arrows/space to browse, esc to quit, or start typing."
elif position < len(quote):
color = curses.color_pair(3 if incorrect == 0 else 1)
typed = "> " + typed
if position + incorrect < len(quote):
sx, sy = screen_coords(lengths, position + incorrect - 1)
self.window.chgat(2 + sy, max(sx, 0), 1, color)
sx, sy = screen_coords(lengths, position + incorrect + 1)
self.window.chgat(2 + sy, sx, curses.color_pair(4))
# Show typed text
if self.cheight < curses.LINES:
self.window.move(self.cheight, 0)
self.window.clrtoeol()
self.window.addstr(self.cheight, 0, typed, curses.color_pair(7))
if browse > 1:
# If done, highlight score
self.window.chgat(self.cheight, 11,
len(str("%.1f" % wpm)), curses.color_pair(9))
# Move cursor to current position in text before refreshing
if browse < 1:
sx, sy = screen_coords(lengths, position + incorrect)
self.window.move(2 + sy, min(sx, cols - 1))
else:
self.window.move(2, 0)
self.window.refresh()
评论列表
文章目录