diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-10-16 21:45:34 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-10-16 21:45:34 -0400 |
commit | cbcc7635cbf780555f1d183fdc3ef56f3330cd96 (patch) | |
tree | b80f4fa381a165bb6de489cee3b90a5f38e142c2 /termcast_server | |
parent | a5f25638d5b6076d4a1d1c0ffe647ab95edc91b7 (diff) | |
download | python-termcast-server-cbcc7635cbf780555f1d183fdc3ef56f3330cd96.tar.gz python-termcast-server-cbcc7635cbf780555f1d183fdc3ef56f3330cd96.zip |
also handle bold/italic/underline
Diffstat (limited to 'termcast_server')
-rw-r--r-- | termcast_server/index.html | 64 | ||||
-rw-r--r-- | termcast_server/termcast.py | 29 |
2 files changed, 73 insertions, 20 deletions
diff --git a/termcast_server/index.html b/termcast_server/index.html index cf65341..6b72eb1 100644 --- a/termcast_server/index.html +++ b/termcast_server/index.html @@ -309,7 +309,7 @@ socket.onmessage = function (e) { term += '<tr>'; row.forEach(function (cell) { term += '<td'; - if (cell.fgcolor || cell.bgcolor) { + if (cell.fgcolor != null || cell.bgcolor != null || cell.bold || cell.italic || cell.underline) { term += ' style="'; if (cell.fgcolor != null) { term += 'color: ' + colors[cell.fgcolor] + ';'; @@ -317,6 +317,15 @@ socket.onmessage = function (e) { if (cell.bgcolor != null) { term += 'background-color: ' + colors[cell.bgcolor] + ';'; } + if (cell.bold) { + term += 'font-weight: bold;'; + } + if (cell.italic) { + term += 'font-style: italic;'; + } + if (cell.underline) { + term += 'text-decoration: underline;'; + } term += '"'; } term += '>'; @@ -339,19 +348,52 @@ socket.onmessage = function (e) { data.updates.forEach(function (update) { var tr = termtable.children[update.row]; var td = tr.children[update.col]; - var contents = update.cell.contents; - if (contents == " " || contents == "") { - contents = " "; + if (update.cell.hasOwnProperty('contents')) { + var contents = update.cell.contents; + if (contents == " " || contents == "") { + contents = " "; + } + td.innerHTML = contents; } - td.innerHTML = contents; - if (update.cell.fgcolor != null) { - td.style.setProperty('color', colors[update.cell.fgcolor]); + if (update.cell.hasOwnProperty('fgcolor')) { + if (update.cell.fgcolor != null) { + td.style.setProperty('color', colors[update.cell.fgcolor]); + } + else { + td.style.removeProperty('color'); + } } - if (update.cell.bgcolor != null) { - td.style.setProperty('background-color', colors[update.cell.bgcolor]); + if (update.cell.hasOwnProperty('bgcolor')) { + if (update.cell.bgcolor != null) { + td.style.setProperty('background-color', colors[update.cell.bgcolor]); + } + else { + td.style.removeProperty('background-color'); + } } - else { - td.style.removeProperty('background-color'); + if (update.cell.hasOwnProperty('bold')) { + if (update.cell.bold) { + td.style.setProperty('font-weight', 'bold'); + } + else { + td.style.removeProperty('font-weight'); + } + } + if (update.cell.hasOwnProperty('italic')) { + if (update.cell.italic) { + td.style.setProperty('font-style', 'italic'); + } + else { + td.style.removeProperty('font-style'); + } + } + if (update.cell.hasOwnProperty('underline')) { + if (update.cell.underline) { + td.style.setProperty('text-decoration', 'underline'); + } + else { + td.style.removeProperty('text-decoration'); + } } }) } diff --git a/termcast_server/termcast.py b/termcast_server/termcast.py index 1bb6d15..8858fb3 100644 --- a/termcast_server/termcast.py +++ b/termcast_server/termcast.py @@ -73,6 +73,10 @@ class Handler(object): "contents": cell.contents(), "fgcolor": cell.fgcolor().color(), "bgcolor": cell.bgcolor().color(), + "bold": cell.bold(), + "italic": cell.italic(), + "underline": cell.underline(), + "inverse": cell.inverse(), }) return term @@ -83,18 +87,25 @@ class Handler(object): for j in range(0, self.cols): cell = self.vt.cell(i, j) prev_cell = screen[i][j] - contents = cell.contents() - fgcolor = cell.fgcolor().color() - bgcolor = cell.bgcolor().color() - if contents != prev_cell["contents"] or fgcolor != prev_cell["fgcolor"] or bgcolor != prev_cell["bgcolor"]: + cur_cell = { + "contents": cell.contents(), + "fgcolor": cell.fgcolor().color(), + "bgcolor": cell.bgcolor().color(), + "bold": cell.bold(), + "italic": cell.italic(), + "underline": cell.underline(), + "inverse": cell.inverse(), + } + cell_changes = {} + for key in cur_cell: + if cur_cell[key] != prev_cell[key]: + cell_changes[key] = cur_cell[key] + + if len(cell_changes) > 0: changes.append({ "row": i, "col": j, - "cell": { - "contents": contents, - "fgcolor": fgcolor, - "bgcolor": bgcolor, - }, + "cell": cell_changes, }) return changes |