From f047449344fecec789fcc030a050c979a328a52e Mon Sep 17 00:00:00 2001 From: Harshad Sharma Date: Fri, 16 Jun 2017 21:19:44 +0530 Subject: [PATCH] Add: barebones html template. --- src/qutescript/utils.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/qutescript/utils.py b/src/qutescript/utils.py index ce378a0..988c1b2 100644 --- a/src/qutescript/utils.py +++ b/src/qutescript/utils.py @@ -3,7 +3,19 @@ import os import tempfile -HTML_TEMPLATE = """\ +HTML_BODY = """\ + + +
+{}
+
+
+"""
+
+HTML_MESSAGE_TEMPLATE = """\
+
+{}
+
""" log_file_path = './qutescript.log' @@ -32,7 +44,9 @@ def log_to_browser(*messages, prefix: str = None, console=True): Attempt to open the file through FIFO in the browser. """ [write_log(msg, console=console) for msg in messages] - send_to_browser('\n'.join(messages), prefix=prefix) + html_messages = '\n'.join([HTML_MESSAGE_TEMPLATE.format(m) for m in messages]) + html_body = HTML_BODY.format(html_messages) + send_to_browser(html_body, prefix=prefix) def send_to_browser(text, prefix: str = None): @@ -43,7 +57,7 @@ def send_to_browser(text, prefix: str = None): prefix = normalize_prefix(prefix) prefix = 'qutescript_{}'.format((prefix or '')) with tempfile.NamedTemporaryFile(mode='w', prefix=prefix, suffix='.html', delete=False) as out_file: - out_file.writelines(HTML_TEMPLATE.format(text)) + out_file.writelines(text) with open(fifo, 'w') as fifo_file: fifo_file.write('open -t file://{}'.format( os.path.abspath(out_file.name)))