Skip to content

Commit

Permalink
fix issue with not working greetings + update #363
Browse files Browse the repository at this point in the history
the problem was that terminal width was 100 initialy and signature was empty and div for it was not created
and next time when it was updating it coun'd not found div with id for the greetings
  • Loading branch information
jcubic committed Jan 2, 2018
1 parent 1adce52 commit c8f14cf
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 101 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Next
* fix issue with not working greetings + update [#363](https://github.com/jcubic/jquery.terminal/issues/363)

## 1.11.2
* fix issue with --char-width == 0 if terminal have display:none
* fix DELETE numpad key on IE
Expand Down
76 changes: 43 additions & 33 deletions js/jquery.terminal-1.11.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Tue, 02 Jan 2018 07:33:01 +0000
* Date: Tue, 02 Jan 2018 18:12:01 +0000
*/

/* TODO:
Expand Down Expand Up @@ -790,10 +790,14 @@
callbacks.add(callback);
$this.data('callbacks', callbacks);
var resizer;
var first = true;
if (window.ResizeObserver) {
resizer = new ResizeObserver(function() {
var callbacks = $this.data('callbacks');
callbacks.fire();
if (!first) {
var callbacks = $this.data('callbacks');
callbacks.fire();
}
first = false;
});
resizer.observe(this);
$this.data('observer', resizer);
Expand Down Expand Up @@ -2797,7 +2801,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Tue, 02 Jan 2018 07:33:01 +0000',
date: 'Tue, 02 Jan 2018 18:12:01 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -4509,29 +4513,31 @@
// urls should always have formatting to keep url if split
var i, len;
output_buffer.push(NEW_LINE);
if (!options.raw && (strlen(string) > num_chars ||
string.match(/\n/)) &&
((settings.wrap === true && options.wrap === undefined) ||
settings.wrap === false && options.wrap === true)) {
var words = options.keepWords;
var array = $.terminal.split_equal(string, num_chars, words);
for (i = 0, len = array.length; i < len; ++i) {
if (array[i] === '' || array[i] === '\r') {
output_buffer.push('<span></span>');
} else {
output_buffer.push($.terminal.format(array[i], {
linksNoReferrer: settings.linksNoReferrer
}));
if (!options.raw) {
if ((strlen(string) > num_chars ||
string.match(/\n/)) &&
((settings.wrap === true && options.wrap === undefined) ||
settings.wrap === false && options.wrap === true)) {
var words = options.keepWords;
var array = $.terminal.split_equal(string, num_chars, words);
for (i = 0, len = array.length; i < len; ++i) {
if (array[i] === '' || array[i] === '\r') {
output_buffer.push('<span></span>');
} else {
output_buffer.push($.terminal.format(array[i], {
linksNoReferrer: settings.linksNoReferrer
}));
}
}
} else {
string = $.terminal.normalize(string);
string = $.terminal.format(string, {
linksNoReferrer: settings.linksNoReferrer
});
string.split(/\n/).forEach(function(string) {
output_buffer.push(string);
});
}
} else if (!options.raw) {
string = $.terminal.normalize(string);
string = $.terminal.format(string, {
linksNoReferrer: settings.linksNoReferrer
});
string.split(/\n/).forEach(function(string) {
output_buffer.push(string);
});
} else {
output_buffer.push(string);
}
Expand Down Expand Up @@ -4725,18 +4731,22 @@
// :: Display user greetings or terminal signature
// ---------------------------------------------------------------------
function show_greetings() {
function echo(string) {
self.echo(string, {finalize: a11y_hide, formatters: false});
}
if (settings.greetings === undefined) {
// signature have ascii art so it's not suite for screen readers
echo(self.signature);
self.echo(self.signature, {finalize: a11y_hide, formatters: false});
} else if (settings.greetings) {
var type = typeof settings.greetings;
if (type === 'string') {
echo(settings.greetings);
self.echo(settings.greetings);
} else if (type === 'function') {
settings.greetings.call(self, echo);
self.echo(function() {
try {
return settings.greetings.call(self);
} catch (e) {
settings.greetings = null;
display_exception(e, 'greetings');
}
});
} else {
self.error(strings().wrongGreetings);
}
Expand Down Expand Up @@ -5065,7 +5075,7 @@
prepare_top_interpreter();
show_greetings();
if (lines.length) {
redraw(); // for case when showing long error before init
self.refresh(); // for case when showing long error before init
}
// was_paused flag is workaround for case when user call exec before
// login and pause in onInit, 3rd exec will have proper timing (will
Expand Down Expand Up @@ -6086,7 +6096,7 @@
return signatures[i].join('\n') + '\n';
}
}
return '';
return ' ';
},
// -------------------------------------------------------------
// :: Return the version number
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-1.11.2.min.js

Large diffs are not rendered by default.

72 changes: 41 additions & 31 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,14 @@
callbacks.add(callback);
$this.data('callbacks', callbacks);
var resizer;
var first = true;
if (window.ResizeObserver) {
resizer = new ResizeObserver(function() {
var callbacks = $this.data('callbacks');
callbacks.fire();
if (!first) {
var callbacks = $this.data('callbacks');
callbacks.fire();
}
first = false;
});
resizer.observe(this);
$this.data('observer', resizer);
Expand Down Expand Up @@ -4509,29 +4513,31 @@
// urls should always have formatting to keep url if split
var i, len;
output_buffer.push(NEW_LINE);
if (!options.raw && (strlen(string) > num_chars ||
string.match(/\n/)) &&
((settings.wrap === true && options.wrap === undefined) ||
settings.wrap === false && options.wrap === true)) {
var words = options.keepWords;
var array = $.terminal.split_equal(string, num_chars, words);
for (i = 0, len = array.length; i < len; ++i) {
if (array[i] === '' || array[i] === '\r') {
output_buffer.push('<span></span>');
} else {
output_buffer.push($.terminal.format(array[i], {
linksNoReferrer: settings.linksNoReferrer
}));
if (!options.raw) {
if ((strlen(string) > num_chars ||
string.match(/\n/)) &&
((settings.wrap === true && options.wrap === undefined) ||
settings.wrap === false && options.wrap === true)) {
var words = options.keepWords;
var array = $.terminal.split_equal(string, num_chars, words);
for (i = 0, len = array.length; i < len; ++i) {
if (array[i] === '' || array[i] === '\r') {
output_buffer.push('<span></span>');
} else {
output_buffer.push($.terminal.format(array[i], {
linksNoReferrer: settings.linksNoReferrer
}));
}
}
} else {
string = $.terminal.normalize(string);
string = $.terminal.format(string, {
linksNoReferrer: settings.linksNoReferrer
});
string.split(/\n/).forEach(function(string) {
output_buffer.push(string);
});
}
} else if (!options.raw) {
string = $.terminal.normalize(string);
string = $.terminal.format(string, {
linksNoReferrer: settings.linksNoReferrer
});
string.split(/\n/).forEach(function(string) {
output_buffer.push(string);
});
} else {
output_buffer.push(string);
}
Expand Down Expand Up @@ -4725,18 +4731,22 @@
// :: Display user greetings or terminal signature
// ---------------------------------------------------------------------
function show_greetings() {
function echo(string) {
self.echo(string, {finalize: a11y_hide, formatters: false});
}
if (settings.greetings === undefined) {
// signature have ascii art so it's not suite for screen readers
echo(self.signature);
self.echo(self.signature, {finalize: a11y_hide, formatters: false});
} else if (settings.greetings) {
var type = typeof settings.greetings;
if (type === 'string') {
echo(settings.greetings);
self.echo(settings.greetings);
} else if (type === 'function') {
settings.greetings.call(self, echo);
self.echo(function() {
try {
return settings.greetings.call(self);
} catch (e) {
settings.greetings = null;
display_exception(e, 'greetings');
}
});
} else {
self.error(strings().wrongGreetings);
}
Expand Down Expand Up @@ -5065,7 +5075,7 @@
prepare_top_interpreter();
show_greetings();
if (lines.length) {
redraw(); // for case when showing long error before init
self.refresh(); // for case when showing long error before init
}
// was_paused flag is workaround for case when user call exec before
// login and pause in onInit, 3rd exec will have proper timing (will
Expand Down Expand Up @@ -6086,7 +6096,7 @@
return signatures[i].join('\n') + '\n';
}
}
return '';
return ' ';
},
// -------------------------------------------------------------
// :: Return the version number
Expand Down
76 changes: 43 additions & 33 deletions js/jquery.terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Tue, 02 Jan 2018 07:33:01 +0000
* Date: Tue, 02 Jan 2018 18:12:01 +0000
*/

/* TODO:
Expand Down Expand Up @@ -790,10 +790,14 @@
callbacks.add(callback);
$this.data('callbacks', callbacks);
var resizer;
var first = true;
if (window.ResizeObserver) {
resizer = new ResizeObserver(function() {
var callbacks = $this.data('callbacks');
callbacks.fire();
if (!first) {
var callbacks = $this.data('callbacks');
callbacks.fire();
}
first = false;
});
resizer.observe(this);
$this.data('observer', resizer);
Expand Down Expand Up @@ -2797,7 +2801,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Tue, 02 Jan 2018 07:33:01 +0000',
date: 'Tue, 02 Jan 2018 18:12:01 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -4509,29 +4513,31 @@
// urls should always have formatting to keep url if split
var i, len;
output_buffer.push(NEW_LINE);
if (!options.raw && (strlen(string) > num_chars ||
string.match(/\n/)) &&
((settings.wrap === true && options.wrap === undefined) ||
settings.wrap === false && options.wrap === true)) {
var words = options.keepWords;
var array = $.terminal.split_equal(string, num_chars, words);
for (i = 0, len = array.length; i < len; ++i) {
if (array[i] === '' || array[i] === '\r') {
output_buffer.push('<span></span>');
} else {
output_buffer.push($.terminal.format(array[i], {
linksNoReferrer: settings.linksNoReferrer
}));
if (!options.raw) {
if ((strlen(string) > num_chars ||
string.match(/\n/)) &&
((settings.wrap === true && options.wrap === undefined) ||
settings.wrap === false && options.wrap === true)) {
var words = options.keepWords;
var array = $.terminal.split_equal(string, num_chars, words);
for (i = 0, len = array.length; i < len; ++i) {
if (array[i] === '' || array[i] === '\r') {
output_buffer.push('<span></span>');
} else {
output_buffer.push($.terminal.format(array[i], {
linksNoReferrer: settings.linksNoReferrer
}));
}
}
} else {
string = $.terminal.normalize(string);
string = $.terminal.format(string, {
linksNoReferrer: settings.linksNoReferrer
});
string.split(/\n/).forEach(function(string) {
output_buffer.push(string);
});
}
} else if (!options.raw) {
string = $.terminal.normalize(string);
string = $.terminal.format(string, {
linksNoReferrer: settings.linksNoReferrer
});
string.split(/\n/).forEach(function(string) {
output_buffer.push(string);
});
} else {
output_buffer.push(string);
}
Expand Down Expand Up @@ -4725,18 +4731,22 @@
// :: Display user greetings or terminal signature
// ---------------------------------------------------------------------
function show_greetings() {
function echo(string) {
self.echo(string, {finalize: a11y_hide, formatters: false});
}
if (settings.greetings === undefined) {
// signature have ascii art so it's not suite for screen readers
echo(self.signature);
self.echo(self.signature, {finalize: a11y_hide, formatters: false});
} else if (settings.greetings) {
var type = typeof settings.greetings;
if (type === 'string') {
echo(settings.greetings);
self.echo(settings.greetings);
} else if (type === 'function') {
settings.greetings.call(self, echo);
self.echo(function() {
try {
return settings.greetings.call(self);
} catch (e) {
settings.greetings = null;
display_exception(e, 'greetings');
}
});
} else {
self.error(strings().wrongGreetings);
}
Expand Down Expand Up @@ -5065,7 +5075,7 @@
prepare_top_interpreter();
show_greetings();
if (lines.length) {
redraw(); // for case when showing long error before init
self.refresh(); // for case when showing long error before init
}
// was_paused flag is workaround for case when user call exec before
// login and pause in onInit, 3rd exec will have proper timing (will
Expand Down Expand Up @@ -6086,7 +6096,7 @@
return signatures[i].join('\n') + '\n';
}
}
return '';
return ' ';
},
// -------------------------------------------------------------
// :: Return the version number
Expand Down
Loading

0 comments on commit c8f14cf

Please sign in to comment.