diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-11-07 19:43:13 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-11-07 19:43:13 +0100 |
commit | 04f103b9e67ccd1de7376be4f7b5156ec425e99c (patch) | |
tree | 6c4c93348040c7d4c8b51d5be025eff210735547 /src | |
parent | 1e1d977942c9358c3f0255b218ab13b47841bb11 (diff) | |
download | poezio-04f103b9e67ccd1de7376be4f7b5156ec425e99c.tar.gz poezio-04f103b9e67ccd1de7376be4f7b5156ec425e99c.tar.bz2 poezio-04f103b9e67ccd1de7376be4f7b5156ec425e99c.tar.xz poezio-04f103b9e67ccd1de7376be4f7b5156ec425e99c.zip |
Add a function to convert ncurses colors to HTML color code.
Diffstat (limited to 'src')
-rw-r--r-- | src/xhtml.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/xhtml.py b/src/xhtml.py index f6487905..2cedba7d 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -14,6 +14,7 @@ poezio colors to xhtml code import re import subprocess +import curses from sleekxmpp.xmlstream import ET from xml.etree.ElementTree import ElementTree from sys import version_info @@ -192,6 +193,29 @@ def get_body_from_message_stanza(message): return xhtml_to_poezio_colors(xhtml_body) return message['body'] +def ncurses_color_to_html(color): + """ + Takes an int between 0 and 256 and returns + a string of the form #XXXXXX representing an + html color. + """ + if color <= 15: + (r, g, b) = curses.color_content(color) + r = r / 1000 * 6 + g = g / 1000 * 6 + b = b / 1000 * 6 + elif color <= 231: + color = color - 16 + r = color % 6 + color = color / 6 + g = color % 6 + color = color / 6 + b = color % 6 + else: + color -= 232 + r = g = b = color / 24 * 6 + return '#%X%X%X' % (r*256/6, g*256/6, b*256/6) + def xhtml_to_poezio_colors(text): def parse_css(css): def get_color(value): @@ -324,7 +348,6 @@ def xhtml_to_poezio_colors(text): message += trim(elem.tail) return message - def clean_text(s): """ Remove all xhtml-im attributes (\x19etc) from the string with the |