Skip to content

Commit 131b3d1

Browse files
committed
fix order of async echo when import view #1004
1 parent ddcde6a commit 131b3d1

6 files changed

+67
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
99
![bower](https://img.shields.io/badge/bower-DEV-yellow.svg)
1010
[![Build and test](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml)
11-
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&1e8bbe7e144977411c2c22df5eaa33ac)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
11+
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&30337a9afb55435af852014140b95ef5)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
1212
![NPM Downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
1313
[![jsDelivr Downloads](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded&n=1)](https://www.jsdelivr.com/package/npm/jquery.terminal)
1414
[![Paid Support](https://img.shields.io/badge/paid-support-354465.svg)](https://support.jcubic.pl/)

__tests__/terminal.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5266,7 +5266,7 @@ describe('Terminal plugin', function() {
52665266
term.clear();
52675267
term.import_view(view);
52685268
setTimeout(() => {
5269-
expect(term.get_output()).toEqual('world\nhello');
5269+
expect(term.get_output()).toEqual('hello\nworld');
52705270
done();
52715271
}, 200);
52725272
});

js/jquery.terminal-src.js

+30
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,35 @@
20592059
this._output_buffer = [];
20602060
};
20612061
// -------------------------------------------------------------------------
2062+
// :: the buffer needs to be sorted when using import_view and async echo
2063+
// -------------------------------------------------------------------------
2064+
FormatBuffer.prototype.sort = function() {
2065+
var chunk = [];
2066+
var chunks = [];
2067+
for (var i = 0; i < this._output_buffer.length; i++) {
2068+
var item = this._output_buffer[i];
2069+
chunk.push(item);
2070+
if (item !== FormatBuffer.NEW_LINE && 'index' in item) {
2071+
chunks.push(chunk);
2072+
chunk = [];
2073+
}
2074+
}
2075+
2076+
// don't sort single chunk
2077+
if (chunks.lenght === 1) {
2078+
return;
2079+
}
2080+
2081+
chunks.sort(function(a, b) {
2082+
return a[2].index - b[2].index;
2083+
});
2084+
2085+
this._output_buffer = [];
2086+
chunks.forEach(function(chunk) {
2087+
this._output_buffer = this._output_buffer.concat(chunk);
2088+
}, this);
2089+
};
2090+
// -------------------------------------------------------------------------
20622091
FormatBuffer.prototype.forEach = function(fn) {
20632092
var i = 0;
20642093
while (i < this._output_buffer.length) {
@@ -10858,6 +10887,7 @@
1085810887
if (!options.update) {
1085910888
partial = self.find('.partial');
1086010889
snapshot = lines.get_partial();
10890+
buffer.sort();
1086110891
}
1086210892
// TODO: refactor buffer.flush(), there is way
1086310893
// to many levels of abstractions in one place

js/jquery.terminal.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
* broken image by Sophia Bai from the Noun Project (CC-BY)
4343
*
44-
* Date: Tue, 14 Jan 2025 21:24:13 +0000
44+
* Date: Tue, 14 Jan 2025 23:13:58 +0000
4545
*/
4646
/* global define, Map, BigInt */
4747
/* eslint-disable */
@@ -2059,6 +2059,35 @@
20592059
this._output_buffer = [];
20602060
};
20612061
// -------------------------------------------------------------------------
2062+
// :: the buffer needs to be sorted when using import_view and async echo
2063+
// -------------------------------------------------------------------------
2064+
FormatBuffer.prototype.sort = function() {
2065+
var chunk = [];
2066+
var chunks = [];
2067+
for (var i = 0; i < this._output_buffer.length; i++) {
2068+
var item = this._output_buffer[i];
2069+
chunk.push(item);
2070+
if (item !== FormatBuffer.NEW_LINE && 'index' in item) {
2071+
chunks.push(chunk);
2072+
chunk = [];
2073+
}
2074+
}
2075+
2076+
// don't sort single chunk
2077+
if (chunks.lenght === 1) {
2078+
return;
2079+
}
2080+
2081+
chunks.sort(function(a, b) {
2082+
return a[2].index - b[2].index;
2083+
});
2084+
2085+
this._output_buffer = [];
2086+
chunks.forEach(function(chunk) {
2087+
this._output_buffer = this._output_buffer.concat(chunk);
2088+
}, this);
2089+
};
2090+
// -------------------------------------------------------------------------
20622091
FormatBuffer.prototype.forEach = function(fn) {
20632092
var i = 0;
20642093
while (i < this._output_buffer.length) {
@@ -5407,7 +5436,7 @@
54075436
// -------------------------------------------------------------------------
54085437
$.terminal = {
54095438
version: 'DEV',
5410-
date: 'Tue, 14 Jan 2025 21:24:13 +0000',
5439+
date: 'Tue, 14 Jan 2025 23:13:58 +0000',
54115440
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
54125441
color_names: [
54135442
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
@@ -10858,6 +10887,7 @@
1085810887
if (!options.update) {
1085910888
partial = self.find('.partial');
1086010889
snapshot = lines.get_partial();
10890+
buffer.sort();
1086110891
}
1086210892
// TODO: refactor buffer.flush(), there is way
1086310893
// to many levels of abstractions in one place

js/jquery.terminal.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/jquery.terminal.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)