diff --git a/CHANGELOG.md b/CHANGELOG.md index eb60a1e7..ec953f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 2.45.0 ### Features * add `id` option that allow to create same terminal using hot reload [#978](https://github.com/jcubic/jquery.terminal/issues/978) +### Bugfix +* fix `terminal::login()` when user already authenticated [#980](https://github.com/jcubic/jquery.terminal/issues/980) ## 2.44.1 ### Bugfix diff --git a/README.md b/README.md index 586d0d20..f0394ea5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/jquery.terminal) ![bower](https://img.shields.io/badge/bower-DEV-yellow.svg) [![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) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&3a08274fb3d1c4cbcdf3ca25c25dabb7)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&1620e1f399d74967a5e6292177558e0a)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel) ![NPM Downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat) [![jsDelivr Downloads](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded&n=1)](https://www.jsdelivr.com/package/npm/jquery.terminal) [![Paid Support](https://img.shields.io/badge/paid-support-354465.svg)](https://support.jcubic.pl/) diff --git a/__tests__/terminal.spec.js b/__tests__/terminal.spec.js index 3f24809b..59f92600 100644 --- a/__tests__/terminal.spec.js +++ b/__tests__/terminal.spec.js @@ -5879,6 +5879,18 @@ describe('Terminal plugin', function() { expect(term.get_prompt()).toEqual('>>> '); term.logout(true).pop().pop(); }); + it('should login when already auth', function() { + term.push($.noop, {prompt: '>>> '}).login(login.callback, true); + if (term.token(true)) { + term.logout(true); + } + enter(term, 'foo'); + enter(term, 'bar'); + expect(term.token(true)).toEqual(token); + term.login(login.callback, true); + expect(term.paused()).toBe(false); + term.logout(true).pop().pop(); + }); it('should login to nested interpreter when using login option', function() { term.push($.noop, { prompt: '$$$ ', diff --git a/js/jquery.terminal-src.js b/js/jquery.terminal-src.js index d0603ec4..598bb2c4 100644 --- a/js/jquery.terminal-src.js +++ b/js/jquery.terminal-src.js @@ -9936,6 +9936,8 @@ if (valid !== false) { if (is_function(success)) { success(); + } else { + self.resume(); } } else { self.resume(); diff --git a/js/jquery.terminal.js b/js/jquery.terminal.js index 7c16b5ad..b3b9f69f 100644 --- a/js/jquery.terminal.js +++ b/js/jquery.terminal.js @@ -4,7 +4,7 @@ * __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / * / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ * \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ - * \/ /____/ version 2.44.1 + * \/ /____/ version DEV * * This file is part of jQuery Terminal. https://terminal.jcubic.pl * @@ -41,7 +41,7 @@ * * broken image by Sophia Bai from the Noun Project (CC-BY) * - * Date: Sat, 26 Oct 2024 19:45:38 +0000 + * Date: Tue, 29 Oct 2024 22:55:22 +0000 */ /* global define, Map, BigInt */ /* eslint-disable */ @@ -1522,7 +1522,9 @@ set: function(index, value) { if (!data[index]) { data[index] = value; + return true; } + return false; }, append: function(item) { data.push(item); @@ -5347,8 +5349,8 @@ } // ------------------------------------------------------------------------- $.terminal = { - version: '2.44.1', - date: 'Sat, 26 Oct 2024 19:45:38 +0000', + version: 'DEV', + date: 'Tue, 29 Oct 2024 22:55:22 +0000', // colors from https://www.w3.org/wiki/CSS/Properties/color/keywords color_names: [ 'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white', @@ -7668,7 +7670,9 @@ invalidMask: 'Invalid mask used only string or boolean allowed', defunctTerminal: "You can't call method '%s' on terminal that was destroyed", abortError: 'Abort with CTRL+D', - timeoutError: 'Signal timed out' + timeoutError: 'Signal timed out', + invalidId: 'terminal with this `id` aready exists! You need to destr' + + 'oy old terminal before you can create terminal with the same `id`' } }; // ------------------------------------------------------------------------- @@ -9932,6 +9936,8 @@ if (valid !== false) { if (is_function(success)) { success(); + } else { + self.resume(); } } else { self.resume(); @@ -12075,7 +12081,9 @@ global_login_fn = make_json_rpc_login(base_interpreter, settings.login); } if (have_custom_id) { - terminals.set(settings.id, self); + if (!terminals.set(settings.id, self)) { + warn(strings().invalidId); + } } else { terminals.append(self); } diff --git a/js/jquery.terminal.min.js b/js/jquery.terminal.min.js index 307445be..53728f05 100644 --- a/js/jquery.terminal.min.js +++ b/js/jquery.terminal.min.js @@ -4,7 +4,7 @@ * __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / * / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ * \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ - * \/ /____/ version 2.44.1 + * \/ /____/ version DEV * * This file is part of jQuery Terminal. https://terminal.jcubic.pl * @@ -41,7 +41,7 @@ * * broken image by Sophia Bai from the Noun Project (CC-BY) * - * Date: Sat, 26 Oct 2024 19:45:38 +0000 + * Date: Tue, 29 Oct 2024 22:55:22 +0000 */ -(function(e){var m=function(){if(!m.cache.hasOwnProperty(arguments[0])){m.cache[arguments[0]]=m.parse(arguments[0])}return m.format.call(null,m.cache[arguments[0]],arguments)};m.format=function(e,t){var r=1,n=e.length,i="",a,u=[],o,s,l,f,c,p;for(o=0;o>>0;break;case"x":a=a.toString(16);break;case"X":a=a.toString(16).toUpperCase();break}a=/[def]/.test(l[8])&&l[3]&&a>=0?" +"+a:a;c=l[4]?l[4]==="0"?"0":l[4].charAt(1):" ";p=l[6]-String(a).length;f=l[6]?d(c,p):"";u.push(l[5]?a+f:f+a)}}return u.join("")};m.cache={};m.parse=function(e){var t=e,r=[],n=[],i=0;while(t){if((r=/^[^\x25]+/.exec(t))!==null){n.push(r[0])}else if((r=/^\x25{2}/.exec(t))!==null){n.push("%")}else if((r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(t))!==null){if(r[2]){i|=1;var a=[],u=r[2],o=[];if((o=/^([a-z_][a-z_\d]*)/i.exec(u))!==null){a.push(o[1]);while((u=u.slice(o[0].length))!==""){if((o=/^\.([a-z_][a-z_\d]*)/i.exec(u))!==null){a.push(o[1])}else if((o=/^\[(\d+)\]/.exec(u))!==null){a.push(o[1])}else{throw"[sprintf] huh?"}}}else{throw"[sprintf] huh?"}r[2]=a}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}n.push(r)}else{throw"[sprintf] huh?"}t=t.slice(r[0].length)}return n};var t=function(e,t,r){r=t.slice(0);r.splice(0,0,e);return m.apply(null,r)};function D(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function d(e,t){for(var r=[];t>0;r[--t]=e){}return r.join("")}e.sprintf=m;e.vsprintf=t})(typeof global!=="undefined"?global:self||window);(function(n,i){var r;if(typeof window!=="undefined"){r=window}else if(typeof self!=="undefined"){r=self}else if(typeof global!=="undefined"){r=global}else{throw new Error("Unknow context")}if(typeof define==="function"&&define.amd){define(["jquery","wcwidth"],function(e,t){n(e,t,r);return e})}else if(typeof module==="object"&&module.exports){module.exports=function(e,t,r){if(t===i){if(typeof window!=="undefined"){t=require("jquery")}else{t=require("jquery")(e)}}if(r===i){r=require("wcwidth")}n(t,r,e);return t}}else{if(!r.jQuery){r.$=r.cash}n(r.jQuery||r.cash,r.wcwidth,r)}})(function($,wcwidth,root,undefined){"use strict";function debug(e){if(false){console.log(e)}}function DelayQueue(){var t=$.Callbacks();var r=false;var e=this;this.resolve=function(){t.fire();e.resolved=r=true};this.add=function(e){if(r){e()}else{t.add(e)}}}$.omap=function(r,n){var i={};$.each(r,function(e,t){i[e]=n.call(r,e,t)});return i};$.fn.text_length=function(){return this.map(function(){return $(this).text().length}).get().reduce(function(e,t){return e+t},0)};var Clone={clone_object:function(e){var t={};if(typeof e==="object"){if(Array.isArray(e)){return this.clone_array(e)}else if(e===null){return e}else{for(var r in e){if(Array.isArray(e[r])){t[r]=this.clone_array(e[r])}else if(typeof e[r]==="object"){t[r]=this.clone_object(e[r])}else{t[r]=e[r]}}}}return t},clone_array:function(e){if(!is_function(Array.prototype.map)){throw new Error("Your browser don't support ES5 array map "+"use es5-shim")}return e.slice(0).map(function(e){if(typeof e==="object"){return this.clone_object(e)}else{return e}}.bind(this))}};var clone=function(e){return Clone.clone_object(e)};if("Map"in root&&!("clear"in Map.prototype)){Map.prototype.clear=function(){this.forEach(function(e,t,r){r.delete(t)})}}var localStorage;(function(){var e=function(){try{var e="test",t=window.localStorage;t.setItem(e,"1");t.removeItem(e);return true}catch(e){return false}};var t=function(){try{document.cookie.split(";");return true}catch(e){return false}};var r=e();function n(e,t){var r;if(typeof e==="string"&&typeof t==="string"){localStorage[e]=t;return true}else if(typeof e==="object"&&typeof t==="undefined"){for(r in e){if(e.hasOwnProperty(r)){localStorage[r]=e[r]}}return true}return false}function i(e,t){var r,n,i;r=new Date;r.setTime(r.getTime()+31536e6);n="; expires="+r.toGMTString();if(typeof e==="string"&&typeof t==="string"){document.cookie=e+"="+t+n+"; path=/";return true}else if(typeof e==="object"&&typeof t==="undefined"){for(i in e){if(e.hasOwnProperty(i)){document.cookie=i+"="+e[i]+n+"; path=/"}}return true}return false}function a(e){return localStorage[e]}function u(e){var t,r,n,i;t=e+"=";r=document.cookie.split(";");for(n=0;n=i||t<0||D&&r>=s}function y(){var e=$();if(_(e)){return b(e)}f=setTimeout(y,g(e))}function b(e){f=undefined;if(d&&u){return h(e)}u=o=undefined;return l}function C(){if(f!==undefined){clearTimeout(f)}p=0;u=c=o=f=undefined}function F(){return f===undefined?l:b($())}function w(){var e=$(),t=_(e);u=arguments;o=this;c=e;if(t){if(f===undefined){return v(c)}if(D){f=setTimeout(y,i);return h(c)}}if(f===undefined){f=setTimeout(y,i)}return l}w.cancel=C;w.flush=F;return w}}();var jQuery=$;(function(e){jQuery.fn.extend({everyTime:function(e,t,r,n,i){return this.each(function(){jQuery.timer.add(this,e,t,r,n,i)})},oneTime:function(e,t,r){return this.each(function(){jQuery.timer.add(this,e,t,r,1)})},stopTime:function(e,t){return this.each(function(){jQuery.timer.remove(this,e,t)})}});jQuery.extend({timer:{guid:1,global:{},regex:/^([0-9]+)\s*(.*s)?$/,powers:{ms:1,cs:10,ds:100,s:1e3,das:1e4,hs:1e5,ks:1e6},timeParse:function(e){if(e===undefined||e===null){return null}var t=this.regex.exec(e.toString().trim());if(t[2]){var r=parseInt(t[1],10);var n=this.powers[t[2]]||1;return r*n}else{return e}},add:function(e,t,r,n,i,a){var u=0;if(typeof r==="function"){if(!i){i=n}n=r;r=t}t=jQuery.timer.timeParse(t);if(typeof t!=="number"||isNaN(t)||t<=0){return}if(i&&i.constructor!==Number){a=!!i;i=0}i=i||0;a=a||false;if(!e.$timers){e.$timers={}}if(!e.$timers[r]){e.$timers[r]={}}n.$timerID=n.$timerID||this.guid++;var o=function(){if(a&&o.inProgress){return}o.inProgress=true;if(++u>i&&i!==0||n.call(e,u)===false){jQuery.timer.remove(e,r,n)}o.inProgress=false};o.$timerID=n.$timerID;if(!e.$timers[r][n.$timerID]){e.$timers[r][n.$timerID]=setInterval(o,t)}if(!this.global[r]){this.global[r]=[]}this.global[r].push(e)},remove:function(e,t,r){var n=e.$timers,i;if(n){if(!t){for(var a in n){if(n.hasOwnProperty(a)){this.remove(e,a,r)}}}else if(n[t]){if(r){if(r.$timerID){clearInterval(n[t][r.$timerID]);delete n[t][r.$timerID]}}else{for(var u in n[t]){if(n[t].hasOwnProperty(u)){clearInterval(n[t][u]);delete n[t][u]}}}for(i in n[t]){if(n[t].hasOwnProperty(i)){break}}if(!i){i=null;delete n[t]}}for(i in n){if(n.hasOwnProperty(i)){break}}if(!i){e.$timers=null}}}}});if(/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())){e(window).one("unload",function(){var e=jQuery.timer.global;for(var t in e){if(e.hasOwnProperty(t)){var r=e[t],n=r.length;while(--n){jQuery.timer.remove(r[n],t)}}}})}})(jQuery);(function(f){if(!String.prototype.split.toString().match(/\[native/)){return}var c=String.prototype.split,p=/()??/.exec("")[1]===f,r;r=function(e,t,r){if(Object.prototype.toString.call(t)!=="[object RegExp]"){return c.call(e,t,r)}var n=[],i=(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.extended?"x":"")+(t.sticky?"y":""),a=0,u,o,s,l;t=new RegExp(t.source,i+"g");e+="";if(!p){u=new RegExp("^"+t.source+"$(?!\\s)",i)}r=r===f?-1>>>0:r>>>0;while(o=t.exec(e)){s=o.index+o[0].length;if(s>a){n.push(e.slice(a,o.index));if(!p&&o.length>1){o[0].replace(u,function(){for(var e=1;e1&&o.index=r){break}}if(t.lastIndex===o.index){t.lastIndex++}}if(a===e.length){if(l||!t.test("")){n.push("")}}else{n.push(e.slice(a))}return n.length>r?n.slice(0,r):n};String.prototype.split=function(e,t){return r(this,e,t)};return r})();$.fn.caret=function(e){var t=this[0];var r=t.contentEditable==="true";if(arguments.length===0){if(window.getSelection){if(r){if(!this.is(":focus")){t.focus()}var n=window.getSelection().getRangeAt(0),i=n.cloneRange();i.selectNodeContents(t);i.setEnd(n.endContainer,n.endOffset);return i.toString().length}return t.selectionStart}if(document.selection){t.focus();if(r){var n=document.selection.createRange(),i=document.body.createTextRange();i.moveToElementText(t);i.setEndPoint("EndToEnd",n);return i.text.length}var e=0,a=t.createTextRange(),i=document.selection.createRange().duplicate(),u=i.getBookmark();a.moveToBookmark(u);while(a.moveStart("character",-1)!==0)e++;return e}return 0}if(e===-1)e=this[r?"text":"val"]().length;if(window.getSelection){if(r){if(!this.is(":focus")){t.focus()}var o=window.getSelection();o.collapse(o.focusNode,e)}else t.setSelectionRange(e,e)}else if(document.body.createTextRange){var a=document.body.createTextRange();a.moveToElementText(t);a.moveStart("character",e);a.collapse(true);a.select()}if(!r&&!this.is(":focus")){t.focus()}return e};function make_callback_plugin(e){var s=$.extend({init:$.noop,destroy:$.noop,name:"event"},e);return function(n,i){var a=arguments.length===0;var u=arguments[0]==="unbind";if(!a&&!u&&!is_function(n)){throw new Error("Invalid argument, it need to a function or string "+'"unbind" or no arguments.')}if(u){n=is_function(arguments[1])?arguments[1]:null}var o="callbacks_"+s.name;return this.each(function(){var t=$(this);var r;function e(e){r.fireWith(t,[e])}if(a||u){r=t.data(o);if(a){r&&r.fire()}else{if(n&&r){r.remove(n);if(!r.has()){r=null}}else{r=null}if(!r){t.removeData(o);s.destroy.call(this,e,i)}}}else if(t.data(o)){$(this).data(o).add(n)}else{r=$.Callbacks();r.add(n);t.data(o,r);s.init.call(this,e,i)}})}}$.fn.resizer=make_callback_plugin({name:"resize",init:function(e,t){var r=$.extend({prefix:""},t);var n=$(this);var i;var a=true;if(n.is("body")){$(window).on("resize.resizer",e)}else if(window.ResizeObserver){i=new ResizeObserver(function(){if(!a){setTimeout(e,0)}a=false});i.observe(this);n.data("observer",i)}else{var u=$("