Historize by ext

This commit is contained in:
Florian Mounier
2016-10-13 16:11:44 +02:00
parent b9f1727f1e
commit 3624962d3c
7 changed files with 67 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
(function() {
var Popup, Selection, _set_theme_href, _theme, alt, cancel, clean_ansi, copy, ctrl, first, linkify, nextLeaf, popup, previousLeaf, selection, setAlarm, virtualInput, walk,
var Popup, Selection, _set_theme_href, _theme, alt, cancel, clean_ansi, copy, ctrl, first, histSize, linkify, maybePack, nextLeaf, packSize, popup, previousLeaf, selection, setAlarm, tid, virtualInput, walk,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
clean_ansi = function(data) {
@@ -225,6 +225,39 @@
return cancel(e);
});
tid = null;
packSize = 1000;
histSize = 100;
maybePack = function() {
var hist, i, j, pack, packfrag, ref;
if (!(butterfly.term.childElementCount > packSize + butterfly.rows)) {
return;
}
hist = document.getElementById('packed');
packfrag = document.createDocumentFragment('fragment');
for (i = j = 0, ref = packSize; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
packfrag.appendChild(butterfly.term.firstChild);
}
pack = document.createElement('div');
pack.classList.add('pack');
pack.appendChild(packfrag);
hist.appendChild(pack);
if (hist.childElementCount > histSize) {
hist.firstChild.remove();
}
return tid = setTimeout(maybePack);
};
Terminal.on('refresh', function() {
if (tid) {
clearTimeout(tid);
}
return maybePack();
});
Popup = (function() {
function Popup() {
this.el = document.getElementById('popup');

File diff suppressed because one or more lines are too long

View File

@@ -170,7 +170,7 @@
};
function Terminal(parent, out, ctl1) {
var div, px;
var div;
this.parent = parent;
this.out = out;
this.ctl = ctl1 != null ? ctl1 : function() {};
@@ -189,9 +189,6 @@
this.computeCharSize();
this.cols = Math.floor(this.body.clientWidth / this.charSize.width);
this.rows = Math.floor(window.innerHeight / this.charSize.height);
px = window.innerHeight % this.charSize.height;
this.scrollback = 10000;
this.buffSize = 100000;
this.visualBell = 100;
this.convertEol = false;
this.termName = 'xterm';
@@ -704,7 +701,7 @@
};
Terminal.prototype.writeDom = function(dom) {
var frag, i, k, len, line, m, r, ref, results, y;
var frag, k, len, line, r, y;
r = Math.max(this.term.childElementCount - this.rows, 0);
for (y = k = 0, len = dom.length; k < len; y = ++k) {
line = dom[y];
@@ -722,14 +719,7 @@
}
frag && this.term.appendChild(frag);
this.shift = 0;
this.screen = this.screen.slice(-this.rows);
if (this.term.childElementCount > this.scrollback) {
results = [];
for (i = m = 0, ref = this.term.childElementCount - this.scrollback; 0 <= ref ? m <= ref : m >= ref; i = 0 <= ref ? ++m : --m) {
results.push(this.term.firstChild.remove());
}
return results;
}
return this.screen = this.screen.slice(-this.rows);
};
Terminal.prototype.refresh = function(force) {
@@ -742,7 +732,8 @@
}
dom = this.screenToDom(force);
this.writeDom(dom);
return this.nativeScrollTo();
this.nativeScrollTo();
return this.emit('refresh');
};
Terminal.prototype._cursorBlink = function() {

File diff suppressed because one or more lines are too long

View File

@@ -24,6 +24,7 @@
<script src="{{ static_url('ext.%sjs' % (
'' if options.unminified else 'min.')) }}"></script>
<script src="{{ reverse_url('LocalJsStatic') }}"></script>
<div id="packed"></div>
<div id="term"></div>
</body>
</html>

23
coffees/ext/pack.coffee Normal file
View File

@@ -0,0 +1,23 @@
tid = null
packSize = 1000
histSize = 100
maybePack = ->
return unless butterfly.term.childElementCount > packSize + butterfly.rows
hist = document.getElementById 'packed'
packfrag = document.createDocumentFragment 'fragment'
for i in [0..packSize]
packfrag.appendChild butterfly.term.firstChild
pack = document.createElement 'div'
pack.classList.add 'pack'
pack.appendChild packfrag
hist.appendChild pack
hist.firstChild.remove() if hist.childElementCount > histSize
tid = setTimeout maybePack
Terminal.on 'refresh', ->
clearTimeout tid if tid
maybePack()

View File

@@ -81,10 +81,6 @@ class Terminal
@computeCharSize()
@cols = Math.floor(@body.clientWidth / @charSize.width)
@rows = Math.floor(window.innerHeight / @charSize.height)
px = window.innerHeight % @charSize.height
@scrollback = 10000
@buffSize = 100000
@visualBell = 100
@convertEol = false
@@ -535,15 +531,13 @@ class Terminal
@shift = 0
@screen = @screen.slice -@rows
if @term.childElementCount > @scrollback
for i in [0..@term.childElementCount - @scrollback]
@term.firstChild.remove()
refresh: (force=false) ->
@active?.classList.remove('active')
dom = @screenToDom(force)
@writeDom dom
@nativeScrollTo()
@emit 'refresh'
_cursorBlink: ->
@cursorState ^= 1