Skip to content

Commit

Permalink
- Add fileReader and filesReader API for automatic file input with sm…
Browse files Browse the repository at this point in the history
…art type coercion.

- Add file(s) input to built-in cat / grep
- Use monospace fonts for plain text
- preliminary hex support
- preliminary ansi support
- separate unix legacy output filters from binary escaping
- Add more mime types
- Add more inline documentation
- More testsa
  • Loading branch information
unconed committed Jun 13, 2011
1 parent 5fa6922 commit 6ee14bc
Show file tree
Hide file tree
Showing 18 changed files with 1,105 additions and 332 deletions.
Binary file modified HTML/Images/folder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 36 additions & 4 deletions HTML/outputview/outputfactory.js
Expand Up @@ -358,7 +358,6 @@ widgets.code = function (properties) {
'text/x-sql': 'sql',
'text/xml': 'xml',
'text/html': 'text',
'text/plain': 'text',
};
this.brush = brushes[properties.language];

Expand All @@ -378,11 +377,44 @@ widgets.code.prototype = $.extend(new widgets.text(), {
updateElement: function () {
this.$contents.html('<pre></pre>');
this.$pre = this.$contents.find('pre');

this.$pre.text(this.properties.contents);
this.$pre.attr('class', 'brush: ' + this.brush);

SyntaxHighlighter.highlight({}, this.$pre[0]);
if (this.brush) {
this.$pre.attr('class', 'brush: ' + this.brush);

SyntaxHighlighter.highlight({}, this.$pre[0]);
}

this.$element.data('controller', this);
},

});

/**
* Widget: Hex output
*/
widgets.hex = function (properties) {

// Initialize node.
ov.outputNode.call(this, properties);

this.$contents = this.$element.find('.contents');
this.$pre = this.$contents.find('pre');

this.updateElement();
};

