summaryrefslogtreecommitdiff
path: root/src/xhtml.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-07 19:43:13 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-08 00:15:27 +0100
commitf271ef0620ab91573bfebb196ef5db54296bab4b (patch)
treef46f14fd76fc05a50b8b0edab2e652ee8203ff07 /src/xhtml.py
parent2c9cbc9f58cd167ba6a77932a57f50ca219b60a8 (diff)
downloadpoezio-f271ef0620ab91573bfebb196ef5db54296bab4b.tar.gz
poezio-f271ef0620ab91573bfebb196ef5db54296bab4b.tar.bz2
poezio-f271ef0620ab91573bfebb196ef5db54296bab4b.tar.xz
poezio-f271ef0620ab91573bfebb196ef5db54296bab4b.zip
Add a function to convert ncurses colors to HTML color code.
(cherry picked from commit 04f103b9e67ccd1de7376be4f7b5156ec425e99c)
Diffstat (limited to 'src/xhtml.py')
-rw-r--r--src/xhtml.py25
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