You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP โ†’
Socket
Book a DemoInstallSign in
Socket

react-terminal-plus

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-terminal-plus - npm Package Compare versions

Comparing version

to
0.0.16

2

dist/index.es.js

@@ -1,1 +0,1 @@

import*as e from"react";import{CancelablePromise as t}from"cancelable-promise";var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function r(e,t,n,r){return new(n||(n=Promise))((function(o,a){function l(e){try{c(r.next(e))}catch(e){a(e)}}function i(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,i)}c((r=r.apply(e,t||[])).next())}))}function o(e,t){var n,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return l.label++,{value:i[1],done:!1};case 5:l.label++,r=i[1],i=[0];continue;case 7:i=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){l=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){l.label=i[1];break}if(6===i[0]&&l.label<o[1]){l.label=o[1],o=i;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(i);break}o[2]&&l.ops.pop(),l.trys.pop();continue}i=t.call(e,l)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('@import url("https://fonts.googleapis.com/css?family=Source+Code+Pro&display=swap");\n#index-module_terminalContainer__i6yCT {\n --control-default-bg-color: #ccc;\n --control-close-bg-color: #fc5b57;\n --control-minimize-bg-color: #e5bf3c;\n --control-maximize-bg-color: #57c038;\n}\n\n.index-module_controls__-Pz-7 {\n text-align: left;\n height: 26px;\n position: relative;\n top: 4px;\n margin-left: 4px;\n}\n.index-module_controls__-Pz-7 .index-module_consoleCtrl__wASVf {\n display: inline-block;\n width: 13px;\n height: 13px;\n margin: 0 3px;\n border-radius: 50%;\n background: var(--control-default-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_close__Etu85 {\n background: var(--control-close-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_minimize__bT0-I {\n background: var(--control-minimize-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_maximize__mPPF7 {\n background: var(--control-maximize-bg-color);\n}\n\n.index-module_editor__CBDCJ {\n text-align: left;\n height: 100%;\n padding: 10px 15px;\n overflow-wrap: break-word;\n overflow-y: scroll;\n outline: none;\n font-family: "Source Code Pro", monospace;\n font-size: 18px;\n line-height: 22px;\n caret-color: transparent;\n --scroll-bar-thumb-color: transparent;\n --scroll-bar-track-color: transparent;\n --scroll-bar-width: 10px;\n scrollbar-color: var(--scroll-bar-thumb-color) var(--scroll-bar-track-color);\n scrollbar-width: var(--scroll-bar-width);\n}\n.index-module_editor--rounded__-VOd4 {\n border-radius: 5px;\n}\n.index-module_editor__CBDCJ::selection {\n background: transparent;\n}\n.index-module_editor__CBDCJ:focus, .index-module_editor__CBDCJ:hover {\n --scroll-bar-thumb-color: rgb(211 211 211 / 40%);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar {\n width: var(--scroll-bar-width);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-track {\n background-color: var(--scroll-bar-track-color);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-thumb {\n background-color: var(--scroll-bar-thumb-color);\n}\n.index-module_editor__CBDCJ .index-module_lineText__avQ48 {\n display: inline;\n position: relative;\n top: -1px;\n margin-left: 8px;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf {\n white-space: pre-wrap;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf:focus-visible {\n outline: none;\n}\n.index-module_editor__CBDCJ .index-module_charUnderCaret__-M0qT {\n z-index: 10;\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn {\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn .index-module_caretAfter__SMMlh {\n content: "";\n position: absolute;\n top: 2px;\n width: 10px;\n height: 22px;\n z-index: 10;\n}\n@-moz-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-webkit-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-o-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n.index-module_editor__CBDCJ a {\n color: #1a87b5;\n}\n\n.index-module_editorWithTopBar__opXWp {\n height: calc(100% - 46px);\n}\n\n#index-module_terminalContainer__i6yCT {\n height: 100%;\n}\n\n.index-module_terminal__EWHbJ {\n height: 100%;\n width: 100%;\n margin: auto;\n}\n.index-module_terminal--rounded__DZuxh {\n border-radius: 5px;\n}');var a={terminalContainer:"index-module_terminalContainer__i6yCT",controls:"index-module_controls__-Pz-7",consoleCtrl:"index-module_consoleCtrl__wASVf",close:"index-module_close__Etu85",minimize:"index-module_minimize__bT0-I",maximize:"index-module_maximize__mPPF7",editor:"index-module_editor__CBDCJ","editor--rounded":"index-module_editor--rounded__-VOd4",lineText:"index-module_lineText__avQ48",preWhiteSpace:"index-module_preWhiteSpace__v4IYf",charUnderCaret:"index-module_charUnderCaret__-M0qT",caret:"index-module_caret__YobLn",caretAfter:"index-module_caretAfter__SMMlh",editorWithTopBar:"index-module_editorWithTopBar__opXWp",terminal:"index-module_terminal__EWHbJ","terminal--rounded":"index-module_terminal--rounded__DZuxh",blink:"index-module_blink__l83VF"},l=e.createContext(null),i=function(t){var n=t.children;return e.createElement(l.Provider,{value:a},n)},c={dark:{themeBGColor:"rgb(2, 40, 51)",themeToolbarColor:"rgb(19, 21, 25)",themeColor:"rgb(131, 148, 150)",themePromptColor:"rgb(169, 23, 168)"},light:{themeBGColor:"#fdf6e4",themeToolbarColor:"#d8d8d8",themeColor:"#333333",themePromptColor:"#a917a8"},dracula:{themeBGColor:"#272B36",themeToolbarColor:"#DBDBDB",themeColor:"#FFFEFC",themePromptColor:"#a917a8"},"material-dark":{themeBGColor:"#151515",themeToolbarColor:"#424242",themeColor:"#fff",themePromptColor:"#42A5F5"},"material-light":{themeBGColor:"#fafafa",themeToolbarColor:"#424242",themeColor:"#151515",themePromptColor:"#42A5F5"},"material-ocean":{themeBGColor:"#263238",themeToolbarColor:"#37474F",themeColor:"#fff",themePromptColor:"#C3D82C"},matrix:{themeBGColor:"#0D0208",themeToolbarColor:"#0D0208",themeColor:"#00FF41",themePromptColor:"#008F11"}},u=e.createContext(null),s=function(t){var r=t.children,o=n(n({},c),r.props.themes||{}),a=o[r.props.theme]||o.light;return e.createElement(u.Provider,{value:a},r)},d=function(t,n,r){var o=function(e){t.current&&!t.current.contains(e.target)?r(!1):r(!0)};e.useEffect((function(){return document.addEventListener("mousedown",o),function(){document.removeEventListener("mousedown",o)}}))};function m(t){var n=e.useContext(l),r=t.controlButtonLabels,o=t.showControlButtons?r.map((function(t){return e.createElement("div",{key:t,className:"".concat(n.consoleCtrl," ").concat(n[t])})})):null;return e.createElement("div",{className:n.controls},o)}var f=["clear","cls"],p=function(e){return f.includes(e)},C=function(){function e(){}return e.splitStringAtIndex=function(e,t){return e?[e.substring(0,t),e.substring(t)]:["",""]},e}(),_="react-terminal-plus-commandHistory",h=function(){var e;try{var t=null!==(e=localStorage.getItem(_))&&void 0!==e?e:"[]";return JSON.parse(t)}catch(e){return console.error(e),[]}},x=function(e){var t=h();t.push(e);try{JSON.stringify(t).length>20&&(t=t.slice(50)),localStorage.setItem(_,JSON.stringify(t))}catch(n){console.error(n),t=[e],localStorage.setItem(_,JSON.stringify(t))}},b=e.createContext(null);function v(e,t){switch(e.currentLineStatus){case"processing":switch(t.type){case"CANCEL":return n(n({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT_SUCCESS":return n(n({},e),{bufferedContent:t.successNode,currentLineStatus:"success",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});default:return e}case"success":case"error":case"idle":switch(t.type){case"CLEAR":return n(n({},e),{bufferedContent:null});case"CANCEL":return n(n({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT":var r=t.command,o=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,a=t.length;o<a;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e.commandsHistory,!0);return r&&r!==o[o.length-1]&&(o.push(r),x(r)),p(r)?n(n({},e),{commandsHistory:o,bufferedContent:null,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""}):n(n({},e),{commandsHistory:o,bufferedContent:t.loaderNode,currentLineStatus:"processing",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"TYPE":var a=g(e),l=a[0],i=a[1],c=y(h=l+t.text+i,v=e.caretPosition+1),u=c[0],s=c[1];return n(n({},e),{caretPosition:v,editorInput:h,textAfterCaret:s,textBeforeCaret:u});case"DELETE":var d=g(e),m=(l=d[0],i=d[1],y(h=l.slice(0,-1)+i,v=e.caretPosition-1));u=m[0],s=m[1];return n(n({},e),{editorInput:h,caretPosition:v,textAfterCaret:s,textBeforeCaret:u});case"COPY":return e;case"PASTE":var f=g(e),C=(l=f[0],i=f[1],y(h=l+t.text+i,v=e.caretPosition+t.text.length));u=C[0],s=C[1];return n(n({},e),{editorInput:h,caretPosition:v,textAfterCaret:s,textBeforeCaret:u});case"ARROW_UP":var _=y(h=t.previousCommand,v=t.previousCommand.length);u=_[0],s=_[1];return n(n({},e),{editorInput:h,caretPosition:v,textAfterCaret:s,textBeforeCaret:u});case"ARROW_DOWN":var h,b=y(h=t.nextCommand,v=t.nextCommand.length);u=b[0],s=b[1];return n(n({},e),{editorInput:h,caretPosition:v,textAfterCaret:s,textBeforeCaret:u});case"RESET_CARET_POSITION":return n(n({},e),{editorInput:"",textBeforeCaret:"",textAfterCaret:"",caretPosition:0});case"ARROW_LEFT":var v=e.caretPosition-1,E=y(e.editorInput,v);u=E[0],s=E[1];return n(n({},e),{caretPosition:v,textAfterCaret:s,textBeforeCaret:u});case"ARROW_RIGHT":v=e.caretPosition+1;var w=y(e.editorInput,v);u=w[0],s=w[1];return n(n({},e),{caretPosition:v,textAfterCaret:s,textBeforeCaret:u});default:throw new Error("Unhandled action type: ".concat(JSON.stringify(t)))}default:return e}}function g(e){var t=C.splitStringAtIndex(e.editorInput,e.caretPosition);return[t[0],t[1]]}function y(e,t){var n=C.splitStringAtIndex(e,t);return[n[0],n[1]]}function E(){var t=e.useContext(b);if(void 0===t)throw new Error("useTerminal must be used within a TerminalContextProvider");return t}var w=function(n,a,i,c,s,d,m){var f=e.useContext(l),C=e.useContext(u),_=E().store,h=_.textAfterCaret[0],x=_.textAfterCaret.slice(1),b=a&&n,v="processing"!==_.currentLineStatus?e.createElement(e.Fragment,null,e.createElement("span",{style:{color:C.themePromptColor}},i),e.createElement("div",{className:f.lineText},e.createElement("span",{className:f.preWhiteSpace},_.textBeforeCaret),b?e.createElement("span",{className:f.caret},e.createElement("span",{className:f.caretAfter,style:{background:C.themeColor}})):null,e.createElement("span",{className:"".concat(f.preWhiteSpace)},e.createElement("span",{style:{color:b?C.themeBGColor:C.themeColor},className:f.charUnderCaret},h),x))):e.createElement(e.Fragment,null,e.createElement("div",{className:f.lineText},b?e.createElement("span",{className:f.caret},e.createElement("span",{className:f.caretAfter,style:{background:C.themeColor}})):null));return function(n){var a=n.consoleFocused,i=n.enableInput,c=n.commands,s=n.defaultHandler,d=n.errorMessage,m=n.prompt,f=e.useContext(l),C=e.useContext(u),_=E(),h=_.getPreviousCommand,x=_.getNextCommand,b=_.store,v=_.send,g=e.useRef(null),y=e.useCallback((function(){g.current&&g.current.cancel();var t=e.createElement(e.Fragment,null,b.bufferedContent,e.createElement("span",{style:{color:C.themePromptColor}},m),e.createElement("span",{className:"".concat(f.lineText," ").concat(f.preWhiteSpace)},b.editorInput),e.createElement("br",null));"processing"===b.currentLineStatus&&(t=e.createElement(e.Fragment,null,b.bufferedContent)),v({type:"CANCEL",cancelNode:t})}),[m,v,b.bufferedContent,b.currentLineStatus,b.editorInput,f.lineText,f.preWhiteSpace,C.themePromptColor]),w=e.useCallback((function(){return r(void 0,void 0,void 0,(function(){var n,r,a,l,i,u,_,h,x;return o(this,(function(o){switch(o.label){case 0:return n=b.editorInput.trim().split(" "),r=n[0],a=n.slice(1),l=b.editorInput.trim(),i="",u=e.createElement(e.Fragment,null,b.bufferedContent,e.createElement("span",{style:{color:C.themePromptColor}},m),e.createElement("span",{className:"".concat(f.lineText," ").concat(f.preWhiteSpace)},b.editorInput),e.createElement("br",null)),v({type:"SUBMIT",loaderNode:u,command:l}),p(l)?[2]:b.editorInput?(_=a.join(" "),l&&c[l]?"function"!=typeof(h=c[l])?[3,2]:(g.current=new t((function(e){e(h(_))})),[4,g.current]):[3,4]):[3,9];case 1:return i=o.sent(),[3,3];case 2:i=h,o.label=3;case 3:return[3,9];case 4:return"function"!=typeof s?[3,6]:(g.current=new t((function(e){e(s(r,_))})),[4,g.current]);case 5:return i=o.sent(),[3,9];case 6:return"function"!=typeof d?[3,8]:(g.current=new t((function(e){e(d(r,_))})),[4,g.current]);case 7:return i=o.sent(),[3,9];case 8:i=d,o.label=9;case 9:return x=e.createElement(e.Fragment,null,b.bufferedContent,e.createElement("span",{style:{color:C.themePromptColor}},m),e.createElement("span",{className:"".concat(f.lineText," ").concat(f.preWhiteSpace)},b.editorInput),i?e.createElement("span",null,e.createElement("br",null),i):null,e.createElement("br",null)),v({type:"SUBMIT_SUCCESS",successNode:x}),[2]}}))}))}),[v,b.bufferedContent,b.editorInput]),P=e.useCallback((function(e){if(a&&i){e.preventDefault();var t=e.key,n=null;if("Enter"===t)"processing"!==b.currentLineStatus&&w();else if("Backspace"===t)b.editorInput&&0!==b.editorInput.length&&v({type:"DELETE"});else if("ArrowUp"===t)(n=h())&&v({type:"ARROW_UP",previousCommand:n});else if("ArrowDown"===t)n=x(),v(n?{type:"ARROW_DOWN",nextCommand:n}:{type:"RESET_CARET_POSITION"});else if("ArrowLeft"===t)b.caretPosition>0&&v({type:"ARROW_LEFT"}),n=b.editorInput;else if("ArrowRight"===t)b.caretPosition<b.editorInput.length&&v({type:"ARROW_RIGHT"}),n=b.editorInput;else if((e.metaKey||e.ctrlKey)&&"l"===t.toLowerCase())v({type:"CLEAR"});else if((e.metaKey||e.ctrlKey)&&"v"===t.toLowerCase())navigator.clipboard.readText().then((function(e){v({type:"PASTE",text:e})}));else if((e.metaKey||e.ctrlKey)&&"c"===t.toLowerCase()){var r=window.getSelection().toString();r?navigator.clipboard.writeText(r).then((function(){v({type:"COPY"})})):y()}else t&&1===t.length&&v({type:"TYPE",text:t})}}),[y,a,i,x,h,w,v,b.caretPosition,b.currentLineStatus,b.editorInput]);e.useEffect((function(){return document.addEventListener("keydown",P),function(){document.removeEventListener("keydown",P)}}),[P])}({commands:c,errorMessage:s,defaultHandler:m,enableInput:d,prompt:i,consoleFocused:a}),v},P=function(t,n){e.useEffect((function(){n.current&&(n.current.scrollTop=n.current.scrollHeight)}),[t])};function S(t){var n=e.useRef(null),r=e.useContext(l),o=e.useContext(u),a=E(),i=a.store,c=a.send;P(i.bufferedContent,n);var s=t.enableInput,d=t.caret,m=t.consoleFocused,f=t.prompt,p=t.commands,C=t.welcomeMessage,_=t.errorMessage,h=t.showControlBar,x=t.defaultHandler,b=t.rounded?r["terminal--rounded"]:"",v=w(d,m,f,p,_,s,x);return e.createElement("div",{id:"terminalEditor",tabIndex:0,ref:n,onMouseDown:function(e){n.current&&2===e.button&&(n.current.contentEditable="true",setTimeout((function(){n.current.contentEditable="false"}),20))},onPaste:function(e){e.preventDefault(),c({type:"PASTE",text:e.clipboardData.getData("text")})},className:"".concat(r.editor," ").concat(b," ").concat(h?r.editorWithTopBar:null),style:{background:o.themeBGColor}},e.createElement(e.Fragment,null,C,i.bufferedContent,v))}function T(t){var n=e.useRef(null),r=e.useState(!0),o=r[0],a=r[1],i=e.useContext(l),c=e.useContext(u);d(n,o,a);var s=t.caret,f=void 0===s||s,p=t.theme,C=void 0===p?"light":p,_=t.showControlBar,h=void 0===_||_,x=t.showControlButtons,b=void 0===x||x,v=t.controlButtonLabels,g=void 0===v?["close","minimize","maximize"]:v,y=t.prompt,E=void 0===y?">>>":y,w=t.commands,P=void 0===w?{}:w,T=t.welcomeMessage,B=void 0===T?"":T,I=t.errorMessage,A=void 0===I?"not found!":I,k=t.enableInput,N=void 0===k||k,D=t.defaultHandler,L=void 0===D?null:D,F=t.rounded,O=void 0!==F&&F,R=O?i["terminal--rounded"]:"",W=h?e.createElement(m,{consoleFocused:o,showControlButtons:b,controlButtonLabels:g}):null,M=e.createElement(S,{caret:f,consoleFocused:o,prompt:E,commands:P,welcomeMessage:B,errorMessage:A,enableInput:N,showControlBar:h,defaultHandler:L,rounded:O});return e.createElement("div",{ref:n,id:i.terminalContainer,className:i["theme--".concat(C)],"data-testid":"terminal"},e.createElement("div",{className:"".concat(i.terminal," ").concat(R),style:{background:c.themeToolbarColor,color:c.themeColor}},W,M))}function B(t){var n=t.children;return e.createElement(i,null,e.createElement(s,null,n))}function I(t){return e.createElement(B,null,e.createElement(T,n({},t)))}var A=function(t){var n=t.children,r=t.useLocalStorage,o=void 0===r||r,a=e.useState(null),l=a[0],i=a[1],c={bufferedContent:null,commandsHistory:o?h():[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""},u=e.useReducer(v,c),s=u[0],d=u[1],m=e.useCallback((function(e){"SUBMIT"===e.type&&i(s.commandsHistory.length),d(e)}),[s.commandsHistory.length]);e.useEffect((function(){i(s.commandsHistory.length)}),[s.commandsHistory.length]);var f=e.useMemo((function(){return{send:m,store:s,getPreviousCommand:function(){if(0===l)return 0===s.commandsHistory.length?"":s.commandsHistory[0];var e=s.commandsHistory[l-1];return l>0&&i(l-1),e},getNextCommand:function(){if(l+1<=s.commandsHistory.length){var e=s.commandsHistory[l+1];return i(l+1),e}return""}}}),[l,m,s]);return e.createElement(b.Provider,{value:f},n)},k={ReactTerminal:I,TerminalContextProvider:A};export{I as ReactTerminal,A as TerminalContextProvider,k as default};
import*as e from"react";import{CancelablePromise as t}from"cancelable-promise";!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('@import url("https://fonts.googleapis.com/css?family=Source+Code+Pro&display=swap");\n#index-module_terminalContainer__i6yCT {\n --control-default-bg-color: #ccc;\n --control-close-bg-color: #fc5b57;\n --control-minimize-bg-color: #e5bf3c;\n --control-maximize-bg-color: #57c038;\n}\n\n.index-module_controls__-Pz-7 {\n text-align: left;\n height: 26px;\n position: relative;\n top: 4px;\n margin-left: 4px;\n}\n.index-module_controls__-Pz-7 .index-module_consoleCtrl__wASVf {\n display: inline-block;\n width: 13px;\n height: 13px;\n margin: 0 3px;\n border-radius: 50%;\n background: var(--control-default-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_close__Etu85 {\n background: var(--control-close-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_minimize__bT0-I {\n background: var(--control-minimize-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_maximize__mPPF7 {\n background: var(--control-maximize-bg-color);\n}\n\n.index-module_editor__CBDCJ {\n text-align: left;\n height: 100%;\n padding: 10px 15px;\n overflow-wrap: break-word;\n overflow-y: scroll;\n outline: none;\n font-family: "Source Code Pro", monospace;\n font-size: 18px;\n line-height: 22px;\n caret-color: transparent;\n --scroll-bar-thumb-color: transparent;\n --scroll-bar-track-color: transparent;\n --scroll-bar-width: 10px;\n scrollbar-color: var(--scroll-bar-thumb-color) var(--scroll-bar-track-color);\n scrollbar-width: var(--scroll-bar-width);\n}\n.index-module_editor--rounded__-VOd4 {\n border-radius: 5px;\n}\n.index-module_editor__CBDCJ::selection {\n background: transparent;\n}\n.index-module_editor__CBDCJ:focus, .index-module_editor__CBDCJ:hover {\n --scroll-bar-thumb-color: rgb(211 211 211 / 40%);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar {\n width: var(--scroll-bar-width);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-track {\n background-color: var(--scroll-bar-track-color);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-thumb {\n background-color: var(--scroll-bar-thumb-color);\n}\n.index-module_editor__CBDCJ .index-module_lineText__avQ48 {\n display: inline;\n position: relative;\n top: -1px;\n margin-left: 8px;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf {\n white-space: pre-wrap;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf:focus-visible {\n outline: none;\n}\n.index-module_editor__CBDCJ .index-module_charUnderCaret__-M0qT {\n z-index: 10;\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn {\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn .index-module_caretAfter__SMMlh {\n content: "";\n position: absolute;\n top: 2px;\n width: 10px;\n height: 22px;\n z-index: 10;\n}\n@-moz-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-webkit-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-o-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n.index-module_editor__CBDCJ a {\n color: #1a87b5;\n}\n\n.index-module_editorWithTopBar__opXWp {\n height: calc(100% - 46px);\n}\n\n#index-module_terminalContainer__i6yCT {\n height: 100%;\n}\n\n.index-module_terminal__EWHbJ {\n height: 100%;\n width: 100%;\n margin: auto;\n}\n.index-module_terminal--rounded__DZuxh {\n border-radius: 5px;\n}');const n={terminalContainer:"index-module_terminalContainer__i6yCT",controls:"index-module_controls__-Pz-7",consoleCtrl:"index-module_consoleCtrl__wASVf",close:"index-module_close__Etu85",minimize:"index-module_minimize__bT0-I",maximize:"index-module_maximize__mPPF7",editor:"index-module_editor__CBDCJ","editor--rounded":"index-module_editor--rounded__-VOd4",lineText:"index-module_lineText__avQ48",preWhiteSpace:"index-module_preWhiteSpace__v4IYf",charUnderCaret:"index-module_charUnderCaret__-M0qT",caret:"index-module_caret__YobLn",caretAfter:"index-module_caretAfter__SMMlh",editorWithTopBar:"index-module_editorWithTopBar__opXWp",terminal:"index-module_terminal__EWHbJ","terminal--rounded":"index-module_terminal--rounded__DZuxh",blink:"index-module_blink__l83VF"},r=e.createContext(null),o=t=>{const{children:o}=t;return e.createElement(r.Provider,{value:n},o)};const a={dark:{themeBGColor:"rgb(2, 40, 51)",themeToolbarColor:"rgb(19, 21, 25)",themeColor:"rgb(131, 148, 150)",themePromptColor:"rgb(169, 23, 168)"},light:{themeBGColor:"#fdf6e4",themeToolbarColor:"#d8d8d8",themeColor:"#333333",themePromptColor:"#a917a8"},dracula:{themeBGColor:"#272B36",themeToolbarColor:"#DBDBDB",themeColor:"#FFFEFC",themePromptColor:"#a917a8"},"material-dark":{themeBGColor:"#151515",themeToolbarColor:"#424242",themeColor:"#fff",themePromptColor:"#42A5F5"},"material-light":{themeBGColor:"#fafafa",themeToolbarColor:"#424242",themeColor:"#151515",themePromptColor:"#42A5F5"},"material-ocean":{themeBGColor:"#263238",themeToolbarColor:"#37474F",themeColor:"#fff",themePromptColor:"#C3D82C"},matrix:{themeBGColor:"#0D0208",themeToolbarColor:"#0D0208",themeColor:"#00FF41",themePromptColor:"#008F11"}},l=e.createContext(null),i=t=>{const{children:n}=t,r=Object.assign(Object.assign({},a),n.props.themes||{}),o=r[n.props.theme]||r.light;return e.createElement(l.Provider,{value:o},n)},s=(t,n,r)=>{const o=e=>{t.current&&!t.current.contains(e.target)?r(!1):r(!0)};e.useEffect((()=>(document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o)})))};function c(t){const n=e.useContext(r),{controlButtonLabels:o}=t,{showControlButtons:a}=t,l=a?o.map((t=>e.createElement("div",{key:t,className:`${n.consoleCtrl} ${n[t]}`}))):null;return e.createElement("div",{className:n.controls},l)}const d=["clear","cls"],u=e=>d.includes(e);class m{static splitStringAtIndex(e,t){return e?[e.substring(0,t),e.substring(t)]:["",""]}}const p="react-terminal-plus-commandHistory",f=()=>{var e;try{const t=null!==(e=localStorage.getItem(p))&&void 0!==e?e:"[]";return JSON.parse(t)}catch(e){return console.error(e),[]}},C=e=>{let t=f();t.push(e);try{JSON.stringify(t).length>52e5&&(t=t.slice(50)),localStorage.setItem(p,JSON.stringify(t))}catch(n){console.error(n),t=[e],localStorage.setItem(p,JSON.stringify(t))}},_=e.createContext(null);function x(e,t){switch(e.currentLineStatus){case"processing":switch(t.type){case"CANCEL":return Object.assign(Object.assign({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT_SUCCESS":return Object.assign(Object.assign({},e),{bufferedContent:t.successNode,currentLineStatus:"success",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});default:return e}case"success":case"error":case"idle":switch(t.type){case"CLEAR":return Object.assign(Object.assign({},e),{bufferedContent:null});case"CANCEL":return Object.assign(Object.assign({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT":{const{command:n}=t,r=[...e.commandsHistory];return n&&n!==r[r.length-1]&&(r.push(n),C(n)),u(n)?Object.assign(Object.assign({},e),{commandsHistory:r,bufferedContent:null,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""}):Object.assign(Object.assign({},e),{commandsHistory:r,bufferedContent:t.loaderNode,currentLineStatus:"processing",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""})}case"TYPE":{const[n,r]=h(e),o=n+t.text+r,a=e.caretPosition+1,[l,i]=b(o,a);return Object.assign(Object.assign({},e),{caretPosition:a,editorInput:o,textAfterCaret:i,textBeforeCaret:l})}case"DELETE":{const[t,n]=h(e),r=t.slice(0,-1)+n,o=e.caretPosition-1,[a,l]=b(r,o);return Object.assign(Object.assign({},e),{editorInput:r,caretPosition:o,textAfterCaret:l,textBeforeCaret:a})}case"COPY":return e;case"PASTE":{const[n,r]=h(e),o=n+t.text+r,a=e.caretPosition+t.text.length,[l,i]=b(o,a);return Object.assign(Object.assign({},e),{editorInput:o,caretPosition:a,textAfterCaret:i,textBeforeCaret:l})}case"ARROW_UP":{const n=t.previousCommand,r=t.previousCommand.length,[o,a]=b(n,r);return Object.assign(Object.assign({},e),{editorInput:n,caretPosition:r,textAfterCaret:a,textBeforeCaret:o})}case"ARROW_DOWN":{const n=t.nextCommand,r=t.nextCommand.length,[o,a]=b(n,r);return Object.assign(Object.assign({},e),{editorInput:n,caretPosition:r,textAfterCaret:a,textBeforeCaret:o})}case"RESET_CARET_POSITION":return Object.assign(Object.assign({},e),{editorInput:"",textBeforeCaret:"",textAfterCaret:"",caretPosition:0});case"ARROW_LEFT":{const t=e.caretPosition-1,[n,r]=b(e.editorInput,t);return Object.assign(Object.assign({},e),{caretPosition:t,textAfterCaret:r,textBeforeCaret:n})}case"ARROW_RIGHT":{const t=e.caretPosition+1,[n,r]=b(e.editorInput,t);return Object.assign(Object.assign({},e),{caretPosition:t,textAfterCaret:r,textBeforeCaret:n})}default:throw new Error(`Unhandled action type: ${JSON.stringify(t)}`)}default:return e}}function h(e){const[t,n]=m.splitStringAtIndex(e.editorInput,e.caretPosition);return[t,n]}function b(e,t){const[n,r]=m.splitStringAtIndex(e,t);return[n,r]}function g(){const t=e.useContext(_);if(void 0===t)throw new Error("useTerminal must be used within a TerminalContextProvider");return t}function y(e,t,n,r){return new(n||(n=Promise))((function(o,a){function l(e){try{s(r.next(e))}catch(e){a(e)}}function i(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,i)}s((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const E=(n,o,a,i,s,c,d)=>{const m=e.useContext(r),p=e.useContext(l),{store:f}=g(),C=f.textAfterCaret[0],_=f.textAfterCaret.slice(1),x=o&&n,h="processing"!==f.currentLineStatus?e.createElement(e.Fragment,null,e.createElement("span",{style:{color:p.themePromptColor}},a),e.createElement("div",{className:m.lineText},e.createElement("span",{className:m.preWhiteSpace},f.textBeforeCaret),x?e.createElement("span",{className:m.caret},e.createElement("span",{className:m.caretAfter,style:{background:p.themeColor}})):null,e.createElement("span",{className:`${m.preWhiteSpace}`},e.createElement("span",{style:{color:x?p.themeBGColor:p.themeColor},className:m.charUnderCaret},C),_))):e.createElement(e.Fragment,null,e.createElement("div",{className:m.lineText},x?e.createElement("span",{className:m.caret},e.createElement("span",{className:m.caretAfter,style:{background:p.themeColor}})):null));return(({consoleFocused:n,enableInput:o,commands:a,defaultHandler:i,errorMessage:s,prompt:c})=>{const d=e.useContext(r),m=e.useContext(l),{getPreviousCommand:p,getNextCommand:f,store:C,send:_}=g(),x=e.useRef(null),h=e.useCallback((()=>{x.current&&x.current.cancel();let t=e.createElement(e.Fragment,null,C.bufferedContent,e.createElement("span",{style:{color:m.themePromptColor}},c),e.createElement("span",{className:`${d.lineText} ${d.preWhiteSpace}`},C.editorInput),e.createElement("br",null));"processing"===C.currentLineStatus&&(t=e.createElement(e.Fragment,null,C.bufferedContent)),_({type:"CANCEL",cancelNode:t})}),[c,_,C.bufferedContent,C.currentLineStatus,C.editorInput,d.lineText,d.preWhiteSpace,m.themePromptColor]),b=e.useCallback((()=>y(void 0,void 0,void 0,(function*(){const[n,...r]=C.editorInput.trim().split(" "),o=C.editorInput.trim();let l="";const p=e.createElement(e.Fragment,null,C.bufferedContent,e.createElement("span",{style:{color:m.themePromptColor}},c),e.createElement("span",{className:`${d.lineText} ${d.preWhiteSpace}`},C.editorInput),e.createElement("br",null));if(_({type:"SUBMIT",loaderNode:p,command:o}),u(o))return;if(C.editorInput){const e=r.join(" ");if(o&&a[o]){const n=a[o];"function"==typeof n?(x.current=new t((t=>{t(n(e))})),l=yield x.current):l=n}else"function"==typeof i?(x.current=new t((t=>{t(i(n,e))})),l=yield x.current):"function"==typeof s?(x.current=new t((t=>{t(s(n,e))})),l=yield x.current):l=s}const f=e.createElement(e.Fragment,null,C.bufferedContent,e.createElement("span",{style:{color:m.themePromptColor}},c),e.createElement("span",{className:`${d.lineText} ${d.preWhiteSpace}`},C.editorInput),l?e.createElement("span",null,e.createElement("br",null),l):null,e.createElement("br",null));_({type:"SUBMIT_SUCCESS",successNode:f})}))),[_,C.bufferedContent,C.editorInput]),E=e.useCallback((e=>{if(!n)return;if(!o)return;e.preventDefault();const t=e.key;let r=null;if("Enter"===t)"processing"!==C.currentLineStatus&&b();else if("Backspace"===t)C.editorInput&&0!==C.editorInput.length&&_({type:"DELETE"});else if("ArrowUp"===t)r=p(),r&&_({type:"ARROW_UP",previousCommand:r});else if("ArrowDown"===t)r=f(),_(r?{type:"ARROW_DOWN",nextCommand:r}:{type:"RESET_CARET_POSITION"});else if("ArrowLeft"===t)C.caretPosition>0&&_({type:"ARROW_LEFT"}),r=C.editorInput;else if("ArrowRight"===t)C.caretPosition<C.editorInput.length&&_({type:"ARROW_RIGHT"}),r=C.editorInput;else if((e.metaKey||e.ctrlKey)&&"l"===t.toLowerCase())_({type:"CLEAR"});else if((e.metaKey||e.ctrlKey)&&"v"===t.toLowerCase())navigator.clipboard.readText().then((e=>{_({type:"PASTE",text:e})}));else if((e.metaKey||e.ctrlKey)&&"c"===t.toLowerCase()){const e=window.getSelection().toString();e?navigator.clipboard.writeText(e).then((()=>{_({type:"COPY"})})):h()}else t&&1===t.length&&_({type:"TYPE",text:t})}),[h,n,o,f,p,b,_,C.caretPosition,C.currentLineStatus,C.editorInput]);e.useEffect((()=>(document.addEventListener("keydown",E),()=>{document.removeEventListener("keydown",E)})),[E])})({commands:i,errorMessage:s,defaultHandler:d,enableInput:c,prompt:a,consoleFocused:o}),h},v=(t,n)=>{e.useEffect((()=>{n.current&&(n.current.scrollTop=n.current.scrollHeight)}),[t])};function P(t){const n=e.useRef(null),o=e.useContext(r),a=e.useContext(l),{store:i,send:s}=g();v(i.bufferedContent,n);const{enableInput:c,caret:d,consoleFocused:u,prompt:m,commands:p,welcomeMessage:f,errorMessage:C,showControlBar:_,defaultHandler:x,rounded:h}=t,b=h?o["terminal--rounded"]:"",y=E(d,u,m,p,C,c,x);return e.createElement("div",{id:"terminalEditor",tabIndex:0,ref:n,onMouseDown:e=>{n.current&&2===e.button&&(n.current.contentEditable="true",setTimeout((()=>{n.current.contentEditable="false"}),20))},onPaste:e=>{e.preventDefault(),s({type:"PASTE",text:e.clipboardData.getData("text")})},className:`${o.editor} ${b} ${_?o.editorWithTopBar:null}`,style:{background:a.themeBGColor}},e.createElement(e.Fragment,null,f,i.bufferedContent,y))}function S(t){const n=e.useRef(null),[o,a]=e.useState(!0),i=e.useContext(r),d=e.useContext(l);s(n,o,a);const{caret:u=!0,theme:m="light",showControlBar:p=!0,showControlButtons:f=!0,controlButtonLabels:C=["close","minimize","maximize"],prompt:_=">>>",commands:x={},welcomeMessage:h="",errorMessage:b="not found!",enableInput:g=!0,defaultHandler:y=null,rounded:E=!1}=t,v=E?i["terminal--rounded"]:"",S=p?e.createElement(c,{consoleFocused:o,showControlButtons:f,controlButtonLabels:C}):null,T=e.createElement(P,{caret:u,consoleFocused:o,prompt:_,commands:x,welcomeMessage:h,errorMessage:b,enableInput:g,showControlBar:p,defaultHandler:y,rounded:E});return e.createElement("div",{ref:n,id:i.terminalContainer,className:i[`theme--${m}`],"data-testid":"terminal"},e.createElement("div",{className:`${i.terminal} ${v}`,style:{background:d.themeToolbarColor,color:d.themeColor}},S,T))}function T(t){const{children:n}=t;return e.createElement(o,null,e.createElement(i,null,n))}function B(t){return e.createElement(T,null,e.createElement(S,Object.assign({},t)))}const I=function({children:t,useLocalStorage:n=!0}){const[r,o]=e.useState(null),a={bufferedContent:null,commandsHistory:n?f():[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""},[l,i]=e.useReducer(x,a),s=e.useCallback((e=>{"SUBMIT"===e.type&&o(l.commandsHistory.length),i(e)}),[l.commandsHistory.length]);e.useEffect((()=>{o(l.commandsHistory.length)}),[l.commandsHistory.length]);const c=e.useMemo((()=>({send:s,store:l,getPreviousCommand:()=>{if(0===r)return 0===l.commandsHistory.length?"":l.commandsHistory[0];const e=l.commandsHistory[r-1];return r>0&&o(r-1),e},getNextCommand:()=>{if(r+1<=l.commandsHistory.length){const e=l.commandsHistory[r+1];return o(r+1),e}return""}})),[r,s,l]);return e.createElement(_.Provider,{value:c},t)};var w={ReactTerminal:B,TerminalContextProvider:I};export{B as ReactTerminal,I as TerminalContextProvider,w as default};

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("cancelable-promise");function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var r=n(e),o=function(){return o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},o.apply(this,arguments)};function a(e,t,n,r){return new(n||(n=Promise))((function(o,a){function l(e){try{c(r.next(e))}catch(e){a(e)}}function i(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,i)}c((r=r.apply(e,t||[])).next())}))}function l(e,t){var n,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return l.label++,{value:i[1],done:!1};case 5:l.label++,r=i[1],i=[0];continue;case 7:i=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){l=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){l.label=i[1];break}if(6===i[0]&&l.label<o[1]){l.label=o[1],o=i;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(i);break}o[2]&&l.ops.pop(),l.trys.pop();continue}i=t.call(e,l)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('@import url("https://fonts.googleapis.com/css?family=Source+Code+Pro&display=swap");\n#index-module_terminalContainer__i6yCT {\n --control-default-bg-color: #ccc;\n --control-close-bg-color: #fc5b57;\n --control-minimize-bg-color: #e5bf3c;\n --control-maximize-bg-color: #57c038;\n}\n\n.index-module_controls__-Pz-7 {\n text-align: left;\n height: 26px;\n position: relative;\n top: 4px;\n margin-left: 4px;\n}\n.index-module_controls__-Pz-7 .index-module_consoleCtrl__wASVf {\n display: inline-block;\n width: 13px;\n height: 13px;\n margin: 0 3px;\n border-radius: 50%;\n background: var(--control-default-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_close__Etu85 {\n background: var(--control-close-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_minimize__bT0-I {\n background: var(--control-minimize-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_maximize__mPPF7 {\n background: var(--control-maximize-bg-color);\n}\n\n.index-module_editor__CBDCJ {\n text-align: left;\n height: 100%;\n padding: 10px 15px;\n overflow-wrap: break-word;\n overflow-y: scroll;\n outline: none;\n font-family: "Source Code Pro", monospace;\n font-size: 18px;\n line-height: 22px;\n caret-color: transparent;\n --scroll-bar-thumb-color: transparent;\n --scroll-bar-track-color: transparent;\n --scroll-bar-width: 10px;\n scrollbar-color: var(--scroll-bar-thumb-color) var(--scroll-bar-track-color);\n scrollbar-width: var(--scroll-bar-width);\n}\n.index-module_editor--rounded__-VOd4 {\n border-radius: 5px;\n}\n.index-module_editor__CBDCJ::selection {\n background: transparent;\n}\n.index-module_editor__CBDCJ:focus, .index-module_editor__CBDCJ:hover {\n --scroll-bar-thumb-color: rgb(211 211 211 / 40%);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar {\n width: var(--scroll-bar-width);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-track {\n background-color: var(--scroll-bar-track-color);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-thumb {\n background-color: var(--scroll-bar-thumb-color);\n}\n.index-module_editor__CBDCJ .index-module_lineText__avQ48 {\n display: inline;\n position: relative;\n top: -1px;\n margin-left: 8px;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf {\n white-space: pre-wrap;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf:focus-visible {\n outline: none;\n}\n.index-module_editor__CBDCJ .index-module_charUnderCaret__-M0qT {\n z-index: 10;\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn {\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn .index-module_caretAfter__SMMlh {\n content: "";\n position: absolute;\n top: 2px;\n width: 10px;\n height: 22px;\n z-index: 10;\n}\n@-moz-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-webkit-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-o-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n.index-module_editor__CBDCJ a {\n color: #1a87b5;\n}\n\n.index-module_editorWithTopBar__opXWp {\n height: calc(100% - 46px);\n}\n\n#index-module_terminalContainer__i6yCT {\n height: 100%;\n}\n\n.index-module_terminal__EWHbJ {\n height: 100%;\n width: 100%;\n margin: auto;\n}\n.index-module_terminal--rounded__DZuxh {\n border-radius: 5px;\n}');var i={terminalContainer:"index-module_terminalContainer__i6yCT",controls:"index-module_controls__-Pz-7",consoleCtrl:"index-module_consoleCtrl__wASVf",close:"index-module_close__Etu85",minimize:"index-module_minimize__bT0-I",maximize:"index-module_maximize__mPPF7",editor:"index-module_editor__CBDCJ","editor--rounded":"index-module_editor--rounded__-VOd4",lineText:"index-module_lineText__avQ48",preWhiteSpace:"index-module_preWhiteSpace__v4IYf",charUnderCaret:"index-module_charUnderCaret__-M0qT",caret:"index-module_caret__YobLn",caretAfter:"index-module_caretAfter__SMMlh",editorWithTopBar:"index-module_editorWithTopBar__opXWp",terminal:"index-module_terminal__EWHbJ","terminal--rounded":"index-module_terminal--rounded__DZuxh",blink:"index-module_blink__l83VF"},c=r.createContext(null),u=function(e){var t=e.children;return r.createElement(c.Provider,{value:i},t)},s={dark:{themeBGColor:"rgb(2, 40, 51)",themeToolbarColor:"rgb(19, 21, 25)",themeColor:"rgb(131, 148, 150)",themePromptColor:"rgb(169, 23, 168)"},light:{themeBGColor:"#fdf6e4",themeToolbarColor:"#d8d8d8",themeColor:"#333333",themePromptColor:"#a917a8"},dracula:{themeBGColor:"#272B36",themeToolbarColor:"#DBDBDB",themeColor:"#FFFEFC",themePromptColor:"#a917a8"},"material-dark":{themeBGColor:"#151515",themeToolbarColor:"#424242",themeColor:"#fff",themePromptColor:"#42A5F5"},"material-light":{themeBGColor:"#fafafa",themeToolbarColor:"#424242",themeColor:"#151515",themePromptColor:"#42A5F5"},"material-ocean":{themeBGColor:"#263238",themeToolbarColor:"#37474F",themeColor:"#fff",themePromptColor:"#C3D82C"},matrix:{themeBGColor:"#0D0208",themeToolbarColor:"#0D0208",themeColor:"#00FF41",themePromptColor:"#008F11"}},d=r.createContext(null),m=function(e){var t=e.children,n=o(o({},s),t.props.themes||{}),a=n[t.props.theme]||n.light;return r.createElement(d.Provider,{value:a},t)},f=function(e,t,n){var o=function(t){e.current&&!e.current.contains(t.target)?n(!1):n(!0)};r.useEffect((function(){return document.addEventListener("mousedown",o),function(){document.removeEventListener("mousedown",o)}}))};function p(e){var t=r.useContext(c),n=e.controlButtonLabels,o=e.showControlButtons?n.map((function(e){return r.createElement("div",{key:e,className:"".concat(t.consoleCtrl," ").concat(t[e])})})):null;return r.createElement("div",{className:t.controls},o)}var C=["clear","cls"],_=function(e){return C.includes(e)},h=function(){function e(){}return e.splitStringAtIndex=function(e,t){return e?[e.substring(0,t),e.substring(t)]:["",""]},e}(),x="react-terminal-plus-commandHistory",b=function(){var e;try{var t=null!==(e=localStorage.getItem(x))&&void 0!==e?e:"[]";return JSON.parse(t)}catch(e){return console.error(e),[]}},v=function(e){var t=b();t.push(e);try{JSON.stringify(t).length>20&&(t=t.slice(50)),localStorage.setItem(x,JSON.stringify(t))}catch(n){console.error(n),t=[e],localStorage.setItem(x,JSON.stringify(t))}},g=r.createContext(null);function y(e,t){switch(e.currentLineStatus){case"processing":switch(t.type){case"CANCEL":return o(o({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT_SUCCESS":return o(o({},e),{bufferedContent:t.successNode,currentLineStatus:"success",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});default:return e}case"success":case"error":case"idle":switch(t.type){case"CLEAR":return o(o({},e),{bufferedContent:null});case"CANCEL":return o(o({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT":var n=t.command,r=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,a=t.length;o<a;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e.commandsHistory,!0);return n&&n!==r[r.length-1]&&(r.push(n),v(n)),_(n)?o(o({},e),{commandsHistory:r,bufferedContent:null,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""}):o(o({},e),{commandsHistory:r,bufferedContent:t.loaderNode,currentLineStatus:"processing",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"TYPE":var a=E(e),l=a[0],i=a[1],c=P(h=l+t.text+i,b=e.caretPosition+1),u=c[0],s=c[1];return o(o({},e),{caretPosition:b,editorInput:h,textAfterCaret:s,textBeforeCaret:u});case"DELETE":var d=E(e),m=(l=d[0],i=d[1],P(h=l.slice(0,-1)+i,b=e.caretPosition-1));u=m[0],s=m[1];return o(o({},e),{editorInput:h,caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"COPY":return e;case"PASTE":var f=E(e),p=(l=f[0],i=f[1],P(h=l+t.text+i,b=e.caretPosition+t.text.length));u=p[0],s=p[1];return o(o({},e),{editorInput:h,caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"ARROW_UP":var C=P(h=t.previousCommand,b=t.previousCommand.length);u=C[0],s=C[1];return o(o({},e),{editorInput:h,caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"ARROW_DOWN":var h,x=P(h=t.nextCommand,b=t.nextCommand.length);u=x[0],s=x[1];return o(o({},e),{editorInput:h,caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"RESET_CARET_POSITION":return o(o({},e),{editorInput:"",textBeforeCaret:"",textAfterCaret:"",caretPosition:0});case"ARROW_LEFT":var b=e.caretPosition-1,g=P(e.editorInput,b);u=g[0],s=g[1];return o(o({},e),{caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"ARROW_RIGHT":b=e.caretPosition+1;var y=P(e.editorInput,b);u=y[0],s=y[1];return o(o({},e),{caretPosition:b,textAfterCaret:s,textBeforeCaret:u});default:throw new Error("Unhandled action type: ".concat(JSON.stringify(t)))}default:return e}}function E(e){var t=h.splitStringAtIndex(e.editorInput,e.caretPosition);return[t[0],t[1]]}function P(e,t){var n=h.splitStringAtIndex(e,t);return[n[0],n[1]]}function w(){var e=r.useContext(g);if(void 0===e)throw new Error("useTerminal must be used within a TerminalContextProvider");return e}var T=function(e,n,o,i,u,s,m){var f=r.useContext(c),p=r.useContext(d),C=w().store,h=C.textAfterCaret[0],x=C.textAfterCaret.slice(1),b=n&&e,v="processing"!==C.currentLineStatus?r.createElement(r.Fragment,null,r.createElement("span",{style:{color:p.themePromptColor}},o),r.createElement("div",{className:f.lineText},r.createElement("span",{className:f.preWhiteSpace},C.textBeforeCaret),b?r.createElement("span",{className:f.caret},r.createElement("span",{className:f.caretAfter,style:{background:p.themeColor}})):null,r.createElement("span",{className:"".concat(f.preWhiteSpace)},r.createElement("span",{style:{color:b?p.themeBGColor:p.themeColor},className:f.charUnderCaret},h),x))):r.createElement(r.Fragment,null,r.createElement("div",{className:f.lineText},b?r.createElement("span",{className:f.caret},r.createElement("span",{className:f.caretAfter,style:{background:p.themeColor}})):null));return function(e){var n=e.consoleFocused,o=e.enableInput,i=e.commands,u=e.defaultHandler,s=e.errorMessage,m=e.prompt,f=r.useContext(c),p=r.useContext(d),C=w(),h=C.getPreviousCommand,x=C.getNextCommand,b=C.store,v=C.send,g=r.useRef(null),y=r.useCallback((function(){g.current&&g.current.cancel();var e=r.createElement(r.Fragment,null,b.bufferedContent,r.createElement("span",{style:{color:p.themePromptColor}},m),r.createElement("span",{className:"".concat(f.lineText," ").concat(f.preWhiteSpace)},b.editorInput),r.createElement("br",null));"processing"===b.currentLineStatus&&(e=r.createElement(r.Fragment,null,b.bufferedContent)),v({type:"CANCEL",cancelNode:e})}),[m,v,b.bufferedContent,b.currentLineStatus,b.editorInput,f.lineText,f.preWhiteSpace,p.themePromptColor]),E=r.useCallback((function(){return a(void 0,void 0,void 0,(function(){var e,n,o,a,c,d,C,h,x;return l(this,(function(l){switch(l.label){case 0:return e=b.editorInput.trim().split(" "),n=e[0],o=e.slice(1),a=b.editorInput.trim(),c="",d=r.createElement(r.Fragment,null,b.bufferedContent,r.createElement("span",{style:{color:p.themePromptColor}},m),r.createElement("span",{className:"".concat(f.lineText," ").concat(f.preWhiteSpace)},b.editorInput),r.createElement("br",null)),v({type:"SUBMIT",loaderNode:d,command:a}),_(a)?[2]:b.editorInput?(C=o.join(" "),a&&i[a]?"function"!=typeof(h=i[a])?[3,2]:(g.current=new t.CancelablePromise((function(e){e(h(C))})),[4,g.current]):[3,4]):[3,9];case 1:return c=l.sent(),[3,3];case 2:c=h,l.label=3;case 3:return[3,9];case 4:return"function"!=typeof u?[3,6]:(g.current=new t.CancelablePromise((function(e){e(u(n,C))})),[4,g.current]);case 5:return c=l.sent(),[3,9];case 6:return"function"!=typeof s?[3,8]:(g.current=new t.CancelablePromise((function(e){e(s(n,C))})),[4,g.current]);case 7:return c=l.sent(),[3,9];case 8:c=s,l.label=9;case 9:return x=r.createElement(r.Fragment,null,b.bufferedContent,r.createElement("span",{style:{color:p.themePromptColor}},m),r.createElement("span",{className:"".concat(f.lineText," ").concat(f.preWhiteSpace)},b.editorInput),c?r.createElement("span",null,r.createElement("br",null),c):null,r.createElement("br",null)),v({type:"SUBMIT_SUCCESS",successNode:x}),[2]}}))}))}),[v,b.bufferedContent,b.editorInput]),P=r.useCallback((function(e){if(n&&o){e.preventDefault();var t=e.key,r=null;if("Enter"===t)"processing"!==b.currentLineStatus&&E();else if("Backspace"===t)b.editorInput&&0!==b.editorInput.length&&v({type:"DELETE"});else if("ArrowUp"===t)(r=h())&&v({type:"ARROW_UP",previousCommand:r});else if("ArrowDown"===t)r=x(),v(r?{type:"ARROW_DOWN",nextCommand:r}:{type:"RESET_CARET_POSITION"});else if("ArrowLeft"===t)b.caretPosition>0&&v({type:"ARROW_LEFT"}),r=b.editorInput;else if("ArrowRight"===t)b.caretPosition<b.editorInput.length&&v({type:"ARROW_RIGHT"}),r=b.editorInput;else if((e.metaKey||e.ctrlKey)&&"l"===t.toLowerCase())v({type:"CLEAR"});else if((e.metaKey||e.ctrlKey)&&"v"===t.toLowerCase())navigator.clipboard.readText().then((function(e){v({type:"PASTE",text:e})}));else if((e.metaKey||e.ctrlKey)&&"c"===t.toLowerCase()){var a=window.getSelection().toString();a?navigator.clipboard.writeText(a).then((function(){v({type:"COPY"})})):y()}else t&&1===t.length&&v({type:"TYPE",text:t})}}),[y,n,o,x,h,E,v,b.caretPosition,b.currentLineStatus,b.editorInput]);r.useEffect((function(){return document.addEventListener("keydown",P),function(){document.removeEventListener("keydown",P)}}),[P])}({commands:i,errorMessage:u,defaultHandler:m,enableInput:s,prompt:o,consoleFocused:n}),v},S=function(e,t){r.useEffect((function(){t.current&&(t.current.scrollTop=t.current.scrollHeight)}),[e])};function B(e){var t=r.useRef(null),n=r.useContext(c),o=r.useContext(d),a=w(),l=a.store,i=a.send;S(l.bufferedContent,t);var u=e.enableInput,s=e.caret,m=e.consoleFocused,f=e.prompt,p=e.commands,C=e.welcomeMessage,_=e.errorMessage,h=e.showControlBar,x=e.defaultHandler,b=e.rounded?n["terminal--rounded"]:"",v=T(s,m,f,p,_,u,x);return r.createElement("div",{id:"terminalEditor",tabIndex:0,ref:t,onMouseDown:function(e){t.current&&2===e.button&&(t.current.contentEditable="true",setTimeout((function(){t.current.contentEditable="false"}),20))},onPaste:function(e){e.preventDefault(),i({type:"PASTE",text:e.clipboardData.getData("text")})},className:"".concat(n.editor," ").concat(b," ").concat(h?n.editorWithTopBar:null),style:{background:o.themeBGColor}},r.createElement(r.Fragment,null,C,l.bufferedContent,v))}function I(e){var t=r.useRef(null),n=r.useState(!0),o=n[0],a=n[1],l=r.useContext(c),i=r.useContext(d);f(t,o,a);var u=e.caret,s=void 0===u||u,m=e.theme,C=void 0===m?"light":m,_=e.showControlBar,h=void 0===_||_,x=e.showControlButtons,b=void 0===x||x,v=e.controlButtonLabels,g=void 0===v?["close","minimize","maximize"]:v,y=e.prompt,E=void 0===y?">>>":y,P=e.commands,w=void 0===P?{}:P,T=e.welcomeMessage,S=void 0===T?"":T,I=e.errorMessage,A=void 0===I?"not found!":I,k=e.enableInput,N=void 0===k||k,D=e.defaultHandler,O=void 0===D?null:D,L=e.rounded,F=void 0!==L&&L,R=F?l["terminal--rounded"]:"",W=h?r.createElement(p,{consoleFocused:o,showControlButtons:b,controlButtonLabels:g}):null,M=r.createElement(B,{caret:s,consoleFocused:o,prompt:E,commands:w,welcomeMessage:S,errorMessage:A,enableInput:N,showControlBar:h,defaultHandler:O,rounded:F});return r.createElement("div",{ref:t,id:l.terminalContainer,className:l["theme--".concat(C)],"data-testid":"terminal"},r.createElement("div",{className:"".concat(l.terminal," ").concat(R),style:{background:i.themeToolbarColor,color:i.themeColor}},W,M))}function A(e){var t=e.children;return r.createElement(u,null,r.createElement(m,null,t))}function k(e){return r.createElement(A,null,r.createElement(I,o({},e)))}var N=function(e){var t=e.children,n=e.useLocalStorage,o=void 0===n||n,a=r.useState(null),l=a[0],i=a[1],c={bufferedContent:null,commandsHistory:o?b():[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""},u=r.useReducer(y,c),s=u[0],d=u[1],m=r.useCallback((function(e){"SUBMIT"===e.type&&i(s.commandsHistory.length),d(e)}),[s.commandsHistory.length]);r.useEffect((function(){i(s.commandsHistory.length)}),[s.commandsHistory.length]);var f=r.useMemo((function(){return{send:m,store:s,getPreviousCommand:function(){if(0===l)return 0===s.commandsHistory.length?"":s.commandsHistory[0];var e=s.commandsHistory[l-1];return l>0&&i(l-1),e},getNextCommand:function(){if(l+1<=s.commandsHistory.length){var e=s.commandsHistory[l+1];return i(l+1),e}return""}}}),[l,m,s]);return r.createElement(g.Provider,{value:f},t)},D={ReactTerminal:k,TerminalContextProvider:N};exports.ReactTerminal=k,exports.TerminalContextProvider=N,exports.default=D;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("cancelable-promise");function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var r=n(e);!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('@import url("https://fonts.googleapis.com/css?family=Source+Code+Pro&display=swap");\n#index-module_terminalContainer__i6yCT {\n --control-default-bg-color: #ccc;\n --control-close-bg-color: #fc5b57;\n --control-minimize-bg-color: #e5bf3c;\n --control-maximize-bg-color: #57c038;\n}\n\n.index-module_controls__-Pz-7 {\n text-align: left;\n height: 26px;\n position: relative;\n top: 4px;\n margin-left: 4px;\n}\n.index-module_controls__-Pz-7 .index-module_consoleCtrl__wASVf {\n display: inline-block;\n width: 13px;\n height: 13px;\n margin: 0 3px;\n border-radius: 50%;\n background: var(--control-default-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_close__Etu85 {\n background: var(--control-close-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_minimize__bT0-I {\n background: var(--control-minimize-bg-color);\n}\n.index-module_controls__-Pz-7 .index-module_maximize__mPPF7 {\n background: var(--control-maximize-bg-color);\n}\n\n.index-module_editor__CBDCJ {\n text-align: left;\n height: 100%;\n padding: 10px 15px;\n overflow-wrap: break-word;\n overflow-y: scroll;\n outline: none;\n font-family: "Source Code Pro", monospace;\n font-size: 18px;\n line-height: 22px;\n caret-color: transparent;\n --scroll-bar-thumb-color: transparent;\n --scroll-bar-track-color: transparent;\n --scroll-bar-width: 10px;\n scrollbar-color: var(--scroll-bar-thumb-color) var(--scroll-bar-track-color);\n scrollbar-width: var(--scroll-bar-width);\n}\n.index-module_editor--rounded__-VOd4 {\n border-radius: 5px;\n}\n.index-module_editor__CBDCJ::selection {\n background: transparent;\n}\n.index-module_editor__CBDCJ:focus, .index-module_editor__CBDCJ:hover {\n --scroll-bar-thumb-color: rgb(211 211 211 / 40%);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar {\n width: var(--scroll-bar-width);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-track {\n background-color: var(--scroll-bar-track-color);\n}\n.index-module_editor__CBDCJ::-webkit-scrollbar-thumb {\n background-color: var(--scroll-bar-thumb-color);\n}\n.index-module_editor__CBDCJ .index-module_lineText__avQ48 {\n display: inline;\n position: relative;\n top: -1px;\n margin-left: 8px;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf {\n white-space: pre-wrap;\n}\n.index-module_editor__CBDCJ .index-module_preWhiteSpace__v4IYf:focus-visible {\n outline: none;\n}\n.index-module_editor__CBDCJ .index-module_charUnderCaret__-M0qT {\n z-index: 10;\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn {\n position: relative;\n}\n.index-module_editor__CBDCJ .index-module_caret__YobLn .index-module_caretAfter__SMMlh {\n content: "";\n position: absolute;\n top: 2px;\n width: 10px;\n height: 22px;\n z-index: 10;\n}\n@-moz-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-webkit-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@-o-keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n@keyframes index-module_blink__l83VF {\n 0% {\n opacity: 0;\n -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\n filter: alpha(opacity=0);\n }\n 100% {\n opacity: 1;\n -ms-filter: none;\n filter: none;\n }\n}\n.index-module_editor__CBDCJ a {\n color: #1a87b5;\n}\n\n.index-module_editorWithTopBar__opXWp {\n height: calc(100% - 46px);\n}\n\n#index-module_terminalContainer__i6yCT {\n height: 100%;\n}\n\n.index-module_terminal__EWHbJ {\n height: 100%;\n width: 100%;\n margin: auto;\n}\n.index-module_terminal--rounded__DZuxh {\n border-radius: 5px;\n}');const o={terminalContainer:"index-module_terminalContainer__i6yCT",controls:"index-module_controls__-Pz-7",consoleCtrl:"index-module_consoleCtrl__wASVf",close:"index-module_close__Etu85",minimize:"index-module_minimize__bT0-I",maximize:"index-module_maximize__mPPF7",editor:"index-module_editor__CBDCJ","editor--rounded":"index-module_editor--rounded__-VOd4",lineText:"index-module_lineText__avQ48",preWhiteSpace:"index-module_preWhiteSpace__v4IYf",charUnderCaret:"index-module_charUnderCaret__-M0qT",caret:"index-module_caret__YobLn",caretAfter:"index-module_caretAfter__SMMlh",editorWithTopBar:"index-module_editorWithTopBar__opXWp",terminal:"index-module_terminal__EWHbJ","terminal--rounded":"index-module_terminal--rounded__DZuxh",blink:"index-module_blink__l83VF"},a=r.createContext(null),l=e=>{const{children:t}=e;return r.createElement(a.Provider,{value:o},t)};const i={dark:{themeBGColor:"rgb(2, 40, 51)",themeToolbarColor:"rgb(19, 21, 25)",themeColor:"rgb(131, 148, 150)",themePromptColor:"rgb(169, 23, 168)"},light:{themeBGColor:"#fdf6e4",themeToolbarColor:"#d8d8d8",themeColor:"#333333",themePromptColor:"#a917a8"},dracula:{themeBGColor:"#272B36",themeToolbarColor:"#DBDBDB",themeColor:"#FFFEFC",themePromptColor:"#a917a8"},"material-dark":{themeBGColor:"#151515",themeToolbarColor:"#424242",themeColor:"#fff",themePromptColor:"#42A5F5"},"material-light":{themeBGColor:"#fafafa",themeToolbarColor:"#424242",themeColor:"#151515",themePromptColor:"#42A5F5"},"material-ocean":{themeBGColor:"#263238",themeToolbarColor:"#37474F",themeColor:"#fff",themePromptColor:"#C3D82C"},matrix:{themeBGColor:"#0D0208",themeToolbarColor:"#0D0208",themeColor:"#00FF41",themePromptColor:"#008F11"}},c=r.createContext(null),s=e=>{const{children:t}=e,n=Object.assign(Object.assign({},i),t.props.themes||{}),o=n[t.props.theme]||n.light;return r.createElement(c.Provider,{value:o},t)},d=(e,t,n)=>{const o=t=>{e.current&&!e.current.contains(t.target)?n(!1):n(!0)};r.useEffect((()=>(document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o)})))};function u(e){const t=r.useContext(a),{controlButtonLabels:n}=e,{showControlButtons:o}=e,l=o?n.map((e=>r.createElement("div",{key:e,className:`${t.consoleCtrl} ${t[e]}`}))):null;return r.createElement("div",{className:t.controls},l)}const m=["clear","cls"],p=e=>m.includes(e);class f{static splitStringAtIndex(e,t){return e?[e.substring(0,t),e.substring(t)]:["",""]}}const C="react-terminal-plus-commandHistory",_=()=>{var e;try{const t=null!==(e=localStorage.getItem(C))&&void 0!==e?e:"[]";return JSON.parse(t)}catch(e){return console.error(e),[]}},x=e=>{let t=_();t.push(e);try{JSON.stringify(t).length>52e5&&(t=t.slice(50)),localStorage.setItem(C,JSON.stringify(t))}catch(n){console.error(n),t=[e],localStorage.setItem(C,JSON.stringify(t))}},b=r.createContext(null);function h(e,t){switch(e.currentLineStatus){case"processing":switch(t.type){case"CANCEL":return Object.assign(Object.assign({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT_SUCCESS":return Object.assign(Object.assign({},e),{bufferedContent:t.successNode,currentLineStatus:"success",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});default:return e}case"success":case"error":case"idle":switch(t.type){case"CLEAR":return Object.assign(Object.assign({},e),{bufferedContent:null});case"CANCEL":return Object.assign(Object.assign({},e),{bufferedContent:t.cancelNode,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""});case"SUBMIT":{const{command:n}=t,r=[...e.commandsHistory];return n&&n!==r[r.length-1]&&(r.push(n),x(n)),p(n)?Object.assign(Object.assign({},e),{commandsHistory:r,bufferedContent:null,editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""}):Object.assign(Object.assign({},e),{commandsHistory:r,bufferedContent:t.loaderNode,currentLineStatus:"processing",editorInput:"",caretPosition:0,textBeforeCaret:"",textAfterCaret:""})}case"TYPE":{const[n,r]=g(e),o=n+t.text+r,a=e.caretPosition+1,[l,i]=y(o,a);return Object.assign(Object.assign({},e),{caretPosition:a,editorInput:o,textAfterCaret:i,textBeforeCaret:l})}case"DELETE":{const[t,n]=g(e),r=t.slice(0,-1)+n,o=e.caretPosition-1,[a,l]=y(r,o);return Object.assign(Object.assign({},e),{editorInput:r,caretPosition:o,textAfterCaret:l,textBeforeCaret:a})}case"COPY":return e;case"PASTE":{const[n,r]=g(e),o=n+t.text+r,a=e.caretPosition+t.text.length,[l,i]=y(o,a);return Object.assign(Object.assign({},e),{editorInput:o,caretPosition:a,textAfterCaret:i,textBeforeCaret:l})}case"ARROW_UP":{const n=t.previousCommand,r=t.previousCommand.length,[o,a]=y(n,r);return Object.assign(Object.assign({},e),{editorInput:n,caretPosition:r,textAfterCaret:a,textBeforeCaret:o})}case"ARROW_DOWN":{const n=t.nextCommand,r=t.nextCommand.length,[o,a]=y(n,r);return Object.assign(Object.assign({},e),{editorInput:n,caretPosition:r,textAfterCaret:a,textBeforeCaret:o})}case"RESET_CARET_POSITION":return Object.assign(Object.assign({},e),{editorInput:"",textBeforeCaret:"",textAfterCaret:"",caretPosition:0});case"ARROW_LEFT":{const t=e.caretPosition-1,[n,r]=y(e.editorInput,t);return Object.assign(Object.assign({},e),{caretPosition:t,textAfterCaret:r,textBeforeCaret:n})}case"ARROW_RIGHT":{const t=e.caretPosition+1,[n,r]=y(e.editorInput,t);return Object.assign(Object.assign({},e),{caretPosition:t,textAfterCaret:r,textBeforeCaret:n})}default:throw new Error(`Unhandled action type: ${JSON.stringify(t)}`)}default:return e}}function g(e){const[t,n]=f.splitStringAtIndex(e.editorInput,e.caretPosition);return[t,n]}function y(e,t){const[n,r]=f.splitStringAtIndex(e,t);return[n,r]}function E(){const e=r.useContext(b);if(void 0===e)throw new Error("useTerminal must be used within a TerminalContextProvider");return e}function P(e,t,n,r){return new(n||(n=Promise))((function(o,a){function l(e){try{c(r.next(e))}catch(e){a(e)}}function i(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,i)}c((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const v=(e,n,o,l,i,s,d)=>{const u=r.useContext(a),m=r.useContext(c),{store:f}=E(),C=f.textAfterCaret[0],_=f.textAfterCaret.slice(1),x=n&&e,b="processing"!==f.currentLineStatus?r.createElement(r.Fragment,null,r.createElement("span",{style:{color:m.themePromptColor}},o),r.createElement("div",{className:u.lineText},r.createElement("span",{className:u.preWhiteSpace},f.textBeforeCaret),x?r.createElement("span",{className:u.caret},r.createElement("span",{className:u.caretAfter,style:{background:m.themeColor}})):null,r.createElement("span",{className:`${u.preWhiteSpace}`},r.createElement("span",{style:{color:x?m.themeBGColor:m.themeColor},className:u.charUnderCaret},C),_))):r.createElement(r.Fragment,null,r.createElement("div",{className:u.lineText},x?r.createElement("span",{className:u.caret},r.createElement("span",{className:u.caretAfter,style:{background:m.themeColor}})):null));return(({consoleFocused:e,enableInput:n,commands:o,defaultHandler:l,errorMessage:i,prompt:s})=>{const d=r.useContext(a),u=r.useContext(c),{getPreviousCommand:m,getNextCommand:f,store:C,send:_}=E(),x=r.useRef(null),b=r.useCallback((()=>{x.current&&x.current.cancel();let e=r.createElement(r.Fragment,null,C.bufferedContent,r.createElement("span",{style:{color:u.themePromptColor}},s),r.createElement("span",{className:`${d.lineText} ${d.preWhiteSpace}`},C.editorInput),r.createElement("br",null));"processing"===C.currentLineStatus&&(e=r.createElement(r.Fragment,null,C.bufferedContent)),_({type:"CANCEL",cancelNode:e})}),[s,_,C.bufferedContent,C.currentLineStatus,C.editorInput,d.lineText,d.preWhiteSpace,u.themePromptColor]),h=r.useCallback((()=>P(void 0,void 0,void 0,(function*(){const[e,...n]=C.editorInput.trim().split(" "),a=C.editorInput.trim();let c="";const m=r.createElement(r.Fragment,null,C.bufferedContent,r.createElement("span",{style:{color:u.themePromptColor}},s),r.createElement("span",{className:`${d.lineText} ${d.preWhiteSpace}`},C.editorInput),r.createElement("br",null));if(_({type:"SUBMIT",loaderNode:m,command:a}),p(a))return;if(C.editorInput){const r=n.join(" ");if(a&&o[a]){const e=o[a];"function"==typeof e?(x.current=new t.CancelablePromise((t=>{t(e(r))})),c=yield x.current):c=e}else"function"==typeof l?(x.current=new t.CancelablePromise((t=>{t(l(e,r))})),c=yield x.current):"function"==typeof i?(x.current=new t.CancelablePromise((t=>{t(i(e,r))})),c=yield x.current):c=i}const f=r.createElement(r.Fragment,null,C.bufferedContent,r.createElement("span",{style:{color:u.themePromptColor}},s),r.createElement("span",{className:`${d.lineText} ${d.preWhiteSpace}`},C.editorInput),c?r.createElement("span",null,r.createElement("br",null),c):null,r.createElement("br",null));_({type:"SUBMIT_SUCCESS",successNode:f})}))),[_,C.bufferedContent,C.editorInput]),g=r.useCallback((t=>{if(!e)return;if(!n)return;t.preventDefault();const r=t.key;let o=null;if("Enter"===r)"processing"!==C.currentLineStatus&&h();else if("Backspace"===r)C.editorInput&&0!==C.editorInput.length&&_({type:"DELETE"});else if("ArrowUp"===r)o=m(),o&&_({type:"ARROW_UP",previousCommand:o});else if("ArrowDown"===r)o=f(),_(o?{type:"ARROW_DOWN",nextCommand:o}:{type:"RESET_CARET_POSITION"});else if("ArrowLeft"===r)C.caretPosition>0&&_({type:"ARROW_LEFT"}),o=C.editorInput;else if("ArrowRight"===r)C.caretPosition<C.editorInput.length&&_({type:"ARROW_RIGHT"}),o=C.editorInput;else if((t.metaKey||t.ctrlKey)&&"l"===r.toLowerCase())_({type:"CLEAR"});else if((t.metaKey||t.ctrlKey)&&"v"===r.toLowerCase())navigator.clipboard.readText().then((e=>{_({type:"PASTE",text:e})}));else if((t.metaKey||t.ctrlKey)&&"c"===r.toLowerCase()){const e=window.getSelection().toString();e?navigator.clipboard.writeText(e).then((()=>{_({type:"COPY"})})):b()}else r&&1===r.length&&_({type:"TYPE",text:r})}),[b,e,n,f,m,h,_,C.caretPosition,C.currentLineStatus,C.editorInput]);r.useEffect((()=>(document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g)})),[g])})({commands:l,errorMessage:i,defaultHandler:d,enableInput:s,prompt:o,consoleFocused:n}),b},T=(e,t)=>{r.useEffect((()=>{t.current&&(t.current.scrollTop=t.current.scrollHeight)}),[e])};function S(e){const t=r.useRef(null),n=r.useContext(a),o=r.useContext(c),{store:l,send:i}=E();T(l.bufferedContent,t);const{enableInput:s,caret:d,consoleFocused:u,prompt:m,commands:p,welcomeMessage:f,errorMessage:C,showControlBar:_,defaultHandler:x,rounded:b}=e,h=b?n["terminal--rounded"]:"",g=v(d,u,m,p,C,s,x);return r.createElement("div",{id:"terminalEditor",tabIndex:0,ref:t,onMouseDown:e=>{t.current&&2===e.button&&(t.current.contentEditable="true",setTimeout((()=>{t.current.contentEditable="false"}),20))},onPaste:e=>{e.preventDefault(),i({type:"PASTE",text:e.clipboardData.getData("text")})},className:`${n.editor} ${h} ${_?n.editorWithTopBar:null}`,style:{background:o.themeBGColor}},r.createElement(r.Fragment,null,f,l.bufferedContent,g))}function O(e){const t=r.useRef(null),[n,o]=r.useState(!0),l=r.useContext(a),i=r.useContext(c);d(t,n,o);const{caret:s=!0,theme:m="light",showControlBar:p=!0,showControlButtons:f=!0,controlButtonLabels:C=["close","minimize","maximize"],prompt:_=">>>",commands:x={},welcomeMessage:b="",errorMessage:h="not found!",enableInput:g=!0,defaultHandler:y=null,rounded:E=!1}=e,P=E?l["terminal--rounded"]:"",v=p?r.createElement(u,{consoleFocused:n,showControlButtons:f,controlButtonLabels:C}):null,T=r.createElement(S,{caret:s,consoleFocused:n,prompt:_,commands:x,welcomeMessage:b,errorMessage:h,enableInput:g,showControlBar:p,defaultHandler:y,rounded:E});return r.createElement("div",{ref:t,id:l.terminalContainer,className:l[`theme--${m}`],"data-testid":"terminal"},r.createElement("div",{className:`${l.terminal} ${P}`,style:{background:i.themeToolbarColor,color:i.themeColor}},v,T))}function B(e){const{children:t}=e;return r.createElement(l,null,r.createElement(s,null,t))}function w(e){return r.createElement(B,null,r.createElement(O,Object.assign({},e)))}const I=function({children:e,useLocalStorage:t=!0}){const[n,o]=r.useState(null),a={bufferedContent:null,commandsHistory:t?_():[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""},[l,i]=r.useReducer(h,a),c=r.useCallback((e=>{"SUBMIT"===e.type&&o(l.commandsHistory.length),i(e)}),[l.commandsHistory.length]);r.useEffect((()=>{o(l.commandsHistory.length)}),[l.commandsHistory.length]);const s=r.useMemo((()=>({send:c,store:l,getPreviousCommand:()=>{if(0===n)return 0===l.commandsHistory.length?"":l.commandsHistory[0];const e=l.commandsHistory[n-1];return n>0&&o(n-1),e},getNextCommand:()=>{if(n+1<=l.commandsHistory.length){const e=l.commandsHistory[n+1];return o(n+1),e}return""}})),[n,c,l]);return r.createElement(b.Provider,{value:s},e)};var A={ReactTerminal:w,TerminalContextProvider:I};exports.ReactTerminal=w,exports.TerminalContextProvider=I,exports.default=A;

@@ -60,3 +60,3 @@ import * as React from "react";

};
export declare function TerminalContextProvider({ children, useLocalStorage }: TerminalContextProviderProps): React.JSX.Element;
export declare function TerminalContextProvider({ children, useLocalStorage, }: TerminalContextProviderProps): React.JSX.Element;
export declare function useTerminal(): TerminalContextState;

@@ -63,0 +63,0 @@ declare const _default: {

import * as React from "react";
export declare const useEditorInput: ({ consoleFocused, enableInput, commands, defaultHandler, errorMessage, prompt }: {
export declare const useEditorInput: ({ consoleFocused, enableInput, commands, defaultHandler, errorMessage, prompt, }: {
consoleFocused: boolean;

@@ -4,0 +4,0 @@ enableInput: boolean;

@@ -1,4 +0,4 @@

import * as React from 'react';
import { TerminalContextProvider as _TerminalContextProvider } from './contexts/TerminalContext';
import type { TerminalProps } from './components/Terminal';
import * as React from "react";
import { TerminalContextProvider as _TerminalContextProvider } from "./contexts/TerminalContext";
import type { TerminalProps } from "./components/Terminal";
export declare function ReactTerminal<ThemesT extends string = never>(props: TerminalProps<ThemesT>): React.JSX.Element;

@@ -5,0 +5,0 @@ export declare const TerminalContextProvider: typeof _TerminalContextProvider;

{
"name": "react-terminal-plus",
"np": {
"tests": false
},
"version": "0.0.15",
"description": "A fork of the the 'react-terminal' package, with some extra features - react-terminal-plus",
"main": "dist/index.js",
"module": "dist/index.es.js",
"types": "dist/src/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "./node_modules/.bin/cross-env NODE_ENV=production rollup -c",
"watch": "rollup -cw",
"test": "cypress run --component --headless",
"cct:open": "cypress open --component",
"test:jest": "jest",
"prepublishOnly": "npm run build",
"release": "npx np"
},
"files": [
"dist",
"LICENCE",
"package.json",
"README.md"
],
"repository": {
"type": "git",
"url": "git@gitlab.com:singlestore/engineering/react-terminal-fork.git"
},
"keywords": [
"node",
"npm",
"react",
"terminal"
],
"author": "SingleStore",
"license": "MIT",
"homepage": "https://github.com/bony2023/react-terminal#readme",
"devDependencies": {
"@testing-library/cypress": "^9.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.2.0",
"@types/enzyme": "^3.10.4",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@types/react-test-renderer": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"@vitejs/plugin-react": "^4.0.4",
"cheerio": "1.0.0-rc.12",
"codecov": "^3.6.1",
"cross-env": "^7.0.3",
"cypress": "^12.17.2",
"cypress-real-events": "^1.9.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.7",
"enzyme-to-json": "^3.4.3",
"eslint": "^8.33.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.1",
"npm-install-peers": "^1.2.1",
"postcss": "^8.4.21",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-test-renderer": "^18.2.0",
"rollup": "^3.13.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.34.1",
"sass": "^1.58.0",
"ts-jest": "^29.0.5",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5",
"vite": "^4.4.8"
},
"resolutions": {
"cheerio": "1.0.0-rc.10"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"jest": {
"testEnvironment": "jsdom",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"moduleNameMapper": {
"^.+\\.(css|less|scss)$": "identity-obj-proxy"
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"testMatch": [
"**/tests/**/?(*.)+(spec|test).[jt]s?(x)"
],
"coverageDirectory": "./coverage/",
"collectCoverage": true
},
"dependencies": {
"cancelable-promise": "^4.3.1"
},
"engines": {
"node": ">=16"
}
"name": "react-terminal-plus",
"version": "0.0.16",
"description": "A improved version of `react-terminal` - react-terminal-plus",
"keywords": [
"node",
"npm",
"react",
"terminal"
],
"homepage": "https://github.com/singlestore-labs/react-terminal-plus#readme",
"repository": {
"type": "git",
"url": "https://github.com/singlestore-labs/react-terminal-plus.git"
},
"license": "MIT",
"author": {
"name": "Pedro Figueiredo",
"email": "klisarkk@gmail.com"
},
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.es.js",
"types": "dist/src/index.d.ts",
"files": [
"dist",
"LICENCE",
"package.json",
"README.md"
],
"scripts": {
"build": "./node_modules/.bin/cross-env NODE_ENV=production rollup -c",
"cct:open": "cypress open --component",
"format": "prettier \"**/*\" --ignore-unknown --write",
"preinstall": "npx only-allow pnpm && cd ./example && pnpm install",
"postinstall": "husky install",
"prepare": "husky install",
"prepublishOnly": "npm run build",
"release": "npx np",
"start": "cd ./example && pnpm run start",
"test": "cypress run --component --headless",
"watch": "rollup -cw"
},
"lint-staged": {
"*": "prettier --ignore-unknown --write"
},
"dependencies": {
"cancelable-promise": "^4.3.1"
},
"devDependencies": {
"@testing-library/cypress": "^9.0.0",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"@vitejs/plugin-react": "^4.0.4",
"cross-env": "^7.0.3",
"cypress": "^12.17.2",
"cypress-real-events": "^1.9.1",
"eslint": "^8.33.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.0",
"lint-staged": "^15.0.2",
"postcss": "^8.4.21",
"prettier": "3.0.3",
"prettier-plugin-curly": "^0.1.3",
"prettier-plugin-packagejson": "^2.4.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"rollup": "^3.13.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.34.1",
"sass": "^1.58.0",
"tslib": "^2.6.2",
"typescript": "^4.9.5",
"vite": "^4.4.8"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"engines": {
"node": ">=18"
},
"np": {
"tests": true
}
}

@@ -1,80 +0,123 @@

# Forked version of react-terminal
# react-terminal-plus
original repo: https://github.com/bony2023/react-terminal
<p align="center">๐Ÿš€ React component that renders and feels like a Terminal ๐Ÿ–ฅ</p>
setting up github repo in gitlab: https://gist.github.com/DavideMontersino/810ebaa170a2aa2d2cad
<p align="center">
<a href="#features">Features</a> โ€ข
<a href="#installation">Installation</a> โ€ข
<a href="#usage">Usage</a> โ€ข
<a href="#props">Props</a> โ€ข
<a href="#development">Development</a> โ€ข
<a href="#credits">Credits</a>
</p>
## Roadmap
<img alt="react-terminal-plus preview" src="./react-terminal-plus.gif" />
Features to add:
## Features
- [X]: Properly styled results - `white-space: pre-wrap;`
- [X]: Add new native commands like: CTRL+L, CTRL+C
- []: Hook to run controlled commands - e.g useTerminal()
- []: Allow highlighting of text with keyboard
- Mobile support. ๐Ÿ“ฑ
- Customizable commands, prompt and error message. โœ…
- Support callbacks(async/non-async) for commands. ๐Ÿ”„
- Command history using arrow up and down. ๐Ÿ”ผ
- Support for copy/paste through keyboard and browser's context. ๐Ÿ“‹
- Cancel running command using `Ctrl + C`. โ›”
- In-built themes and support to create more. ๐Ÿš€
- Clear the terminal with `clear` command or using `Ctrl + L`. ๐Ÿงน
- Local storage support for the command history. ๐Ÿ’พ
- Full TypeScript support. ๐ŸŽ‰
### New Commands
## Installation
- cls => same as clear
```
npm install react-terminal-plus
```
### New Shortcuts
OR
CTRL + C
CTRL + L
```
yarn add react-terminal-plus
```
### Required to launch
OR
- Cancel command shortcut (or at least button)
```
pnpm i react-terminal-plus
```
### To Look At
## Usage
- blinking cursor (maybe too fast)
- look into colors highlights
- a way to copy everything
- save buffer to local-storage
```tsx
import { TerminalContextProvider, ReactTerminal } from "react-terminal-plus";
### Portal Stuff
function App(props) {
// Define commands here
const commands = {
whoami: "jackharper",
cd: (directory) => `changed path to ${directory}`,
};
- allow eval on portal - iframe isolate?
- connection state info
- firewall rules
return (
<TerminalContextProvider>
<ReactTerminal commands={commands} />
</TerminalContextProvider>
);
}
```
### Timeline 4 weeks / 5 June - 2 July
## Creating custom themes
week 1/2
The component comes with few in-built themes: `light`, `dark`, `material-light`, `material-dark`, `material-ocean`, `matrix` and `dracula`. You can also create custom themes by passing `themes` parameter in props, as follows:
1. Implement "cancel running command" shortcut => Ctrl + C
1. Add `cls` command => same as clear
1. Allow eval on portal - iframe isolate?
1. Hide Mongo Terminal it behind employee flag for internal testing
```
<ReactTerminal
commands={commands}
themes={{
"my-custom-theme": {
themeBGColor: "#272B36",
themeToolbarColor: "#DBDBDB",
themeColor: "#FFFEFC",
themePromptColor: "#a917a8"
}
}}
theme="my-custom-theme"
/>
```
---
## Props
week 3/4 (if time permits)
| name | description | default |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| `welcomeMessage` | A welcome message to show at the start, before the prompt begins. Value can be either a string or JSX | null |
| `prompt` | Terminal prompt | >>> |
| `commands` | List of commands to be provided as a key value pair where value can be either a string, JSX/HTML tag or callback | null |
| `errorMessage` | Message to show when unidentified command executed, can be either a string, JSX/HTML tag or callback | "not found!" |
| `enableInput` | Whether to enable user input | true |
| `showControlBar` | Whether to show the top control bar | true |
| `showControlButtons` | Whether to show the control buttons at the top bar of the terminal | true |
| `theme` | Theme of the terminal | "light" |
| `themes` | Themes object to supply custom themes | null |
| `defaultHandler` | Default handler to be used (if provided) when no commands match. Useful when you don't know list of commands beforehand/want to send them to server for handling. | null |
1. a way to copy everything
1. save buffer to local-storage
1. apply colors highlights
## In-built commands
## Terminal Features
| command | description |
| ------- | ------------------ |
| clear | clears the console |
| cls | clears the console |
- [X]: Copy Pasting through keyboard - Ctrl+c/Ctrl+V
- [X]: Copy Pasting through browser's context menu - Right Click
- [X]: Cancel running command with Ctrl+C
- [X]: Clear terminal with Ctrl+L
- [X]: Add `cls` command to clear terminal
- [X]: Localstorage support for commands history
## In-built shortcuts
## Mongo Shell in Portal - Missing Features
| shortcut | description |
| -------- | ----------------------------------------------------------- |
| ctrl + c | copy OR cancel running command if there is no selected text |
| ctrl + v | paste |
| ctrl + l | clear the console |
- [X]: Talk with Francisco about the portal's security concerns
- [X]: Bug showing the connected database - urgent
- [X]: colors/font-size/line-height - urgent
- [X]: Terminal background color - talk with Design
- [X]: Integrate into the tutorial?? - later
- [1]: Blocklist commands - [window, ...]
- [2]: Only show mongo shell if there are workspaces with KAI enabled - let's hide for now
- [3]: Look at analytics
- [2]: Look at firewall rules - try
- [2]: Talk with Design about including a "don't copy paste" warning - later
- []: ???
## Development
See [`.github/CONTRIBUTING.md`](./.github/CONTRIBUTING.md), then [`.github/DEVELOPMENT.md`](./.github/DEVELOPMENT.md).
Thanks! ๐Ÿ’ช
## Credits
This repository resulted from a [`react-terminal`](https://github.com/bony2023/react-terminal) fork, and as such we would like to thank all its contributors for creating such an amazing piece of OS software. ๐Ÿ’–

Sorry, the diff of this file is not supported yet