From fa6a77a6ea6eb017da62676d24d5ac18c53160a7 Mon Sep 17 00:00:00 2001 From: Simon Heather <32168619+X-Guardian@users.noreply.github.com> Date: Sun, 11 Jun 2023 07:22:09 +0100 Subject: [PATCH] Add xterm-addon-search-bar (#3507) --- server/controllers/templates/web_templates.go | 7 ++ server/static/js/xterm-addon-search-0.7.0.js | 2 + server/static/js/xterm-addon-search-bar.js | 114 ++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 server/static/js/xterm-addon-search-0.7.0.js create mode 100644 server/static/js/xterm-addon-search-bar.js diff --git a/server/controllers/templates/web_templates.go b/server/controllers/templates/web_templates.go index 3debb922f..5fe9515ab 100644 --- a/server/controllers/templates/web_templates.go +++ b/server/controllers/templates/web_templates.go @@ -407,6 +407,8 @@ var ProjectJobsTemplate = template.Must(template.New("blank.html.tmpl").Parse(` + + diff --git a/server/static/js/xterm-addon-search-0.7.0.js b/server/static/js/xterm-addon-search-0.7.0.js new file mode 100644 index 000000000..bcfdd8308 --- /dev/null +++ b/server/static/js/xterm-addon-search-0.7.0.js @@ -0,0 +1,2 @@ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SearchAddon=t():e.SearchAddon=t()}(window,(function(){return function(e){var t={};function i(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(r,n,function(t){return e[t]}.bind(null,n));return r},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SearchAddon=void 0;var r=function(){function e(){this._linesCacheTimeoutId=0}return e.prototype.activate=function(e){this._terminal=e},e.prototype.dispose=function(){},e.prototype.findNext=function(e,t){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!e||0===e.length)return this._terminal.clearSelection(),!1;var i,r=0,n=0;if(this._terminal.hasSelection()){var o=!!t&&t.incremental;i=this._terminal.getSelectionPosition(),n=o?i.startRow:i.endRow,r=o?i.startColumn:i.endColumn}this._initLinesCache();var s={startRow:n,startCol:r},a=this._findInLine(e,s,t);if(!a)for(var l=n+1;l=0&&(a.startRow=l,!(i=this._findInLine(e,a,t,!0)));l--);}if(!i&&n!==this._terminal.buffer.active.baseY+this._terminal.rows)for(l=this._terminal.buffer.active.baseY+this._terminal.rows;l>=n&&(a.startRow=l,!(i=this._findInLine(e,a,t,!0)));l--);return!(i||!r)||this._selectResult(i)},e.prototype._initLinesCache=function(){var e=this,t=this._terminal;this._linesCache||(this._linesCache=new Array(t.buffer.active.length),this._cursorMoveListener=t.onCursorMove((function(){return e._destroyLinesCache()})),this._resizeListener=t.onResize((function(){return e._destroyLinesCache()}))),window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=window.setTimeout((function(){return e._destroyLinesCache()}),15e3)},e.prototype._destroyLinesCache=function(){this._linesCache=void 0,this._cursorMoveListener&&(this._cursorMoveListener.dispose(),this._cursorMoveListener=void 0),this._resizeListener&&(this._resizeListener.dispose(),this._resizeListener=void 0),this._linesCacheTimeoutId&&(window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=0)},e.prototype._isWholeWord=function(e,t,i){return!(0!==e&&-1===" ~!@#$%^&*()+`-=[]{}|;:\"',./<>?".indexOf(t[e-1])||e+i.length!==t.length&&-1===" ~!@#$%^&*()+`-=[]{}|;:\"',./<>?".indexOf(t[e+i.length]))},e.prototype._findInLine=function(e,t,i,r){void 0===i&&(i={}),void 0===r&&(r=!1);var n=this._terminal,o=t.startRow,s=t.startCol,a=n.buffer.active.getLine(o);if(a&&a.isWrapped)return r?void(t.startCol+=n.cols):(t.startRow--,t.startCol+=n.cols,this._findInLine(e,t,i));var l=this._linesCache?this._linesCache[o]:void 0;void 0===l&&(l=this._translateBufferLineToStringWithWrap(o,!0),this._linesCache&&(this._linesCache[o]=l));var f=i.caseSensitive?e:e.toLowerCase(),c=i.caseSensitive?l:l.toLowerCase(),h=-1;if(i.regex){var u=RegExp(f,"g"),d=void 0;if(r)for(;d=u.exec(c.slice(0,s));)h=u.lastIndex-d[0].length,e=d[0],u.lastIndex-=e.length-1;else(d=u.exec(c.slice(s)))&&d[0].length>0&&(h=s+(u.lastIndex-d[0].length),e=d[0])}else r?s-f.length>=0&&(h=c.lastIndexOf(f,s-f.length)):h=c.indexOf(f,s);if(h>=0){if(h>=n.cols&&(o+=Math.floor(h/n.cols),h%=n.cols),i.wholeWord&&!this._isWholeWord(h,c,e))return;var _=n.buffer.active.getLine(o);if(_)for(var v=0;v1&&(h-=m.length-1),0===p.getWidth()&&h++}return{term:e,col:h,row:o}}},e.prototype._translateBufferLineToStringWithWrap=function(e,t){var i,r=this._terminal,n="";do{var o=r.buffer.active.getLine(e+1);i=!!o&&o.isWrapped;var s=r.buffer.active.getLine(e);if(!s)break;n+=s.translateToString(!i&&t).substring(0,r.cols),e++}while(i);return n},e.prototype._selectResult=function(e){var t=this._terminal;if(!e)return t.clearSelection(),!1;if(t.select(e.col,e.row,e.term.length),e.row>=t.buffer.active.viewportY+t.rows||e.row + + + `), + (e.className = t); + const a = this.terminal.element.parentElement; + (this.searchBarElement = e), +/* ["relative", "absolute", "fixed"].includes(a.style.position) || + (a.style.position = "relative"),*/ + a.appendChild(this.searchBarElement), + this.on(".search-bar__btn.close", "click", () => { + this.hidden(); + }), + this.on(".search-bar__btn.next", "click", () => { + this.searchAddon.findNext(this.searchKey, { incremental: !1 }); + }), + this.on(".search-bar__btn.prev", "click", () => { + this.searchAddon.findPrevious(this.searchKey, { incremental: !1 }); + }), + this.on(".search-bar__input", "keyup", (e) => { + (this.searchKey = e.target.value), + this.searchAddon.findNext(this.searchKey, { + incremental: "Enter" !== e.key, + }); + }), + this.searchBarElement.querySelector("input").select(); + } + hidden() { + this.searchBarElement && + this.terminal.element.parentElement && + (this.searchBarElement.style.visibility = "hidden"); + } + on(e, t, a) { + const i = this.terminal.element.parentElement; + i.addEventListener(t, (t) => { + let n = t.target; + for (; n !== document.querySelector(e); ) { + if (n === i) { + n = null; + break; + } + n = n.parentElement; + } + n === document.querySelector(e) && + (a.call(this, t), t.stopPropagation()); + }); + } + addNewStyle(e) { + let a = document.getElementById(t); + a || + (((a = document.createElement("style")).type = "text/css"), + (a.id = t), + document.getElementsByTagName("head")[0].appendChild(a)), + a.appendChild(document.createTextNode(e)); + } + }), + Object.defineProperty(e, "__esModule", { value: !0 }); +});