Initial YakPanel commit
This commit is contained in:
141
YakPanel/static/build/addons/attach/attach.js
Normal file
141
YakPanel/static/build/addons/attach/attach.js
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*
|
||||
* Implements the attach method, that attaches the terminal to a WebSocket stream.
|
||||
*/
|
||||
|
||||
(function (attach) {
|
||||
if (typeof exports === 'object' && typeof module === 'object') {
|
||||
/*
|
||||
* CommonJS environment
|
||||
*/
|
||||
module.exports = attach(require('../../Terminal').Terminal);
|
||||
} else if (typeof define == 'function') {
|
||||
/*
|
||||
* Require.js is available
|
||||
*/
|
||||
define(['../../xterm'], attach);
|
||||
} else {
|
||||
/*
|
||||
* Plain browser environment
|
||||
*/
|
||||
attach(window.Terminal);
|
||||
}
|
||||
})(function (Terminal) {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
|
||||
/**
|
||||
* Attaches the given terminal to the given socket.
|
||||
*
|
||||
* @param {Terminal} term - The terminal to be attached to the given socket.
|
||||
* @param {WebSocket} socket - The socket to attach the current terminal.
|
||||
* @param {boolean} bidirectional - Whether the terminal should send data
|
||||
* to the socket as well.
|
||||
* @param {boolean} buffered - Whether the rendering of incoming data
|
||||
* should happen instantly or at a maximum
|
||||
* frequency of 1 rendering per 10ms.
|
||||
*/
|
||||
exports.attach = function (term, socket, bidirectional, buffered) {
|
||||
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
|
||||
term.socket = socket;
|
||||
|
||||
term._flushBuffer = function () {
|
||||
term.write(term._attachSocketBuffer);
|
||||
term._attachSocketBuffer = null;
|
||||
};
|
||||
|
||||
term._pushToBuffer = function (data) {
|
||||
if (term._attachSocketBuffer) {
|
||||
term._attachSocketBuffer += data;
|
||||
} else {
|
||||
term._attachSocketBuffer = data;
|
||||
setTimeout(term._flushBuffer, 10);
|
||||
}
|
||||
};
|
||||
|
||||
var myTextDecoder;
|
||||
|
||||
term._getMessage = function (ev) {
|
||||
var str;
|
||||
if (typeof ev.data === "object") {
|
||||
if (ev.data instanceof ArrayBuffer) {
|
||||
if (!myTextDecoder) {
|
||||
myTextDecoder = new TextDecoder();
|
||||
}
|
||||
|
||||
str = myTextDecoder.decode( ev.data );
|
||||
}
|
||||
else {
|
||||
throw "TODO: handle Blob?";
|
||||
}
|
||||
}
|
||||
|
||||
if (buffered) {
|
||||
term._pushToBuffer(str || ev.data);
|
||||
} else {
|
||||
term.write(str || ev.data);
|
||||
}
|
||||
};
|
||||
|
||||
term._sendData = function (data) {
|
||||
socket.send(data);
|
||||
};
|
||||
|
||||
socket.addEventListener('message', term._getMessage);
|
||||
|
||||
if (bidirectional) {
|
||||
term.on('data', term._sendData);
|
||||
}
|
||||
|
||||
socket.addEventListener('close', term.detach.bind(term, socket));
|
||||
socket.addEventListener('error', term.detach.bind(term, socket));
|
||||
};
|
||||
|
||||
/**
|
||||
* Detaches the given terminal from the given socket
|
||||
*
|
||||
* @param {Terminal} term - The terminal to be detached from the given socket.
|
||||
* @param {WebSocket} socket - The socket from which to detach the current
|
||||
* terminal.
|
||||
*/
|
||||
exports.detach = function (term, socket) {
|
||||
term.off('data', term._sendData);
|
||||
|
||||
socket = (typeof socket == 'undefined') ? term.socket : socket;
|
||||
|
||||
if (socket) {
|
||||
socket.removeEventListener('message', term._getMessage);
|
||||
}
|
||||
|
||||
delete term.socket;
|
||||
};
|
||||
|
||||
/**
|
||||
* Attaches the current terminal to the given socket
|
||||
*
|
||||
* @param {WebSocket} socket - The socket to attach the current terminal.
|
||||
* @param {boolean} bidirectional - Whether the terminal should send data
|
||||
* to the socket as well.
|
||||
* @param {boolean} buffered - Whether the rendering of incoming data
|
||||
* should happen instantly or at a maximum
|
||||
* frequency of 1 rendering per 10ms.
|
||||
*/
|
||||
Terminal.prototype.attach = function (socket, bidirectional, buffered) {
|
||||
return exports.attach(this, socket, bidirectional, buffered);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detaches the current terminal from the given socket.
|
||||
*
|
||||
* @param {WebSocket} socket - The socket from which to detach the current
|
||||
* terminal.
|
||||
*/
|
||||
Terminal.prototype.detach = function (socket) {
|
||||
return exports.detach(this, socket);
|
||||
};
|
||||
|
||||
return exports;
|
||||
});
|
||||
1
YakPanel/static/build/addons/attach/attach.min.js
vendored
Normal file
1
YakPanel/static/build/addons/attach/attach.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).attach=e()}}(function(){return function f(a,i,u){function s(t,e){if(!i[t]){if(!a[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var o=i[t]={exports:{}};a[t][0].call(o.exports,function(e){return s(a[t][1][e]||e)},o,o.exports,f,a,i,u)}return i[t].exports}for(var c="function"==typeof require&&require,e=0;e<u.length;e++)s(u[e]);return s}({1:[function(e,t,n){"use strict";function r(e,t,n,r){var o,f=e;function a(e,t){r?f.__pushToBuffer(e||t):f.write(e||t)}n=void 0===n||n,f.__socket=t,f.__flushBuffer=function(){f.write(f.__attachSocketBuffer),f.__attachSocketBuffer=null},f.__pushToBuffer=function(e){f.__attachSocketBuffer?f.__attachSocketBuffer+=e:(f.__attachSocketBuffer=e,setTimeout(f.__flushBuffer,10))},f.__getMessage=function(e){if("object"==typeof e.data)if(o=o||new TextDecoder,e.data instanceof ArrayBuffer)a(o.decode(e.data));else{var t=new FileReader;t.addEventListener("load",function(){a(o.decode(t.result))}),t.readAsArrayBuffer(e.data)}else{if("string"!=typeof e.data)throw Error('Cannot handle "'+typeof e.data+'" websocket message.');a(e.data)}},f.__sendData=function(e){1===t.readyState&&t.send(e)},f._core.register(i(t,"message",f.__getMessage)),n&&(f.__dataListener=f.onData(f.__sendData),f._core.register(f.__dataListener)),f._core.register(i(t,"close",function(){return u(f,t)})),f._core.register(i(t,"error",function(){return u(f,t)}))}function i(e,t,n){return e.addEventListener(t,n),{dispose:function(){n&&(e.removeEventListener(t,n),n=null)}}}function u(e,t){var n=e;n.__dataListener.dispose(),(t=(n.__dataListener=void 0)===t?n.__socket:t)&&t.removeEventListener("message",n.__getMessage),delete n.__socket}Object.defineProperty(n,"__esModule",{value:!0}),n.attach=r,n.detach=u,n.apply=function(e){e.prototype.attach=function(e,t,n){r(this,e,t,n)},e.prototype.detach=function(e){u(this,e)}}},{}]},{},[1])(1)});
|
||||
93
YakPanel/static/build/addons/attach/index.html
Normal file
93
YakPanel/static/build/addons/attach/index.html
Normal file
@@ -0,0 +1,93 @@
|
||||
<!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>
|
||||
<style>
|
||||
body {
|
||||
color: #111;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
color: #444;
|
||||
border-bottom: 1px solid #ddd;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
input, button {
|
||||
line-height: 22px;
|
||||
font-size: 16px;
|
||||
display: inline-block;
|
||||
border-radius: 2px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
input {
|
||||
height: 22px;
|
||||
padding-left: 4px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
button {
|
||||
height: 28px;
|
||||
background-color: #ccc;
|
||||
cursor: pointer;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
<h1>
|
||||
xterm.js: socket attach
|
||||
</h1>
|
||||
<p>
|
||||
Attach the terminal to a WebSocket terminal stream with ease. Perfect for attaching to your
|
||||
Docker containers.
|
||||
</p>
|
||||
<h2>
|
||||
Socket information
|
||||
</h2>
|
||||
<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>
|
||||
|
||||
</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>
|
||||
5
YakPanel/static/build/addons/attach/package.json
Normal file
5
YakPanel/static/build/addons/attach/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "xterm.attach",
|
||||
"main": "attach.js",
|
||||
"private": true
|
||||
}
|
||||
Reference in New Issue
Block a user