diff --git a/clover/www/js/json-to-pretty-yaml.js b/clover/www/js/json-to-pretty-yaml.js new file mode 100644 index 00000000..661afd9b --- /dev/null +++ b/clover/www/js/json-to-pretty-yaml.js @@ -0,0 +1,236 @@ +// Browserified https://www.npmjs.com/package/json-to-pretty-yaml module + +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i/g, ">"); + }; + } + + if (!String.prototype.quote) { + String.prototype.quote = function () { + var c, i, l = this.length, o = '"'; + for (i = 0; i < l; i += 1) { + c = this.charAt(i); + if (c >= ' ') { + if (c === '\\' || c === '"') { + o += '\\'; + } + o += c; + } else { + switch (c) { + case '\b': + o += '\\b'; + break; + case '\f': + o += '\\f'; + break; + case '\n': + o += '\\n'; + break; + case '\r': + o += '\\r'; + break; + case '\t': + o += '\\t'; + break; + default: + c = c.charCodeAt(); + o += '\\u00' + Math.floor(c / 16).toString(16) + + (c % 16).toString(16); + } + } + } + return o + '"'; + }; + } + + if (!String.prototype.supplant) { + String.prototype.supplant = function (o) { + return this.replace(/{([^{}]*)}/g, + function (a, b) { + var r = o[b]; + return typeof r === 'string' || typeof r === 'number' ? r : a; + } + ); + }; + } + + if (!String.prototype.trim) { + String.prototype.trim = function () { + return this.replace(/^\s*(\S*(?:\s+\S+)*)\s*$/, "$1"); + }; + } + + // CommonJS / npm / Ender.JS + module.exports = { + typeOf: typeOf, + isEmpty: isEmpty + }; + global.typeOf = global.typeOf || typeOf; + global.isEmpty = global.isEmpty || isEmpty; +}()); + +},{}],3:[function(require,module,exports){ +"use strict"; + +/** + * removeTrailingSpaces + * Remove the trailing spaces from a string. + * + * @name removeTrailingSpaces + * @function + * @param {String} input The input string. + * @returns {String} The output string. + */ + +module.exports = function removeTrailingSpaces(input) { + // TODO If possible, use a regex + return input.split("\n").map(function (x) { + return x.trimRight(); + }).join("\n"); +}; +},{}]},{},[1]); diff --git a/clover/www/js/topics.js b/clover/www/js/topics.js index f9d588eb..7fd663f1 100644 --- a/clover/www/js/topics.js +++ b/clover/www/js/topics.js @@ -47,7 +47,7 @@ function viewTopic(topic) { new ROSLIB.Topic({ ros: ros, name: topic }).subscribe(function(msg) { document.title = topic; if (mouseDown) return; - topicMessage.innerHTML = JSON.stringify(msg, null, 4); + topicMessage.innerHTML = yamlStringify(msg); // JSON.stringify(msg, null, 4); }); } diff --git a/clover/www/topics.html b/clover/www/topics.html index a8d9838c..b42ac1c2 100644 --- a/clover/www/topics.html +++ b/clover/www/topics.html @@ -4,6 +4,7 @@ +