Skip to content

Commit

Permalink
gateone.js: Modified GateOne.Utils.loadStyle() slightly... It will no…
Browse files Browse the repository at this point in the history
…w set the "media" attribute to "screen" on loaded stylesheets. This is to differentiate them from media="print".

gateone.js:  Got rid of a trailing comma near the end of the script (where it sets the defaults for GateOne.Net.actions) that was causing IE 8 (and below) to barf and not display the error message that tells the user why Gate One won't work in their terrible browser :).  For reference, trailing commas at the end of objects inside of curley braces is perfectly valid JavaScript.  IE just sucks.
gateone.py:  Added support for print style sheets to TerminalWebSocket.get_style() and GateOne.Utils.loadStyle() (in gateone.js).  Turns out this was much easier than I thought.
Templates:  Added a stylesheet for printing (gateone/templates/printing/default.css).  It's trivial, really:  It just makes sure that when you print out your terminal it will be black-on-white text.  Works great from the "Printable" log view (aka "flat" format).
Logging Plugin:  A few tweaks to the "Printable" view to make it look better when, er, printed.
NOTE:  The reason I added the new media="print" stylesheet feature is because printing from the "Printable" (flat) log view wasn't working properly when a dark theme was set.  So it's really a kind of bug fix :)
  • Loading branch information
