From 68dbff765c25cab8acdd3a40015cd2690b71e6a0 Mon Sep 17 00:00:00 2001 From: Mike Mueller Date: Tue, 24 Apr 2012 17:07:13 -0700 Subject: [PATCH] Compact color codes in Worddle results. Previously every word would be LCYAN+word+LGRAY (or GRAY+word+LGRAY) and all these extra color codes would cause the message to be truncated when a lot of words are found. Compacted by only sending a color code when a color change is needed. --- plugin.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugin.py b/plugin.py index 532c4d3..ba3cedb 100644 --- a/plugin.py +++ b/plugin.py @@ -391,17 +391,20 @@ class Worddle(BaseGame): "Return the words in this result, colorized appropriately." words = sorted(list(self.unique) + list(self.dup)) words_text = '' + last_color = LGRAY for word in words: - if word in self.unique: - color = LCYAN - else: - color = GRAY + color = LCYAN if word in self.unique else GRAY + if color != last_color: + words_text += color + last_color = color if len(word) == longest_len: word += LYELLOW + '*' - words_text += '%s%s%s ' % (color, word, LGRAY) + last_color = LYELLOW + words_text += '%s ' % word if not words_text: - words_text = '%s-none-%s' % (GRAY, LGRAY) - return words_text.strip() + words_text = '%s-none-' % (GRAY) + words_text = words_text.strip() + LGRAY + return words_text class Results: "Represents results for all players."