aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-06 14:59:37 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-06 14:59:37 -0400
commite2ef15ca99a79ac02457ddf18ffbf9c5c0720ee9 (patch)
treeb8270f52e04a63c7aaf2baf2d9002e6b859c029e
parent30729ca5c0a389781d6029d0134ac508db741475 (diff)
downloadpython-termcast-server-e2ef15ca99a79ac02457ddf18ffbf9c5c0720ee9.tar.gz
python-termcast-server-e2ef15ca99a79ac02457ddf18ffbf9c5c0720ee9.zip
add foreground and background colors to the web interface
-rw-r--r--termcast_server/index.html23
-rw-r--r--termcast_server/termcast.py5
2 files changed, 26 insertions, 2 deletions
diff --git a/termcast_server/index.html b/termcast_server/index.html
index 373587f..e12e578 100644
--- a/termcast_server/index.html
+++ b/termcast_server/index.html
@@ -16,6 +16,16 @@
}
</style>
<script>
+var colors = [
+ "#000000",
+ "#ff0000",
+ "#00ff00",
+ "#ffff00",
+ "#0000ff",
+ "#ff00ff",
+ "#00ffff",
+ "#ffffff",
+];
var url = location.origin.replace(/^http/, 'ws') + "/-/";
socket = new WebSocket(url);
socket.onopen = function (e) {
@@ -44,7 +54,18 @@ socket.onmessage = function (e) {
data.screen.forEach(function (row) {
term += '<tr>';
row.forEach(function (cell) {
- term += '<td>' + cell.contents + '</td>';
+ term += '<td';
+ if (cell.fgcolor || cell.bgcolor) {
+ term += ' style="';
+ if (cell.fgcolor) {
+ term += 'color: ' + colors[cell.fgcolor] + ';';
+ }
+ if (cell.bgcolor) {
+ term += 'background-color: ' + colors[cell.bgcolor] + ';';
+ }
+ term += '"';
+ }
+ term += '>' + cell.contents + '</td>';
});
term += '</td>';
});
diff --git a/termcast_server/termcast.py b/termcast_server/termcast.py
index 28be7a0..743274b 100644
--- a/termcast_server/termcast.py
+++ b/termcast_server/termcast.py
@@ -67,11 +67,14 @@ class Handler(object):
for i in range(0, self.rows):
term.append([])
for j in range(0, self.cols):
- contents = self.vt.cell(i, j).contents()
+ cell = self.vt.cell(i, j)
+ contents = cell.contents()
if len(contents) == 0:
contents = " "
term[i].append({
"contents": contents,
+ "fgcolor": cell.fgcolor().color(),
+ "bgcolor": cell.bgcolor().color(),
})
return term