liftoff committed Sep 14, 2012
1 parent b44560d commit 6f92ff3
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 32 deletions.
41 changes: 28 additions & 13 deletions gateone/gateone.py
Expand Up @@ -1898,12 +1898,14 @@ def get_style(self, settings):
* **theme** - The name of the CSS theme to be retrieved.
* **colors** - The name of the text color CSS scheme to be retrieved.
* **plugins** - If true, will send all plugin .css files to the client.
* **print** - If true, will send the print stylesheet.
"""
logging.debug('get_style(%s)' % settings)
out_dict = {'result': 'Success'}
templates_path = os.path.join(GATEONE_DIR, 'templates')
themes_path = os.path.join(templates_path, 'themes')
colors_path = os.path.join(templates_path, 'term_colors')
printing_path = os.path.join(templates_path, 'printing')
go_url = settings['go_url'] # Used to prefix the url_prefix
if not go_url.endswith('/'):
go_url += '/'
Expand All @@ -1918,20 +1920,23 @@ def get_style(self, settings):
plugins = None
if 'plugins' in settings:
plugins = settings["plugins"]
_print = None
if 'print' in settings:
_print = settings["print"]
# Setup our 256-color support CSS:
colors_256 = ""
for i in xrange(256):
fg = "#%s span.fx%s {color: #%s;}" % (
container, i, COLORS_256[i])
bg = "#%s span.bx%s {background-color: #%s;} " % (
container, i, COLORS_256[i])
fg_rev = "#%s span.reverse.fx%s {background-color: #%s; color: inherit;}" % (
container, i, COLORS_256[i])
bg_rev = "#%s span.reverse.bx%s {color: #%s; background-color: inherit;} " % (
container, i, COLORS_256[i])
colors_256 += "%s %s %s %s\n" % (fg, bg, fg_rev, bg_rev)
colors_256 += "\n"
if theme:
# Setup our 256-color support CSS:
colors_256 = ""
for i in xrange(256):
fg = "#%s span.fx%s {color: #%s;}" % (
container, i, COLORS_256[i])
bg = "#%s span.bx%s {background-color: #%s;} " % (
container, i, COLORS_256[i])
fg_rev = "#%s span.reverse.fx%s {background-color: #%s; color: inherit;}" % (
container, i, COLORS_256[i])
bg_rev = "#%s span.reverse.bx%s {color: #%s; background-color: inherit;} " % (
container, i, COLORS_256[i])
colors_256 += "%s %s %s %s\n" % (fg, bg, fg_rev, bg_rev)
colors_256 += "\n"
theme_path = os.path.join(themes_path, "%s.css" % theme)
theme_css = self.render_string(
theme_path,
Expand Down Expand Up @@ -1975,6 +1980,16 @@ def get_style(self, settings):
if bytes != str: # Python 3
plugin_css = str(plugin_css, 'UTF-8')
out_dict['plugins'][plugin] += plugin_css
if _print:
print_css_path = os.path.join(printing_path, "default.css")
print_css = self.render_string(
print_css_path,
container=container,
prefix=prefix,
colors_256=colors_256,
url_prefix=go_url
)
out_dict['print'] = print_css
self.write_message(json_encode({'load_style': out_dict}))

# NOTE: This has been disabled for now. It works OK but the problem is that
Expand Down
5 changes: 3 additions & 2 deletions gateone/plugins/logging/static/logging.js
Expand Up @@ -749,7 +749,7 @@ GateOne.Base.update(GateOne.Logging, {
logLines = message['log'],
metadata = message['metadata'],
logViewContent = u.createElement('div', {'id': 'logview_content'}),
logContainer = u.createElement('div', {'id': 'logview', 'class': 'terminal', 'style': {'width': '100%', 'height': '100%'}});
logContainer = u.createElement('div', {'id': 'logview', 'class': 'terminal'});
if (result != "Success") {
v.displayMessage("Could not retrieve log: " + result);
} else {
Expand All @@ -767,8 +767,9 @@ GateOne.Base.update(GateOne.Logging, {
}
});
newWindow.document.body.appendChild(goDiv);
logContainer.innerHTML = '<pre style="height: 100%; overflow: auto; position: static;">' + logLines.join('\n') + '</pre>';
logContainer.innerHTML = '<pre style="overflow: visible; position: static; white-space: pre-wrap;">' + logLines.join('\n') + '</pre>';
logViewContent.appendChild(logContainer);
goDiv.style['overflow'] = 'visible';
goDiv.appendChild(logViewContent);
}
},
Expand Down
31 changes: 17 additions & 14 deletions gateone/static/gateone.js
Expand Up @@ -1130,7 +1130,7 @@ GateOne.Base.update(GateOne.Utils, {
if (message['result'] == 'Success') {
if (message['theme']) {
var existing = u.getNode('#'+prefix+'theme'),
stylesheet = u.createElement('style', {'id': 'theme'});
stylesheet = u.createElement('style', {'id': 'theme', 'rel': 'stylesheet', 'type': 'text/css', 'media': 'screen'});
stylesheet.textContent = message['theme'];
if (existing) {
existing.textContent = message['theme'];
Expand All @@ -1140,7 +1140,7 @@ GateOne.Base.update(GateOne.Utils, {
}
if (message['colors']) {
var existing = u.getNode('#'+prefix+'colors'),
stylesheet = u.createElement('style', {'id': 'colors'}),
stylesheet = u.createElement('style', {'id': 'colors', 'rel': 'stylesheet', 'type': 'text/css', 'media': 'screen'}),
themeStyle = u.getNode('#'+prefix+'theme'); // Theme should always be last so it can override defaults and plugins
stylesheet.textContent = message['colors'];
if (existing) {
Expand All @@ -1156,7 +1156,7 @@ GateOne.Base.update(GateOne.Utils, {
continue; // Nothing to load
}
var existing = u.getNode('#'+prefix+plugin+"_css"),
stylesheet = u.createElement('style', {'id': plugin+"_css"}),
stylesheet = u.createElement('style', {'id': plugin+"_css", 'rel': 'stylesheet', 'type': 'text/css', 'media': 'screen'}),
themeStyle = u.getNode('#'+prefix+'theme'); // Theme should always be last so it can override defaults and plugins
stylesheet.textContent = message['plugins'][plugin];
if (existing) {
Expand All @@ -1166,16 +1166,19 @@ GateOne.Base.update(GateOne.Utils, {
}
}
}
// Force the terminals to be re-drawn by the browser to ensure the text stays visible
// setTimeout(function() {
// var terminals = u.toArray(u.getNodes(go.prefs.goDiv+' .terminal pre'));
// terminals.forEach(function(termPre) {
// var term = termPre.id.split('_')[1].split('term')[1]; // go_term1_pre
// termPre.innerHTML = GateOne.terminals[term]['screen'].join('\n') + '\n\n';
// });
// }, 500);
if (message['print']) {
var colors = u.getNode('#'+prefix+'colors'),
existing = u.getNode('#'+prefix+'print'),
stylesheet = u.createElement('style', {'id': 'print', 'rel': 'stylesheet', 'type': 'text/css', 'media': 'print'});
stylesheet.textContent = message['print'];
if (existing) {
existing.textContent = message['print'];
} else { // Print stylesheet needs to come before everything else which means above 'colors'
u.getNode("head").insertBefore(stylesheet, colors);
}
}
}
go.Visual.updateDimensions(); // In case the styles changed things
go.Visual.updateDimensions(); // In case the styles changed the size of text
},
loadCSS: function(url, id){
// Imports the given CSS *URL* and applies the stylesheet to the current document.
Expand Down Expand Up @@ -1215,7 +1218,7 @@ GateOne.Base.update(GateOne.Utils, {
container = go.prefs.goDiv.split('#')[1],
theme = schemeObj['theme'],
colors = schemeObj['colors'];
go.ws.send(JSON.stringify({'get_style': {'go_url': go.prefs.url, 'container': container, 'prefix': go.prefs.prefix, 'theme': schemeObj['theme'], 'colors': schemeObj['colors']}}));
go.ws.send(JSON.stringify({'get_style': {'go_url': go.prefs.url, 'container': container, 'prefix': go.prefs.prefix, 'theme': schemeObj['theme'], 'colors': schemeObj['colors'], 'print': true}}));
},
loadPluginCSS: function() {
// Tells the Gate One server to send all the plugin CSS files to the client.
Expand Down Expand Up @@ -4888,7 +4891,7 @@ GateOne.Net.actions = {
'log': GateOne.Net.log,
'ping': GateOne.Net.ping,
'pong': GateOne.Net.pong,
'reauthenticate': GateOne.Net.reauthenticate,
'reauthenticate': GateOne.Net.reauthenticate
}

GateOne.Icons['prefs'] = '<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="18" width="18" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"><defs><linearGradient id="linearGradient15560" x1="85.834" gradientUnits="userSpaceOnUse" x2="85.834" gradientTransform="translate(288.45271,199.32483)" y1="363.23" y2="388.56"><stop class="stop1" offset="0"/><stop class="stop2" offset="0.4944"/><stop class="stop3" offset="0.5"/><stop class="stop4" offset="1"/></linearGradient></defs><metadata><rdf:RDF><cc:Work rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/><dc:title/></cc:Work></rdf:RDF></metadata><g transform="matrix(0.71050762,0,0,0.71053566,-256.93092,-399.71681)"><path fill="url(#linearGradient15560)" d="m386.95,573.97c0-0.32-0.264-0.582-0.582-0.582h-1.069c-0.324,0-0.662-0.25-0.751-0.559l-1.455-3.395c-0.155-0.277-0.104-0.69,0.123-0.918l0.723-0.723c0.227-0.228,0.227-0.599,0-0.824l-1.74-1.741c-0.226-0.228-0.597-0.228-0.828,0l-0.783,0.787c-0.23,0.228-0.649,0.289-0.931,0.141l-2.954-1.18c-0.309-0.087-0.561-0.423-0.561-0.742v-1.096c0-0.319-0.264-0.581-0.582-0.581h-2.464c-0.32,0-0.583,0.262-0.583,0.581v1.096c0,0.319-0.252,0.657-0.557,0.752l-3.426,1.467c-0.273,0.161-0.683,0.106-0.912-0.118l-0.769-0.77c-0.226-0.226-0.597-0.226-0.824,0l-1.741,1.742c-0.229,0.228-0.229,0.599,0,0.825l0.835,0.839c0.23,0.228,0.293,0.642,0.145,0.928l-1.165,2.927c-0.085,0.312-0.419,0.562-0.742,0.562h-1.162c-0.319,0-0.579,0.262-0.579,0.582v2.463c0,0.322,0.26,0.585,0.579,0.585h1.162c0.323,0,0.66,0.249,0.753,0.557l1.429,3.369c0.164,0.276,0.107,0.688-0.115,0.916l-0.802,0.797c-0.226,0.227-0.226,0.596,0,0.823l1.744,1.741c0.227,0.228,0.598,0.228,0.821,0l0.856-0.851c0.227-0.228,0.638-0.289,0.925-0.137l2.987,1.192c0.304,0.088,0.557,0.424,0.557,0.742v1.141c0,0.32,0.263,0.582,0.583,0.582h2.464c0.318,0,0.582-0.262,0.582-0.582v-1.141c0-0.318,0.25-0.654,0.561-0.747l3.34-1.418c0.278-0.157,0.686-0.103,0.916,0.122l0.753,0.758c0.227,0.225,0.598,0.225,0.825,0l1.743-1.744c0.227-0.226,0.227-0.597,0-0.822l-0.805-0.802c-0.223-0.228-0.285-0.643-0.134-0.926l1.21-3.013c0.085-0.31,0.423-0.559,0.747-0.562h1.069c0.318,0,0.582-0.262,0.582-0.582v-2.461zm-12.666,5.397c-2.29,0-4.142-1.855-4.142-4.144s1.852-4.142,4.142-4.142c2.286,0,4.142,1.854,4.142,4.142s-1.855,4.144-4.142,4.144z"/></g></svg>';
Expand Down

0 comments on commit 6f92ff3

Please sign in to comment.