]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Implemented the attach addon
authorparis <pariskasidiaris@gmail.com>
Thu, 10 Apr 2014 15:54:39 +0000 (15:54 +0000)
committerparis <pariskasidiaris@gmail.com>
Thu, 10 Apr 2014 15:54:39 +0000 (15:54 +0000)
addon/fullscreen/fullscreen.css [deleted file]
addon/fullscreen/fullscreen.js [deleted file]
addons/attach/attach.js [new file with mode: 0644]
addons/attach/index.html [new file with mode: 0644]
addons/fullscreen/fullscreen.css [new file with mode: 0644]
addons/fullscreen/fullscreen.js [new file with mode: 0644]

diff --git a/addon/fullscreen/fullscreen.css b/addon/fullscreen/fullscreen.css
deleted file mode 100644 (file)
index ced6c52..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-.xterm.fullscreen {
-    position: fixed;
-    top: 0;
-    bottom: 0;
-    left: 0;
-    right: 0;
-    width: auto;
-    height: auto;
-    z-index: 255;
-}
\ No newline at end of file
diff --git a/addon/fullscreen/fullscreen.js b/addon/fullscreen/fullscreen.js
deleted file mode 100644 (file)
index a3012a7..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Fullscreen addon for xterm.js
- *
- * Implements the toggleFullscreen function.
- *
- * If the `fullscreen` argument has been supplied, then
- * if it is true, the fullscreen mode gets turned on,
- * if it is false or null, the fullscreen mode gets turned off.
- *
- * If the `fullscreen` argument has not been supplied, the
- * fullscreen mode is being toggled.
- */
-Terminal.prototype.toggleFullscreen = function (fullscreen) {
-  var fn;
-  
-  if (typeof fullscreen == 'undefined') {
-    fn = (this.element.classList.contains('fullscreen')) ? 'remove' : 'add';
-  } else if (!fullscreen) {
-    fn = 'remove';
-  } else {
-    fn = 'add';
-  }
-  
-  this.element.classList[fn]('fullscreen');
-}
\ No newline at end of file
diff --git a/addons/attach/attach.js b/addons/attach/attach.js
new file mode 100644 (file)
index 0000000..12eb135
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Implements the attach method, that
+ * attaches the terminal to a WebSocket stream.
+ * 
+ * The bidirectional argument indicates, whether the terminal should
+ * send data to the socket as well and is true, by default.
+ */
+Terminal.prototype.attach = function (socket, bidirectional) {
+  var term = this;
+  
+  bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
+  this.socket = socket;
+  
+  socket.addEventListener('message', function (ev) {
+    term.write(ev.data);
+  });
+  
+  if (bidirectional) {
+    this.on('data', function (data) {
+      socket.send(data);
+    });
+  }
+}
\ No newline at end of file
diff --git a/addons/attach/index.html b/addons/attach/index.html
new file mode 100644 (file)
index 0000000..654a024
--- /dev/null
@@ -0,0 +1,38 @@
+<!doctype html>
+<html>
+  <head>
+    <link rel="stylesheet" href="../../src/xterm.css" />
+    <link rel="stylesheet" href="../../demo/style.css" />
+    <script src="../../src/xterm.js"></script>
+    <script src="attach.js"></script>
+  </head>
+  <body>
+    <form id="socket-form">
+      <input id="socket-url"
+             type="text"
+             placeholder="Enter socket url (e.g. ws://mysock)"
+             autofocus />
+      <button>
+        Attach
+      </button>
+    </form>
+    <div id="terminal-container"></div>
+    <script>
+      var term = new Terminal(),
+          container = document.getElementById('terminal-container'),
+          socketUrl = document.getElementById('socket-url'),
+          socketForm = document.getElementById('socket-form');
+      
+      socketForm.addEventListener('submit', function (ev) {
+        ev.preventDefault();
+        var url = socketUrl.value,
+            sock = new WebSocket(url);
+        sock.addEventListener('open', function () {
+          term.attach(sock);
+        });
+      });
+      
+      term.open(container);
+    </script>
+  </body>
+</html>
\ No newline at end of file
diff --git a/addons/fullscreen/fullscreen.css b/addons/fullscreen/fullscreen.css
new file mode 100644 (file)
index 0000000..ced6c52
--- /dev/null
@@ -0,0 +1,10 @@
+.xterm.fullscreen {
+    position: fixed;
+    top: 0;
+    bottom: 0;
+    left: 0;
+    right: 0;
+    width: auto;
+    height: auto;
+    z-index: 255;
+}
\ No newline at end of file
diff --git a/addons/fullscreen/fullscreen.js b/addons/fullscreen/fullscreen.js
new file mode 100644 (file)
index 0000000..a3012a7
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Fullscreen addon for xterm.js
+ *
+ * Implements the toggleFullscreen function.
+ *
+ * If the `fullscreen` argument has been supplied, then
+ * if it is true, the fullscreen mode gets turned on,
+ * if it is false or null, the fullscreen mode gets turned off.
+ *
+ * If the `fullscreen` argument has not been supplied, the
+ * fullscreen mode is being toggled.
+ */
+Terminal.prototype.toggleFullscreen = function (fullscreen) {
+  var fn;
+  
+  if (typeof fullscreen == 'undefined') {
+    fn = (this.element.classList.contains('fullscreen')) ? 'remove' : 'add';
+  } else if (!fullscreen) {
+    fn = 'remove';
+  } else {
+    fn = 'add';
+  }
+  
+  this.element.classList[fn]('fullscreen');
+}
\ No newline at end of file