Compare commits

..
11 Commits
Author SHA1 Message Date
paris fb1c484224 Added top: 0 to helpers 2014-04-10 21:45:54 +00:00
paris 59ebbbaaf0 Fix helper position 2014-04-10 18:48:36 +00:00
paris 6e6b5dad8c fit() uses offset height and width now 2014-04-10 18:36:37 +00:00
paris 0b603952c3 Removed debugging stuff
Bumped bower version to 0.9
2014-04-10 16:04:59 +00:00
paris 9bd2a1c202 Implemented the attach addon 2014-04-10 15:54:39 +00:00
paris c7f4658e97 Add fullscreen mode plug in 2014-04-10 15:20:41 +00:00
paris 96848a6425 Improved textarea handling 2014-04-10 15:08:19 +00:00
paris 0997f4398f Proper event handling
Bump bower version to 0.7
2014-04-10 14:39:17 +00:00
paris e278837de8 Fix focus on refresh 2014-04-09 16:49:29 +00:00
paris e572734a21 Syntax fix
Bumped bower version to 0.5
2014-04-09 15:42:37 +00:00
paris 4f2cadd6c9 Fixed paste
Bumped bower version to 0.4
2014-04-09 15:37:45 +00:00
10 changed files with 125 additions and 22 deletions
+23
View File
@@ -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);
});
}
}
+38
View File
@@ -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>
+10
View File
@@ -0,0 +1,10 @@
.xterm.fullscreen {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: auto;
height: auto;
z-index: 255;
}
+25
View File
@@ -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');
}
+2 -2
View File
@@ -1,5 +1,5 @@
{
"name": "xterm.js",
"version": "0.3",
"version": "0.9.2",
"ignore": ["demo", "docs", "test", ".gitignore"]
}
}
+2
View File
@@ -3,8 +3,10 @@
<head>
<title>xterm.js demo</title>
<link rel="stylesheet" href="../src/xterm.css" />
<link rel="stylesheet" href="../addon/fullscreen/fullscreen.css" />
<link rel="stylesheet" href="style.css" />
<script src="../src/xterm.js"></script>
<script src="../addon/fullscreen/fullscreen.js"></script>
<script src="main.js" defer></script>
</head>
<body>
-1
View File
@@ -17,7 +17,6 @@ term.on('key', function (key, ev) {
var printable = (!ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey);
if (ev.keyIdentifier == 'Enter') {
ev.preventDefault();
term.prompt();
} else if (ev.keyCode == 8) {
term.write('\b \b');
-1
View File
@@ -1 +0,0 @@
/mnt/project/
+6
View File
@@ -40,12 +40,18 @@
color: #fff;
outline: none;
font-family: courier-new, courier, monospace;
position: relative;
}
.xterm .terminal-cursor {
background-color: #fff;
}
.xterm .xterm-helpers {
position: absolute;
top: 0;
}
.xterm .xterm-helper-textarea {
opacity: 0;
width: 0;
+19 -18
View File
@@ -419,7 +419,6 @@ Terminal.bindPaste = function(term) {
ev.stopPropagation();
if (ev.clipboardData) {
var text = ev.clipboardData.getData('text/plain');
term.write(text);
term.handler(text);
}
term.textarea.value = '';
@@ -543,6 +542,10 @@ Terminal.prototype.open = function(parent) {
this.element.appendChild(this.helperContainer);
this.textarea = document.createElement('textarea');
this.textarea.classList.add('xterm-helper-textarea');
this.textarea.setAttribute('autocorrect', 'off');
this.textarea.setAttribute('autocapitalize', 'off');
this.textarea.setAttribute('spellcheck', 'false');
this.textarea.tabIndex = 0;
this.helperContainer.appendChild(this.textarea);
for (; i < this.rows; i++) {
@@ -565,9 +568,7 @@ Terminal.prototype.open = function(parent) {
on(this.element, 'mouseup', function() {
var selection = document.getSelection();
if (selection.type == 'Range') {
console.log(selection);
} else {
if (selection.type != 'Range') {
self.focus();
}
});
@@ -954,7 +955,7 @@ Terminal.prototype.destroy = function() {
* 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
*/
Terminal.prototype.refresh = function(start, end) {
var x, y, i, line, out, ch, width, data, attr, bg, fg, flags, row, parent;
var x, y, i, line, out, ch, width, data, attr, bg, fg, flags, row, parent, focused = document.activeElement;
if (end - start >= this.rows / 2) {
parent = this.element.parentNode;
@@ -1087,6 +1088,10 @@ Terminal.prototype.refresh = function(start, end) {
parent.appendChild(this.element);
}
/*
* Return focus to previously focused element
*/
focused.focus();
this.emit('refresh', {element: this.element, start: start, end: end});
};
@@ -2170,14 +2175,17 @@ Terminal.prototype.keyDown = function(ev) {
break;
}
key = '\t';
this.cancel(ev, true);
break;
// return/enter
case 13:
key = '\r';
this.cancel(ev, true);
break;
// escape
case 27:
key = '\x1b';
this.cancel(ev, true);
break;
// left-arrow
case 37:
@@ -2351,7 +2359,6 @@ Terminal.prototype.keyDown = function(ev) {
this.emit('keydown', ev);
this.emit('key', key, ev);
this.showCursor();
this.handler(key);
@@ -2393,7 +2400,6 @@ Terminal.prototype.keyPress = function(ev) {
this.emit('keypress', key, ev);
this.emit('key', key, ev);
this.showCursor();
this.handler(key);
@@ -2531,7 +2537,7 @@ Terminal.prototype.resize = function(x, y) {
Terminal.prototype.fit = function () {
var container = this.element.parentElement,
subjectRow = this.rowContainer.firstElementChild,
rows = parseInt(container.scrollHeight / subjectRow.offsetHeight),
rows = parseInt(container.offsetHeight / subjectRow.offsetHeight),
characterWidth,
cols;
@@ -2539,7 +2545,7 @@ Terminal.prototype.fit = function () {
characterWidth = parseInt(subjectRow.offsetWidth / this.cols);
subjectRow.style.display = '';
cols = parseInt(container.scrollWidth / characterWidth);
cols = parseInt(container.offsetWidth / characterWidth);
this.resize(cols, rows);
}
@@ -4657,17 +4663,12 @@ function off(el, type, handler, capture) {
el.removeEventListener(type, handler, capture || false);
}
function cancel(ev) {
if (!this.cancelEvents) {
function cancel(ev, force) {
if (!this.cancelEvents && !force) {
return;
}
if (ev.preventDefault) {
ev.preventDefault();
}
if (ev.stopPropagation) {
ev.stopPropagation();
}
ev.cancelBubble = true;
ev.preventDefault();
ev.stopPropagation();
return false;
}