Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GabLeRoux committed Feb 18, 2016
0 parents commit 836901b
Show file tree
Hide file tree
Showing 23 changed files with 494 additions and 0 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "app/bower_components"
}
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

[*.json]
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
temp
.tmp
dist
.sass-cache
app/bower_components
test/bower_components
package
app/scripts

24 changes: 24 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"node": true,
"browser": true,
"mocha": true,
"esnext": true,
"module": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
"globals" : {
"chrome": true,
"crypto": true
}
}
3 changes: 3 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"generator-mocha": {}
}
40 changes: 40 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ANSI Colors chrome extension

Chrome extension that converts ANSI characters to colors on the fly / on button click for the lazy ones. Does what [ansi-html-stream][ansi-html-stream] does but within browser.

*Work in progress* (pressing on button currently strip ansi characters for now) :P

## todo

[ ] figure out how to pass data to [ansi-html-stream][ansi-html-stream] (using a stream? maybe I should find a different solution)
[x] Provide ansi stripping capability [strip-ansi][strip-ansi]
[ ] create an icon
[ ] publish

## Notes

* This is mostly an attempt to use [browserify][browserify] in a chrome extensionand at least, this part seems to work eh.
* PR welcome as usual

Right now, hitting extension button can convert from this:
```
Summary
-------------
Succeeded: 24 (changed=3)
Failed: 0
-------------
Total states run: 24
```
to this
```
Summary
-------------
Succeeded: 24 (changed=3)
Failed: 0
-------------
Total states run: 24
```

[strip-ansi]: https://github.com/chalk/strip-ansi
[ansi-html-stream]: https://github.com/hughsk/ansi-html-stream
[browserify]: http://browserify.org/
10 changes: 10 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appName": {
"message": "ansi colors chrome extension",
"description": "The name of the application"
},
"appDescription": {
"message": "Converts ANSI excape characters to colors on current page, useful when viewing log files within chrome",
"description": "The description of the application"
}
}
Binary file added app/images/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/icon-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/icon-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/icon-38.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions app/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "ansi-colors-chrome-extension",
"version": "0.0.1",
"manifest_version": 2,
"description": "Renders ansi escape characters on current page (ex: a log file with ansi colors viewed in chrome)",
"icons": {
"16": "images/icon-16.png",
"128": "images/icon-128.png"
},
"default_locale": "en",
"background": {
"scripts": [
"scripts/chromereload.js",
"scripts/background.js"
]
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["scripts/colorize.js"],
"run_at": "document_end"
}
],
"permissions": [
"file://*",
"activeTab"
],
"browser_action": {
"default_icon": {
"19": "images/icon-19.png",
"38": "images/icon-38.png"
},
"default_title": "ansi colors chrome extension"
}
}
18 changes: 18 additions & 0 deletions app/scripts.babel/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

chrome.runtime.onInstalled.addListener(details => {
console.log('previousVersion', details.previousVersion);
});

chrome.tabs.onUpdated.addListener(tabId => {
chrome.pageAction.show(tabId);
});

// executes colorize action on button click :)
chrome.browserAction.onClicked.addListener(tab => {
// No tabs or host permissions needed!
console.log('Turning ' + tab.url + ' red!');
chrome.tabs.executeScript({
file: 'scripts/colorize.js'
});
});
22 changes: 22 additions & 0 deletions app/scripts.babel/chromereload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

// Reload client for Chrome Apps & Extensions.
// The reload client has a compatibility with livereload.
// WARNING: only supports reload command.

const LIVERELOAD_HOST = 'localhost:';
const LIVERELOAD_PORT = 35729;
const connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');

connection.onerror = (error) => {
console.log('reload connection got error:', error);
};

connection.onmessage = (e) => {
if (e.data) {
const data = JSON.parse(e.data);
if (data && data.command === 'reload') {
chrome.runtime.reload();
}
}
};
40 changes: 40 additions & 0 deletions app/scripts.babel/colorize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

// @see https://github.com/hughsk/ansi-html-stream
var ansi = require('ansi-html-stream');
var stripAnsi = require('strip-ansi');

var fs = require('fs');

var stream = ansi({chunked: false});

// todo: find a way to get document.body.textContent as stream
//console.log(document.body.textContent);

// todo: move this to a button or submenu, whatever. at least this works
document.body.innerText = stripAnsi(document.body.textContent);

// pip document to ansi stream
//documentAsStream = getDocumentAsStream();
//documentAsStream.pipe(stream);

// this should be the current page
var file = fs.createWriteStream('output.html', 'utf8');

stream.pipe(file, {end: false});
stream.once('end', function () {
file.end('</pre>\n');
});
file.write('<pre>\n');


//documentAsStream.on('data', function (data) {
// // not quite sure if I'll need to do something here
// // I think pipe is the magic part here
// })
// .pipe(stream)
// .on('close', function () {
// console.log('stream is over');
// stream.end(null)
// });

3 changes: 3 additions & 0 deletions app/styles/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
padding: 20px;
}
10 changes: 10 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "ansi-colors-chrome-extension",
"private": true,
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^2.4.5"
}
}
Loading

0 comments on commit 836901b

Please sign in to comment.