Permalink
Browse files

hterm-driven output

  • Loading branch information...
1 parent ba13ee5 commit 9beea3a0732111573f31085a2649e15c9f3ef0d9 @daveyeu committed Jun 12, 2012
View
@@ -1,20 +1,85 @@
<html>
<head>
<title>Saw - Log Visualizer</title>
+
+ <script src="vendor/hterm/js/pubsub.js"></script>
+ <script src="vendor/hterm/js/dialogs.js"></script>
+
+ <!-- hterm -->
+ <script src="vendor/hterm/js/hterm.js"></script>
+ <script src="vendor/hterm/js/scrollport.js"></script>
+ <script src="vendor/hterm/js/terminal.js"></script>
+ <script src="vendor/hterm/js/terminal_io.js"></script>
+ <script src="vendor/hterm/js/options.js"></script>
+ <script src="vendor/hterm/js/screen.js"></script>
+ <script src="vendor/hterm/js/text_attributes.js"></script>
+ <script src="vendor/hterm/js/colors.js"></script>
+ <script src="vendor/hterm/js/vt.js"></script>
+ <script src="vendor/hterm/js/keyboard.js"></script>
+ <script src="vendor/hterm/js/default_keymap.js"></script>
+ <script src="vendor/hterm/js/preference_manager.js"></script>
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script src="js/hterm_overrides.js"></script>
<script>
- if (!window.EventSource) {
- // TODO: display some error
- } else {
- var source = new EventSource("stream");
- source.addEventListener("message", function(event) {
- $("#console").append("<p>" + event.data + "</p>");
- }, false);
- }
+ Saw = function(argv) {
+ this.argv_ = argv;
+ this.io = null;
+ this.pid_ = -1;
+ };
+
+ Saw.init = function() {
+ var terminal = new hterm.Terminal("saw");
+ terminal.decorate(document.querySelector('#terminal'));
+
+ // Looks like there is a race between this and terminal initialization, thus adding timeout.
+ setTimeout(function() {
+ terminal.setCursorPosition(0, 0);
+ terminal.setCursorVisible(true);
+ terminal.runCommandClass(Saw, document.location.hash.substr(1));
+ }, 500);
+ return true;
+ };
+
+ Saw.prototype.run = function() {
+ var self = this;
+ this.io = this.argv_.io.push();
+ this.io.println("Ready!");
+
+ if (!window.EventSource) {
+ this.io.println("Sorry, this browser does not support EventSource. Try Google Chrome instead.");
+ } else {
+ var source = new EventSource("stream");
+ source.addEventListener("message", function(event) {
+ self.io.println(event.data);
+ }, false);
+ }
+ };
+
+ $(function() {
+ hterm.init(Saw.init);
+ });
</script>
+
+ <style>
+ body {
+ position: absolute;
+ padding: 0;
+ margin: 0;
+ height: 100%;
+ width: 100%;
+ overflow: hidden;
+ }
+
+ #terminal {
+ display: block;
+ position: relative;
+ width: 100%;
+ height: 100%;
+ }
+ </style>
</head>
<body>
- <h1>Saw</h1>
- <div id="console"></div>
+ <div id="terminal"></div>
</body>
</html>
View
@@ -0,0 +1,7 @@
+/**
+ * The original function uses `chrome.i18n`, which only appears
+ * accessible to extensions.
+ */
+hterm.msg = function(name, opt_args) {
+ return name;
+};
View
37 saw.js
@@ -1,6 +1,8 @@
-var fs = require("fs");
-var http = require("http");
-var LogStream = require("log_stream");
+var fs = require("fs"),
+ http = require("http"),
+ path = require("path"),
+ url = require("url"),
+ LogStream = require("log_stream");
if (process.stdin.readyState != "open") {
console.log("Oops, nothing to read. Shutting down.");
@@ -20,13 +22,32 @@ http.createServer(function(req, res) {
res.write("data: " + data + "\n\n");
});
} else {
- res.writeHead(200, {"Content-Type": "text/html"});
- fs.readFile("index.html", function(err, data) {
- if (err) throw err;
- res.end(data);
- });
+ var pathname = url.parse(req.url).pathname;
+ var filename = path.join(process.cwd(), pathname);
+
+ if (pathname == "/") {
+ res.writeHead(200, {"Content-Type": "text/html"});
+ fs.readFile("index.html", function(err, data) {
+ if (err) throw err;
+ res.end(data);
+ });
+ } else {
+ path.exists(filename, function(exists) {
+ if (!exists) {
+ // TODO: handle missing file
+ } else {
+ // TODO: needs to handle CSS at some point
+ res.writeHead(200, {"Content-Type": "text/javascript"});
+ fs.readFile(filename, function(err, data) {
+ if (err) throw err;
+ res.end(data);
+ });
+ }
+ });
+ }
}
}).listen(3030, "127.0.0.1");
+console.log("Okay, listening on 127.0.0.1:3030");
process.stdin.setEncoding("utf8");
process.stdin.resume();
Oops, something went wrong.

0 comments on commit 9beea3a

Please sign in to comment.