widgets.hex.prototype = $.extend(new widgets.text(), {

// Return active markup for this widget.
$markup: function () {
var $outputNode = $('<div class="termkitOutputNode widgetHex"></div>').data('controller', this);
var that = this;
return $outputNode;
},

// Update markup to match.
updateElement: function () {

this.$element.data('controller', this);
},
Expand Down
109 changes: 109 additions & 0 deletions HTML/termkit.css
Expand Up @@ -57,6 +57,115 @@ body {
word-wrap: break-word;
}

.termkitOutputView .widgetCode pre {

}

.termkitAnsi30 {
color: #000;
}
.termkitAnsi31 {
color: #ba3615;
}
.termkitAnsi32 {
color: #65970b;
}
.termkitAnsi33 {
color: #ba7215;
}
.termkitAnsi34 {
color: #4362d1;
}
.termkitAnsi35 {
color: #a64e80;
}
.termkitAnsi36 {
color: #419197;
}
.termkitAnsi37 {
color: #8c805f;
}
.termkitAnsi30b {
color: #524b37;
font-weight: bolder;
}
.termkitAnsi31b {
color: #ff623b;
font-weight: bolder;
}
.termkitAnsi32b {
color: #c8f82d;
font-weight: bolder;
}
.termkitAnsi33b {
color: #fddc35;
font-weight: bolder;
}
.termkitAnsi34b {
color: #97c4ff;
font-weight: bolder;
}
.termkitAnsi35b {
color: #fa8fc6;
font-weight: bolder;
}
.termkitAnsi36b {
color: #adffe9;
font-weight: bolder;
}
.termkitAnsi37b {
color: #f3ebe2;
font-weight: bolder;
}
.termkitAnsi40 {
background-color: #000;
}
.termkitAnsi41 {
background-color: #ba3615;
}
.termkitAnsi42 {
background-color: #65970b;
}
.termkitAnsi43 {
background-color: #ba7215;
}
.termkitAnsi44 {
background-color: #4362d1;
}
.termkitAnsi45 {
background-color: #a64e80;
}
.termkitAnsi46 {
background-color: #419197;
}
.termkitAnsi47 {
background-color: #8c805f;
}
.termkitAnsi40b {
background-color: #524b37;
}
.termkitAnsi41b {
background-color: #ff623b;
}
.termkitAnsi42b {
background-color: #c8f82d;
}
.termkitAnsi43b {
background-color: #fddc35;
}
.termkitAnsi44b {
background-color: #97c4ff;
}
.termkitAnsi45b {
background-color: #fa8fc6;
}
.termkitAnsi46b {
background-color: #adffe9;
}
.termkitAnsi47b {
background-color: #f3ebe2;
}

.termkitOutputView .widgetCode div.syntaxhighlighter > div.toolbar {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion Node-API.md
Expand Up @@ -102,7 +102,7 @@ To handle headers on dataIn, you can use the built-in `reader.js`. To use it, cr
var handler = { ... };
// Attach reader to dataIn pipe.
var pipe = new reader.reader(pipes.dataIn,
var pipe = new reader.dataReader(pipes.dataIn,
function (headers) {
// Inspect headers, return appropriate handler
return handler;
Expand Down
69 changes: 48 additions & 21 deletions Node/misc.js
Expand Up @@ -219,27 +219,10 @@ exports.objectKeys = function (object) {
* Escape binary data for display as HTML.
*/
exports.escapeBinary = function (data) {
var binary = data.toString('utf-8'), n = binary.length, i = 0;

// Escape HTML characters.
binary = binary.replace(/[<&]/g, function (x) {
return { '<': '&lt;', '&': '&amp;' };
});

// Handle antique italic escapes used by grotty -c.
binary = binary.replace(/_\u0008(.)\u0008\1/g, function (x, char) {
return '<b><i>' + char + '</i></b>';
});

// Handle antique bold escapes used by grotty -c.
binary = binary.replace(/(.)\u0008\1/g, function (x, char) {
return '<b>' + char + '</b>';
});

// Handle antique italic escapes used by grotty -c.
binary = binary.replace(/_\u0008(.)/g, function (x, char) {
return '<i>' + char + '</i>';
});
if (typeof data != 'string') {
data = data.toString('utf-8');
}
var binary = data, n = binary.length, i = 0;

// Escape non-printables
binary = binary.replace(/([\u0000-\u001F\u0080-\u009F])/g, function (x, char) {
Expand All @@ -253,3 +236,47 @@ exports.escapeBinary = function (data) {

return binary;
}

/**
* Escape textual Unix data for display as HTML.
*/
exports.escapeUnixText = function (data) {
if (typeof data != 'string') {
data = data.toString('utf-8');
}
var binary = data, n = binary.length, i = 0;

// Escape HTML characters.
binary = binary.replace(/[<&]/g, function (x) {
return { '<': '&lt;', '&': '&amp;' }[x];
});

// Handle ANSI color escapes.
var bold = false,
italic = false,
underline = false,
blink = false,
strike = false,
binary = binary.replace(/\u001b([0-9]+(;[0-9]+)*)?m/g, function (x, codes) {
codes = codes.split(';');
for (i in codes) {
switch (codes[i]) {

}
}
});

// Handle antique bold/italic escapes used by grotty -c.
binary = binary
.replace(/_\u0008(.)\u0008\1/g, function (x, char) {
return '<b><i>' + char + '</i></b>';
})
.replace(/(.)\u0008\1/g, function (x, char) {
return '<b>' + char + '</b>';
})
.replace(/_\u0008(.)/g, function (x, char) {
return '<i>' + char + '</i>';
});

return exports.escapeBinary(binary);
}
1 change: 1 addition & 0 deletions Node/shell/builtin/builtin.js
Expand Up @@ -5,6 +5,7 @@ exports.commands = {
echo: true,
get: true,
grep: true,
hex: true,
ls: true,
pwd: true,
};

0 comments on commit 6ee14bc

Please sign in to comment.