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.6

dist/src/common/Commands.d.ts

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

## 0.0.6 (1st August 2023)
### Fixes
- Fixed a bug regarding the command history not working properly when submitting the same command twice;
- Fixed a bug the "RESET_CARET" command, to that it also resets the current editor input
### Internal
- Replaced RTL integration tests with CCT ones
## 0.0.5 (30th June 2023)

@@ -2,0 +13,0 @@

2

dist/components/Terminal.d.ts
import * as React from "react";
type TerminalMessage = string | React.ReactNode | Function;
type TerminalProps = {
export type TerminalProps = {
enableInput?: boolean;

@@ -5,0 +5,0 @@ caret?: boolean;

@@ -0,3 +1,5 @@

import * as React from "react";
import { TerminalContextProvider as _TerminalContextProvider } from "./contexts/TerminalContext";
export declare function ReactTerminal(props: any): any;
import type { TerminalProps } from "./components/Terminal";
export declare function ReactTerminal(props: TerminalProps): React.JSX.Element;
export declare const TerminalContextProvider: typeof _TerminalContextProvider;

@@ -4,0 +6,0 @@ declare const _default: {

@@ -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 i(e){try{c(r.next(e))}catch(e){a(e)}}function l(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(i,l)}c((r=r.apply(e,t||[])).next())}))}function o(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(l){return function(c){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,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_terminalContainer__4seT6 {\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_controls__sXDjs {\n text-align: left;\n height: 26px;\n position: relative;\n top: 4px;\n margin-left: 4px;\n}\n.index_controls__sXDjs .index_consoleCtrl__DI2H1 {\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_controls__sXDjs .index_close__XGN9U {\n background: var(--control-close-bg-color);\n}\n.index_controls__sXDjs .index_minimize__pZYTU {\n background: var(--control-minimize-bg-color);\n}\n.index_controls__sXDjs .index_maximize__szRK7 {\n background: var(--control-maximize-bg-color);\n}\n\n.index_editor__JoDSg {\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 border-bottom-left-radius: 5px;\n border-bottom-right-radius: 5px;\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_editor__JoDSg:focus, .index_editor__JoDSg:hover {\n --scroll-bar-thumb-color: rgb(211 211 211 / 40%);\n}\n.index_editor__JoDSg::-webkit-scrollbar {\n width: var(--scroll-bar-width);\n}\n.index_editor__JoDSg::-webkit-scrollbar-track {\n background-color: var(--scroll-bar-track-color);\n}\n.index_editor__JoDSg::-webkit-scrollbar-thumb {\n background-color: var(--scroll-bar-thumb-color);\n}\n.index_editor__JoDSg .index_lineText__j6qNj {\n display: inline;\n position: relative;\n top: -1px;\n margin-left: 8px;\n}\n.index_editor__JoDSg .index_preWhiteSpace__7KwuG {\n white-space: pre-wrap;\n}\n.index_editor__JoDSg .index_caret__VS4iV {\n position: relative;\n}\n.index_editor__JoDSg .index_caret__VS4iV .index_caretAfter__6aXPx {\n content: "";\n position: absolute;\n top: 2px;\n width: 10px;\n height: 22px;\n z-index: 10;\n}\n@-moz-keyframes index_blink__FJp0- {\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_blink__FJp0- {\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_blink__FJp0- {\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_blink__FJp0- {\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_editor__JoDSg a {\n color: #1a87b5;\n}\n\n.index_editorWithTopBar__L6XKw {\n height: calc(100% - 46px);\n}\n\n.index_curvedTop__LX9XS {\n border-top-left-radius: 5px;\n border-top-right-radius: 5px;\n}\n\n#index_terminalContainer__4seT6 {\n height: 100%;\n}\n\n.index_terminal__teubZ {\n height: 100%;\n width: 100%;\n margin: auto;\n border-radius: 5px;\n}');var a={terminalContainer:"index_terminalContainer__4seT6",controls:"index_controls__sXDjs",consoleCtrl:"index_consoleCtrl__DI2H1",close:"index_close__XGN9U",minimize:"index_minimize__pZYTU",maximize:"index_maximize__szRK7",editor:"index_editor__JoDSg",lineText:"index_lineText__j6qNj",preWhiteSpace:"index_preWhiteSpace__7KwuG",caret:"index_caret__VS4iV",caretAfter:"index_caretAfter__6aXPx",editorWithTopBar:"index_editorWithTopBar__L6XKw",curvedTop:"index_curvedTop__LX9XS",terminal:"index_terminal__teubZ",blink:"index_blink__FJp0-"},i=e.createContext(null),l=function(t){var n=t.children;return e.createElement(i.Provider,{value:a},n)},c={dark:{themeBGColor:"#022833",themeToolbarColor:"#131519",themeColor:"#839496",themePromptColor:"#a917a8"},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"}},s=e.createContext(null),u=function(t){var r=t.children,o=n(n({},c),r.props.themes||{}),a=o[r.props.theme]||o.light;return e.createElement(s.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(i),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 p=["clear","cls"],f=function(e){return p.includes(e)},h=function(){function e(){}return e.splitStringAtIndex=function(e,t){return e?[e.substring(0,t),e.substring(t)]:["",""]},e}(),x=e.createContext(null);function _(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=e.commandsHistory;return r&&r!==o[o.length-1]&&o.push(r),f(r)?n(n({},e),{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=C(e),i=a[0],l=a[1],c=b(_=i+t.text+l,v=e.caretPosition+1),s=c[0],u=c[1];return n(n({},e),{caretPosition:v,editorInput:_,textAfterCaret:u,textBeforeCaret:s});case"DELETE":var d=C(e),m=(i=d[0],l=d[1],b(_=i.slice(0,-1)+l,v=e.caretPosition-1));s=m[0],u=m[1];return n(n({},e),{editorInput:_,caretPosition:v,textAfterCaret:u,textBeforeCaret:s});case"COPY":return e;case"PASTE":var p=C(e),h=(i=p[0],l=p[1],b(_=i+t.text+l,v=e.caretPosition+t.text.length));s=h[0],u=h[1];return n(n({},e),{editorInput:_,caretPosition:v,textAfterCaret:u,textBeforeCaret:s});case"ARROW_UP":var x=b(_=t.previousCommand,v=t.previousCommand.length);s=x[0],u=x[1];return n(n({},e),{editorInput:_,caretPosition:v,textAfterCaret:u,textBeforeCaret:s});case"ARROW_DOWN":var _,g=b(_=t.nextCommand,v=t.nextCommand.length);s=g[0],u=g[1];return n(n({},e),{editorInput:_,caretPosition:v,textAfterCaret:u,textBeforeCaret:s});case"RESET_CARET_POSITION":return n(n({},e),{textBeforeCaret:"",textAfterCaret:"",caretPosition:0});case"ARROW_LEFT":var v=e.caretPosition-1,y=b(e.editorInput,v);s=y[0],u=y[1];return n(n({},e),{caretPosition:v,textAfterCaret:u,textBeforeCaret:s});case"ARROW_RIGHT":v=e.caretPosition+1;var E=b(e.editorInput,v);s=E[0],u=E[1];return n(n({},e),{caretPosition:v,textAfterCaret:u,textBeforeCaret:s});default:throw new Error("Unhandled action type: ".concat(JSON.stringify(t)))}default:return e}}function C(e){var t=h.splitStringAtIndex(e.editorInput,e.caretPosition);return[t[0],t[1]]}function b(e,t){var n=h.splitStringAtIndex(e,t);return[n[0],n[1]]}var g={bufferedContent:null,commandsHistory:[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""};function v(){var t=e.useContext(x);if(void 0===t)throw new Error("useTerminal must be used within a TerminalContextProvider");return t}var y=function(n,a,l,c,u,d,m){var p=e.useContext(i),h=e.useContext(s),x=v().store,_="processing"!==x.currentLineStatus?e.createElement(e.Fragment,null,e.createElement("span",{style:{color:h.themePromptColor}},l),e.createElement("div",{className:p.lineText},e.createElement("span",{className:p.preWhiteSpace},x.textBeforeCaret),a&&n?e.createElement("span",{className:p.caret},e.createElement("span",{className:p.caretAfter,style:{background:h.themeColor}})):null,e.createElement("span",{className:p.preWhiteSpace},x.textAfterCaret))):e.createElement(e.Fragment,null,e.createElement("div",{className:p.lineText},a&&n?e.createElement("span",{className:p.caret},e.createElement("span",{className:p.caretAfter,style:{background:h.themeColor}})):null));return function(n){var a=n.consoleFocused,l=n.enableInput,c=n.commands,u=n.defaultHandler,d=n.errorMessage,m=n.prompt,p=e.useContext(i),h=e.useContext(s),x=v(),_=x.getPreviousCommand,C=x.getNextCommand,b=x.store,g=x.send,y=e.useRef(null),E=e.useCallback((function(){y.current&&y.current.cancel();var t=e.createElement(e.Fragment,null,b.bufferedContent,e.createElement("span",{style:{color:h.themePromptColor}},m),e.createElement("span",{className:"".concat(p.lineText," ").concat(p.preWhiteSpace)},b.editorInput),e.createElement("br",null));"processing"===b.currentLineStatus&&(t=e.createElement(e.Fragment,null,b.bufferedContent)),g({type:"CANCEL",cancelNode:t})}),[m,g,b.bufferedContent,b.currentLineStatus,b.editorInput,p.lineText,p.preWhiteSpace,h.themePromptColor]),w=e.useCallback((function(){return r(void 0,void 0,void 0,(function(){var n,r,a,i,l,s,x,_,C;return o(this,(function(o){switch(o.label){case 0:return n=b.editorInput.trim().split(" "),r=n[0],a=n.slice(1),i=b.editorInput.trim(),l="",s=e.createElement(e.Fragment,null,b.bufferedContent,e.createElement("span",{style:{color:h.themePromptColor}},m),e.createElement("span",{className:"".concat(p.lineText," ").concat(p.preWhiteSpace)},b.editorInput),e.createElement("br",null)),g({type:"SUBMIT",loaderNode:s,command:i}),f(i)?[2]:b.editorInput?(x=a.join(" "),i&&c[i]?"function"!=typeof(_=c[i])?[3,2]:(y.current=new t((function(e){e(_(x))})),[4,y.current]):[3,4]):[3,9];case 1:return l=o.sent(),[3,3];case 2:l=_,o.label=3;case 3:return[3,9];case 4:return"function"!=typeof u?[3,6]:(y.current=new t((function(e){e(u(r,x))})),[4,y.current]);case 5:return l=o.sent(),[3,9];case 6:return"function"!=typeof d?[3,8]:(y.current=new t((function(e){e(d(r,x))})),[4,y.current]);case 7:return l=o.sent(),[3,9];case 8:l=d,o.label=9;case 9:return C=e.createElement(e.Fragment,null,b.bufferedContent,e.createElement("span",{style:{color:h.themePromptColor}},m),e.createElement("span",{className:"".concat(p.lineText," ").concat(p.preWhiteSpace)},b.editorInput),l?e.createElement("span",null,e.createElement("br",null),l):null,e.createElement("br",null)),g({type:"SUBMIT_SUCCESS",successNode:C}),[2]}}))}))}),[g,b.bufferedContent,b.editorInput]),S=e.useCallback((function(e){if(a&&l){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&&g({type:"DELETE"});else if("ArrowUp"===t)(n=_())&&g({type:"ARROW_UP",previousCommand:n});else if("ArrowDown"===t)n=C(),g(n?{type:"ARROW_DOWN",nextCommand:n}:{type:"RESET_CARET_POSITION"});else if("ArrowLeft"===t)b.caretPosition>0&&g({type:"ARROW_LEFT"}),n=b.editorInput;else if("ArrowRight"===t)b.caretPosition<b.editorInput.length&&g({type:"ARROW_RIGHT"}),n=b.editorInput;else if((e.metaKey||e.ctrlKey)&&"l"===t.toLowerCase())g({type:"CLEAR"});else if((e.metaKey||e.ctrlKey)&&e.shiftKey&&"v"===t.toLowerCase())navigator.clipboard.readText().then((function(e){g({type:"PASTE",text:e})}));else if((e.metaKey||e.ctrlKey)&&e.shiftKey&&"c"===t.toLowerCase()){var r=window.getSelection().toString();navigator.clipboard.writeText(r).then((function(){g({type:"COPY"})}))}else(e.metaKey||e.ctrlKey)&&"c"===t.toLowerCase()?(y.current&&y.current.cancel(),E()):t&&1===t.length&&g({type:"TYPE",text:t})}}),[E,a,l,C,_,w,g,b.caretPosition,b.currentLineStatus,b.editorInput]);e.useEffect((function(){return document.addEventListener("keydown",S),function(){document.removeEventListener("keydown",S)}}),[S])}({commands:c,errorMessage:u,defaultHandler:m,enableInput:d,prompt:l,consoleFocused:a}),_},E=function(t,n){e.useEffect((function(){n.current&&(n.current.scrollTop=n.current.scrollHeight)}),[t])};function w(t){var n=e.useRef(null),r=e.useContext(i),o=e.useContext(s),a=v().store;E(a.bufferedContent,n);var l=t.enableInput,c=t.caret,u=t.consoleFocused,d=t.prompt,m=t.commands,p=t.welcomeMessage,f=t.errorMessage,h=t.showControlBar,x=t.defaultHandler,_=y(c,u,d,m,f,l,x);return e.createElement("div",{id:"terminalEditor",tabIndex:0,ref:n,className:"".concat(r.editor," ").concat(h?null:r.curvedTop," ").concat(h?r.editorWithTopBar:null),style:{background:o.themeBGColor}},p,a.bufferedContent,_)}function S(t){var n=e.useRef(null),r=e.useState(!0),o=r[0],a=r[1],l=e.useContext(i),c=e.useContext(s);d(n,o,a);var u=t.caret,p=void 0===u||u,f=t.theme,h=void 0===f?"light":f,x=t.showControlBar,_=void 0===x||x,C=t.showControlButtons,b=void 0===C||C,g=t.controlButtonLabels,v=void 0===g?["close","minimize","maximize"]:g,y=t.prompt,E=void 0===y?">>>":y,S=t.commands,T=void 0===S?{}:S,P=t.welcomeMessage,I=void 0===P?"":P,A=t.errorMessage,B=void 0===A?"not found!":A,k=t.enableInput,N=void 0===k||k,L=t.defaultHandler,D=void 0===L?null:L,R=_?e.createElement(m,{consoleFocused:o,showControlButtons:b,controlButtonLabels:v}):null,F=e.createElement(w,{caret:p,consoleFocused:o,prompt:E,commands:T,welcomeMessage:I,errorMessage:B,enableInput:N,showControlBar:_,defaultHandler:D});return e.createElement("div",{ref:n,id:l.terminalContainer,className:l["theme--".concat(h)],"data-testid":"terminal"},e.createElement("div",{className:"".concat(l.terminal),style:{background:c.themeToolbarColor,color:c.themeColor}},R,F))}function T(t){var n=t.children;return e.createElement(l,null,e.createElement(u,null,n))}function P(t){return e.createElement(T,null,e.createElement(S,n({},t)))}var I=function(t){var n=t.children,r=e.useState(null),o=r[0],a=r[1],i=e.useReducer(_,g),l=i[0],c=i[1];e.useEffect((function(){a(l.commandsHistory.length)}),[l.commandsHistory.length]);var s=e.useMemo((function(){return{send:c,store:l,getPreviousCommand:function(){if(0===o)return 0===l.commandsHistory.length?"":l.commandsHistory[0];var e=l.commandsHistory[o-1];return o>0&&a(o-1),e},getNextCommand:function(){if(o+1<=l.commandsHistory.length){var e=l.commandsHistory[o+1];return a(o+1),e}return""}}}),[o,l]);return e.createElement(x.Provider,{value:s},n)},A={ReactTerminal:P,TerminalContextProvider:I};export{P as ReactTerminal,I as TerminalContextProvider,A as default};
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 border-bottom-left-radius: 5px;\n border-bottom-right-radius: 5px;\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__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_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_curvedTop__vzisj {\n border-top-left-radius: 5px;\n border-top-right-radius: 5px;\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 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",lineText:"index-module_lineText__avQ48",preWhiteSpace:"index-module_preWhiteSpace__v4IYf",caret:"index-module_caret__YobLn",caretAfter:"index-module_caretAfter__SMMlh",editorWithTopBar:"index-module_editorWithTopBar__opXWp",curvedTop:"index-module_curvedTop__vzisj",terminal:"index-module_terminal__EWHbJ",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:"#022833",themeToolbarColor:"#131519",themeColor:"#839496",themePromptColor:"#a917a8"},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}(),h=e.createContext(null);function _(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),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=x(e),l=a[0],i=a[1],c=b(_=l+t.text+i,y=e.caretPosition+1),u=c[0],s=c[1];return n(n({},e),{caretPosition:y,editorInput:_,textAfterCaret:s,textBeforeCaret:u});case"DELETE":var d=x(e),m=(l=d[0],i=d[1],b(_=l.slice(0,-1)+i,y=e.caretPosition-1));u=m[0],s=m[1];return n(n({},e),{editorInput:_,caretPosition:y,textAfterCaret:s,textBeforeCaret:u});case"COPY":return e;case"PASTE":var f=x(e),C=(l=f[0],i=f[1],b(_=l+t.text+i,y=e.caretPosition+t.text.length));u=C[0],s=C[1];return n(n({},e),{editorInput:_,caretPosition:y,textAfterCaret:s,textBeforeCaret:u});case"ARROW_UP":var h=b(_=t.previousCommand,y=t.previousCommand.length);u=h[0],s=h[1];return n(n({},e),{editorInput:_,caretPosition:y,textAfterCaret:s,textBeforeCaret:u});case"ARROW_DOWN":var _,v=b(_=t.nextCommand,y=t.nextCommand.length);u=v[0],s=v[1];return n(n({},e),{editorInput:_,caretPosition:y,textAfterCaret:s,textBeforeCaret:u});case"RESET_CARET_POSITION":return n(n({},e),{editorInput:"",textBeforeCaret:"",textAfterCaret:"",caretPosition:0});case"ARROW_LEFT":var y=e.caretPosition-1,g=b(e.editorInput,y);u=g[0],s=g[1];return n(n({},e),{caretPosition:y,textAfterCaret:s,textBeforeCaret:u});case"ARROW_RIGHT":y=e.caretPosition+1;var E=b(e.editorInput,y);u=E[0],s=E[1];return n(n({},e),{caretPosition:y,textAfterCaret:s,textBeforeCaret:u});default:throw new Error("Unhandled action type: ".concat(JSON.stringify(t)))}default:return e}}function x(e){var t=C.splitStringAtIndex(e.editorInput,e.caretPosition);return[t[0],t[1]]}function b(e,t){var n=C.splitStringAtIndex(e,t);return[n[0],n[1]]}var v={bufferedContent:null,commandsHistory:[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""};function y(){var t=e.useContext(h);if(void 0===t)throw new Error("useTerminal must be used within a TerminalContextProvider");return t}var g=function(n,a,i,c,s,d,m){var f=e.useContext(l),C=e.useContext(u),h=y().store,_="processing"!==h.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},h.textBeforeCaret),a&&n?e.createElement("span",{className:f.caret},e.createElement("span",{className:f.caretAfter,style:{background:C.themeColor}})):null,e.createElement("span",{className:f.preWhiteSpace},h.textAfterCaret))):e.createElement(e.Fragment,null,e.createElement("div",{className:f.lineText},a&&n?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),h=y(),_=h.getPreviousCommand,x=h.getNextCommand,b=h.store,v=h.send,g=e.useRef(null),E=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?(h=a.join(" "),l&&c[l]?"function"!=typeof(_=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=_,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,h))})),[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,h))})),[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=_())&&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)&&e.shiftKey&&"v"===t.toLowerCase())navigator.clipboard.readText().then((function(e){v({type:"PASTE",text:e})}));else if((e.metaKey||e.ctrlKey)&&e.shiftKey&&"c"===t.toLowerCase()){var r=window.getSelection().toString();navigator.clipboard.writeText(r).then((function(){v({type:"COPY"})}))}else(e.metaKey||e.ctrlKey)&&"c"===t.toLowerCase()?(g.current&&g.current.cancel(),E()):t&&1===t.length&&v({type:"TYPE",text:t})}}),[E,a,i,x,_,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}),_},E=function(t,n){e.useEffect((function(){n.current&&(n.current.scrollTop=n.current.scrollHeight)}),[t])};function w(t){var n=e.useRef(null),r=e.useContext(l),o=e.useContext(u),a=y().store;E(a.bufferedContent,n);var i=t.enableInput,c=t.caret,s=t.consoleFocused,d=t.prompt,m=t.commands,f=t.welcomeMessage,p=t.errorMessage,C=t.showControlBar,h=t.defaultHandler,_=g(c,s,d,m,p,i,h);return e.createElement("div",{id:"terminalEditor",tabIndex:0,ref:n,className:"".concat(r.editor," ").concat(C?null:r.curvedTop," ").concat(C?r.editorWithTopBar:null),style:{background:o.themeBGColor}},f,a.bufferedContent,_)}function P(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,h=t.showControlBar,_=void 0===h||h,x=t.showControlButtons,b=void 0===x||x,v=t.controlButtonLabels,y=void 0===v?["close","minimize","maximize"]:v,g=t.prompt,E=void 0===g?">>>":g,P=t.commands,T=void 0===P?{}:P,B=t.welcomeMessage,I=void 0===B?"":B,S=t.errorMessage,A=void 0===S?"not found!":S,k=t.enableInput,L=void 0===k||k,N=t.defaultHandler,F=void 0===N?null:N,R=_?e.createElement(m,{consoleFocused:o,showControlButtons:b,controlButtonLabels:y}):null,D=e.createElement(w,{caret:f,consoleFocused:o,prompt:E,commands:T,welcomeMessage:I,errorMessage:A,enableInput:L,showControlBar:_,defaultHandler:F});return e.createElement("div",{ref:n,id:i.terminalContainer,className:i["theme--".concat(C)],"data-testid":"terminal"},e.createElement("div",{className:"".concat(i.terminal),style:{background:c.themeToolbarColor,color:c.themeColor}},R,D))}function T(t){var n=t.children;return e.createElement(i,null,e.createElement(s,null,n))}function B(t){return e.createElement(T,null,e.createElement(P,n({},t)))}var I=function(t){var n=t.children,r=e.useState(null),o=r[0],a=r[1],l=e.useReducer(_,v),i=l[0],c=l[1],u=e.useCallback((function(e){"SUBMIT"===e.type&&a(i.commandsHistory.length),c(e)}),[i.commandsHistory.length]);e.useEffect((function(){a(i.commandsHistory.length)}),[i.commandsHistory.length]);var s=e.useMemo((function(){return{send:u,store:i,getPreviousCommand:function(){if(0===o)return 0===i.commandsHistory.length?"":i.commandsHistory[0];var e=i.commandsHistory[o-1];return o>0&&a(o-1),e},getNextCommand:function(){if(o+1<=i.commandsHistory.length){var e=i.commandsHistory[o+1];return a(o+1),e}return""}}}),[o,u,i]);return e.createElement(h.Provider,{value:s},n)},S={ReactTerminal:B,TerminalContextProvider:I};export{B as ReactTerminal,I as TerminalContextProvider,S 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 i(e){try{c(r.next(e))}catch(e){a(e)}}function l(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(i,l)}c((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(l){return function(c){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,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_terminalContainer__4seT6 {\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_controls__sXDjs {\n text-align: left;\n height: 26px;\n position: relative;\n top: 4px;\n margin-left: 4px;\n}\n.index_controls__sXDjs .index_consoleCtrl__DI2H1 {\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_controls__sXDjs .index_close__XGN9U {\n background: var(--control-close-bg-color);\n}\n.index_controls__sXDjs .index_minimize__pZYTU {\n background: var(--control-minimize-bg-color);\n}\n.index_controls__sXDjs .index_maximize__szRK7 {\n background: var(--control-maximize-bg-color);\n}\n\n.index_editor__JoDSg {\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 border-bottom-left-radius: 5px;\n border-bottom-right-radius: 5px;\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_editor__JoDSg:focus, .index_editor__JoDSg:hover {\n --scroll-bar-thumb-color: rgb(211 211 211 / 40%);\n}\n.index_editor__JoDSg::-webkit-scrollbar {\n width: var(--scroll-bar-width);\n}\n.index_editor__JoDSg::-webkit-scrollbar-track {\n background-color: var(--scroll-bar-track-color);\n}\n.index_editor__JoDSg::-webkit-scrollbar-thumb {\n background-color: var(--scroll-bar-thumb-color);\n}\n.index_editor__JoDSg .index_lineText__j6qNj {\n display: inline;\n position: relative;\n top: -1px;\n margin-left: 8px;\n}\n.index_editor__JoDSg .index_preWhiteSpace__7KwuG {\n white-space: pre-wrap;\n}\n.index_editor__JoDSg .index_caret__VS4iV {\n position: relative;\n}\n.index_editor__JoDSg .index_caret__VS4iV .index_caretAfter__6aXPx {\n content: "";\n position: absolute;\n top: 2px;\n width: 10px;\n height: 22px;\n z-index: 10;\n}\n@-moz-keyframes index_blink__FJp0- {\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_blink__FJp0- {\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_blink__FJp0- {\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_blink__FJp0- {\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_editor__JoDSg a {\n color: #1a87b5;\n}\n\n.index_editorWithTopBar__L6XKw {\n height: calc(100% - 46px);\n}\n\n.index_curvedTop__LX9XS {\n border-top-left-radius: 5px;\n border-top-right-radius: 5px;\n}\n\n#index_terminalContainer__4seT6 {\n height: 100%;\n}\n\n.index_terminal__teubZ {\n height: 100%;\n width: 100%;\n margin: auto;\n border-radius: 5px;\n}');var l={terminalContainer:"index_terminalContainer__4seT6",controls:"index_controls__sXDjs",consoleCtrl:"index_consoleCtrl__DI2H1",close:"index_close__XGN9U",minimize:"index_minimize__pZYTU",maximize:"index_maximize__szRK7",editor:"index_editor__JoDSg",lineText:"index_lineText__j6qNj",preWhiteSpace:"index_preWhiteSpace__7KwuG",caret:"index_caret__VS4iV",caretAfter:"index_caretAfter__6aXPx",editorWithTopBar:"index_editorWithTopBar__L6XKw",curvedTop:"index_curvedTop__LX9XS",terminal:"index_terminal__teubZ",blink:"index_blink__FJp0-"},c=r.createContext(null),s=function(e){var t=e.children;return r.createElement(c.Provider,{value:l},t)},u={dark:{themeBGColor:"#022833",themeToolbarColor:"#131519",themeColor:"#839496",themePromptColor:"#a917a8"},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({},u),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 x=["clear","cls"],h=function(e){return x.includes(e)},_=function(){function e(){}return e.splitStringAtIndex=function(e,t){return e?[e.substring(0,t),e.substring(t)]:["",""]},e}(),C=r.createContext(null);function b(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=e.commandsHistory;return n&&n!==r[r.length-1]&&r.push(n),h(n)?o(o({},e),{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=g(e),i=a[0],l=a[1],c=v(_=i+t.text+l,b=e.caretPosition+1),s=c[0],u=c[1];return o(o({},e),{caretPosition:b,editorInput:_,textAfterCaret:u,textBeforeCaret:s});case"DELETE":var d=g(e),m=(i=d[0],l=d[1],v(_=i.slice(0,-1)+l,b=e.caretPosition-1));s=m[0],u=m[1];return o(o({},e),{editorInput:_,caretPosition:b,textAfterCaret:u,textBeforeCaret:s});case"COPY":return e;case"PASTE":var f=g(e),p=(i=f[0],l=f[1],v(_=i+t.text+l,b=e.caretPosition+t.text.length));s=p[0],u=p[1];return o(o({},e),{editorInput:_,caretPosition:b,textAfterCaret:u,textBeforeCaret:s});case"ARROW_UP":var x=v(_=t.previousCommand,b=t.previousCommand.length);s=x[0],u=x[1];return o(o({},e),{editorInput:_,caretPosition:b,textAfterCaret:u,textBeforeCaret:s});case"ARROW_DOWN":var _,C=v(_=t.nextCommand,b=t.nextCommand.length);s=C[0],u=C[1];return o(o({},e),{editorInput:_,caretPosition:b,textAfterCaret:u,textBeforeCaret:s});case"RESET_CARET_POSITION":return o(o({},e),{textBeforeCaret:"",textAfterCaret:"",caretPosition:0});case"ARROW_LEFT":var b=e.caretPosition-1,y=v(e.editorInput,b);s=y[0],u=y[1];return o(o({},e),{caretPosition:b,textAfterCaret:u,textBeforeCaret:s});case"ARROW_RIGHT":b=e.caretPosition+1;var E=v(e.editorInput,b);s=E[0],u=E[1];return o(o({},e),{caretPosition:b,textAfterCaret:u,textBeforeCaret:s});default:throw new Error("Unhandled action type: ".concat(JSON.stringify(t)))}default:return e}}function g(e){var t=_.splitStringAtIndex(e.editorInput,e.caretPosition);return[t[0],t[1]]}function v(e,t){var n=_.splitStringAtIndex(e,t);return[n[0],n[1]]}var y={bufferedContent:null,commandsHistory:[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""};function E(){var e=r.useContext(C);if(void 0===e)throw new Error("useTerminal must be used within a TerminalContextProvider");return e}var w=function(e,n,o,l,s,u,m){var f=r.useContext(c),p=r.useContext(d),x=E().store,_="processing"!==x.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},x.textBeforeCaret),n&&e?r.createElement("span",{className:f.caret},r.createElement("span",{className:f.caretAfter,style:{background:p.themeColor}})):null,r.createElement("span",{className:f.preWhiteSpace},x.textAfterCaret))):r.createElement(r.Fragment,null,r.createElement("div",{className:f.lineText},n&&e?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,l=e.commands,s=e.defaultHandler,u=e.errorMessage,m=e.prompt,f=r.useContext(c),p=r.useContext(d),x=E(),_=x.getPreviousCommand,C=x.getNextCommand,b=x.store,g=x.send,v=r.useRef(null),y=r.useCallback((function(){v.current&&v.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)),g({type:"CANCEL",cancelNode:e})}),[m,g,b.bufferedContent,b.currentLineStatus,b.editorInput,f.lineText,f.preWhiteSpace,p.themePromptColor]),w=r.useCallback((function(){return a(void 0,void 0,void 0,(function(){var e,n,o,a,c,d,x,_,C;return i(this,(function(i){switch(i.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)),g({type:"SUBMIT",loaderNode:d,command:a}),h(a)?[2]:b.editorInput?(x=o.join(" "),a&&l[a]?"function"!=typeof(_=l[a])?[3,2]:(v.current=new t.CancelablePromise((function(e){e(_(x))})),[4,v.current]):[3,4]):[3,9];case 1:return c=i.sent(),[3,3];case 2:c=_,i.label=3;case 3:return[3,9];case 4:return"function"!=typeof s?[3,6]:(v.current=new t.CancelablePromise((function(e){e(s(n,x))})),[4,v.current]);case 5:return c=i.sent(),[3,9];case 6:return"function"!=typeof u?[3,8]:(v.current=new t.CancelablePromise((function(e){e(u(n,x))})),[4,v.current]);case 7:return c=i.sent(),[3,9];case 8:c=u,i.label=9;case 9:return C=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)),g({type:"SUBMIT_SUCCESS",successNode:C}),[2]}}))}))}),[g,b.bufferedContent,b.editorInput]),S=r.useCallback((function(e){if(n&&o){e.preventDefault();var t=e.key,r=null;if("Enter"===t)"processing"!==b.currentLineStatus&&w();else if("Backspace"===t)b.editorInput&&0!==b.editorInput.length&&g({type:"DELETE"});else if("ArrowUp"===t)(r=_())&&g({type:"ARROW_UP",previousCommand:r});else if("ArrowDown"===t)r=C(),g(r?{type:"ARROW_DOWN",nextCommand:r}:{type:"RESET_CARET_POSITION"});else if("ArrowLeft"===t)b.caretPosition>0&&g({type:"ARROW_LEFT"}),r=b.editorInput;else if("ArrowRight"===t)b.caretPosition<b.editorInput.length&&g({type:"ARROW_RIGHT"}),r=b.editorInput;else if((e.metaKey||e.ctrlKey)&&"l"===t.toLowerCase())g({type:"CLEAR"});else if((e.metaKey||e.ctrlKey)&&e.shiftKey&&"v"===t.toLowerCase())navigator.clipboard.readText().then((function(e){g({type:"PASTE",text:e})}));else if((e.metaKey||e.ctrlKey)&&e.shiftKey&&"c"===t.toLowerCase()){var a=window.getSelection().toString();navigator.clipboard.writeText(a).then((function(){g({type:"COPY"})}))}else(e.metaKey||e.ctrlKey)&&"c"===t.toLowerCase()?(v.current&&v.current.cancel(),y()):t&&1===t.length&&g({type:"TYPE",text:t})}}),[y,n,o,C,_,w,g,b.caretPosition,b.currentLineStatus,b.editorInput]);r.useEffect((function(){return document.addEventListener("keydown",S),function(){document.removeEventListener("keydown",S)}}),[S])}({commands:l,errorMessage:s,defaultHandler:m,enableInput:u,prompt:o,consoleFocused:n}),_},S=function(e,t){r.useEffect((function(){t.current&&(t.current.scrollTop=t.current.scrollHeight)}),[e])};function T(e){var t=r.useRef(null),n=r.useContext(c),o=r.useContext(d),a=E().store;S(a.bufferedContent,t);var i=e.enableInput,l=e.caret,s=e.consoleFocused,u=e.prompt,m=e.commands,f=e.welcomeMessage,p=e.errorMessage,x=e.showControlBar,h=e.defaultHandler,_=w(l,s,u,m,p,i,h);return r.createElement("div",{id:"terminalEditor",tabIndex:0,ref:t,className:"".concat(n.editor," ").concat(x?null:n.curvedTop," ").concat(x?n.editorWithTopBar:null),style:{background:o.themeBGColor}},f,a.bufferedContent,_)}function P(e){var t=r.useRef(null),n=r.useState(!0),o=n[0],a=n[1],i=r.useContext(c),l=r.useContext(d);f(t,o,a);var s=e.caret,u=void 0===s||s,m=e.theme,x=void 0===m?"light":m,h=e.showControlBar,_=void 0===h||h,C=e.showControlButtons,b=void 0===C||C,g=e.controlButtonLabels,v=void 0===g?["close","minimize","maximize"]:g,y=e.prompt,E=void 0===y?">>>":y,w=e.commands,S=void 0===w?{}:w,P=e.welcomeMessage,I=void 0===P?"":P,A=e.errorMessage,B=void 0===A?"not found!":A,k=e.enableInput,N=void 0===k||k,D=e.defaultHandler,L=void 0===D?null:D,R=_?r.createElement(p,{consoleFocused:o,showControlButtons:b,controlButtonLabels:v}):null,O=r.createElement(T,{caret:u,consoleFocused:o,prompt:E,commands:S,welcomeMessage:I,errorMessage:B,enableInput:N,showControlBar:_,defaultHandler:L});return r.createElement("div",{ref:t,id:i.terminalContainer,className:i["theme--".concat(x)],"data-testid":"terminal"},r.createElement("div",{className:"".concat(i.terminal),style:{background:l.themeToolbarColor,color:l.themeColor}},R,O))}function I(e){var t=e.children;return r.createElement(s,null,r.createElement(m,null,t))}function A(e){return r.createElement(I,null,r.createElement(P,o({},e)))}var B=function(e){var t=e.children,n=r.useState(null),o=n[0],a=n[1],i=r.useReducer(b,y),l=i[0],c=i[1];r.useEffect((function(){a(l.commandsHistory.length)}),[l.commandsHistory.length]);var s=r.useMemo((function(){return{send:c,store:l,getPreviousCommand:function(){if(0===o)return 0===l.commandsHistory.length?"":l.commandsHistory[0];var e=l.commandsHistory[o-1];return o>0&&a(o-1),e},getNextCommand:function(){if(o+1<=l.commandsHistory.length){var e=l.commandsHistory[o+1];return a(o+1),e}return""}}}),[o,l]);return r.createElement(C.Provider,{value:s},t)},k={ReactTerminal:A,TerminalContextProvider:B};exports.ReactTerminal=A,exports.TerminalContextProvider=B,exports.default=k;
"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 border-bottom-left-radius: 5px;\n border-bottom-right-radius: 5px;\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__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_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_curvedTop__vzisj {\n border-top-left-radius: 5px;\n border-top-right-radius: 5px;\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 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",lineText:"index-module_lineText__avQ48",preWhiteSpace:"index-module_preWhiteSpace__v4IYf",caret:"index-module_caret__YobLn",caretAfter:"index-module_caretAfter__SMMlh",editorWithTopBar:"index-module_editorWithTopBar__opXWp",curvedTop:"index-module_curvedTop__vzisj",terminal:"index-module_terminal__EWHbJ",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:"#022833",themeToolbarColor:"#131519",themeColor:"#839496",themePromptColor:"#a917a8"},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"],h=function(e){return C.includes(e)},x=function(){function e(){}return e.splitStringAtIndex=function(e,t){return e?[e.substring(0,t),e.substring(t)]:["",""]},e}(),_=r.createContext(null);function b(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),h(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=v(e),l=a[0],i=a[1],c=y(x=l+t.text+i,b=e.caretPosition+1),u=c[0],s=c[1];return o(o({},e),{caretPosition:b,editorInput:x,textAfterCaret:s,textBeforeCaret:u});case"DELETE":var d=v(e),m=(l=d[0],i=d[1],y(x=l.slice(0,-1)+i,b=e.caretPosition-1));u=m[0],s=m[1];return o(o({},e),{editorInput:x,caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"COPY":return e;case"PASTE":var f=v(e),p=(l=f[0],i=f[1],y(x=l+t.text+i,b=e.caretPosition+t.text.length));u=p[0],s=p[1];return o(o({},e),{editorInput:x,caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"ARROW_UP":var C=y(x=t.previousCommand,b=t.previousCommand.length);u=C[0],s=C[1];return o(o({},e),{editorInput:x,caretPosition:b,textAfterCaret:s,textBeforeCaret:u});case"ARROW_DOWN":var x,_=y(x=t.nextCommand,b=t.nextCommand.length);u=_[0],s=_[1];return o(o({},e),{editorInput:x,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=y(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 E=y(e.editorInput,b);u=E[0],s=E[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 v(e){var t=x.splitStringAtIndex(e.editorInput,e.caretPosition);return[t[0],t[1]]}function y(e,t){var n=x.splitStringAtIndex(e,t);return[n[0],n[1]]}var g={bufferedContent:null,commandsHistory:[],editorInput:"",currentLineStatus:"idle",caretPosition:0,textBeforeCaret:"",textAfterCaret:""};function E(){var e=r.useContext(_);if(void 0===e)throw new Error("useTerminal must be used within a TerminalContextProvider");return e}var P=function(e,n,o,i,u,s,m){var f=r.useContext(c),p=r.useContext(d),C=E().store,x="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),n&&e?r.createElement("span",{className:f.caret},r.createElement("span",{className:f.caretAfter,style:{background:p.themeColor}})):null,r.createElement("span",{className:f.preWhiteSpace},C.textAfterCaret))):r.createElement(r.Fragment,null,r.createElement("div",{className:f.lineText},n&&e?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=E(),x=C.getPreviousCommand,_=C.getNextCommand,b=C.store,v=C.send,y=r.useRef(null),g=r.useCallback((function(){y.current&&y.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]),P=r.useCallback((function(){return a(void 0,void 0,void 0,(function(){var e,n,o,a,c,d,C,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}),h(a)?[2]:b.editorInput?(C=o.join(" "),a&&i[a]?"function"!=typeof(x=i[a])?[3,2]:(y.current=new t.CancelablePromise((function(e){e(x(C))})),[4,y.current]):[3,4]):[3,9];case 1:return c=l.sent(),[3,3];case 2:c=x,l.label=3;case 3:return[3,9];case 4:return"function"!=typeof u?[3,6]:(y.current=new t.CancelablePromise((function(e){e(u(n,C))})),[4,y.current]);case 5:return c=l.sent(),[3,9];case 6:return"function"!=typeof s?[3,8]:(y.current=new t.CancelablePromise((function(e){e(s(n,C))})),[4,y.current]);case 7:return c=l.sent(),[3,9];case 8:c=s,l.label=9;case 9:return _=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:_}),[2]}}))}))}),[v,b.bufferedContent,b.editorInput]),w=r.useCallback((function(e){if(n&&o){e.preventDefault();var t=e.key,r=null;if("Enter"===t)"processing"!==b.currentLineStatus&&P();else if("Backspace"===t)b.editorInput&&0!==b.editorInput.length&&v({type:"DELETE"});else if("ArrowUp"===t)(r=x())&&v({type:"ARROW_UP",previousCommand:r});else if("ArrowDown"===t)r=_(),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)&&e.shiftKey&&"v"===t.toLowerCase())navigator.clipboard.readText().then((function(e){v({type:"PASTE",text:e})}));else if((e.metaKey||e.ctrlKey)&&e.shiftKey&&"c"===t.toLowerCase()){var a=window.getSelection().toString();navigator.clipboard.writeText(a).then((function(){v({type:"COPY"})}))}else(e.metaKey||e.ctrlKey)&&"c"===t.toLowerCase()?(y.current&&y.current.cancel(),g()):t&&1===t.length&&v({type:"TYPE",text:t})}}),[g,n,o,_,x,P,v,b.caretPosition,b.currentLineStatus,b.editorInput]);r.useEffect((function(){return document.addEventListener("keydown",w),function(){document.removeEventListener("keydown",w)}}),[w])}({commands:i,errorMessage:u,defaultHandler:m,enableInput:s,prompt:o,consoleFocused:n}),x},w=function(e,t){r.useEffect((function(){t.current&&(t.current.scrollTop=t.current.scrollHeight)}),[e])};function T(e){var t=r.useRef(null),n=r.useContext(c),o=r.useContext(d),a=E().store;w(a.bufferedContent,t);var l=e.enableInput,i=e.caret,u=e.consoleFocused,s=e.prompt,m=e.commands,f=e.welcomeMessage,p=e.errorMessage,C=e.showControlBar,h=e.defaultHandler,x=P(i,u,s,m,p,l,h);return r.createElement("div",{id:"terminalEditor",tabIndex:0,ref:t,className:"".concat(n.editor," ").concat(C?null:n.curvedTop," ").concat(C?n.editorWithTopBar:null),style:{background:o.themeBGColor}},f,a.bufferedContent,x)}function B(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,h=e.showControlBar,x=void 0===h||h,_=e.showControlButtons,b=void 0===_||_,v=e.controlButtonLabels,y=void 0===v?["close","minimize","maximize"]:v,g=e.prompt,E=void 0===g?">>>":g,P=e.commands,w=void 0===P?{}:P,B=e.welcomeMessage,I=void 0===B?"":B,S=e.errorMessage,A=void 0===S?"not found!":S,k=e.enableInput,L=void 0===k||k,N=e.defaultHandler,O=void 0===N?null:N,R=x?r.createElement(p,{consoleFocused:o,showControlButtons:b,controlButtonLabels:y}):null,F=r.createElement(T,{caret:s,consoleFocused:o,prompt:E,commands:w,welcomeMessage:I,errorMessage:A,enableInput:L,showControlBar:x,defaultHandler:O});return r.createElement("div",{ref:t,id:l.terminalContainer,className:l["theme--".concat(C)],"data-testid":"terminal"},r.createElement("div",{className:"".concat(l.terminal),style:{background:i.themeToolbarColor,color:i.themeColor}},R,F))}function I(e){var t=e.children;return r.createElement(u,null,r.createElement(m,null,t))}function S(e){return r.createElement(I,null,r.createElement(B,o({},e)))}var A=function(e){var t=e.children,n=r.useState(null),o=n[0],a=n[1],l=r.useReducer(b,g),i=l[0],c=l[1],u=r.useCallback((function(e){"SUBMIT"===e.type&&a(i.commandsHistory.length),c(e)}),[i.commandsHistory.length]);r.useEffect((function(){a(i.commandsHistory.length)}),[i.commandsHistory.length]);var s=r.useMemo((function(){return{send:u,store:i,getPreviousCommand:function(){if(0===o)return 0===i.commandsHistory.length?"":i.commandsHistory[0];var e=i.commandsHistory[o-1];return o>0&&a(o-1),e},getNextCommand:function(){if(o+1<=i.commandsHistory.length){var e=i.commandsHistory[o+1];return a(o+1),e}return""}}}),[o,u,i]);return r.createElement(_.Provider,{value:s},t)},k={ReactTerminal:S,TerminalContextProvider:A};exports.ReactTerminal=S,exports.TerminalContextProvider=A,exports.default=k;

@@ -6,3 +6,3 @@ {

},
"version": "0.0.5",
"version": "0.0.6",
"description": "A fork of the the 'react-terminal' package, with some extra features - react-terminal-plus",

@@ -12,6 +12,9 @@ "main": "dist/index.js",

"types": "dist/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "./node_modules/.bin/cross-env NODE_ENV=production rollup -c",
"watch": "rollup -cw",
"test": "jest",
"test": "cypress run --component --headless",
"cct:open": "cypress open --component --headed",
"test:jest": "jest",
"prepublishOnly": "npm run build",

@@ -40,2 +43,3 @@ "release": "npx np"

"devDependencies": {
"@testing-library/cypress": "^9.0.0",
"@testing-library/jest-dom": "^5.16.5",

@@ -52,5 +56,7 @@ "@testing-library/react": "^13.4.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",
"enzyme": "^3.11.0",

@@ -70,2 +76,4 @@ "enzyme-adapter-react-16": "^1.15.7",

"postcss": "^8.4.21",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-test-renderer": "^18.2.0",

@@ -79,3 +87,4 @@ "rollup": "^3.13.0",

"ts-loader": "^9.4.2",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"vite": "^4.4.8"
},

@@ -82,0 +91,0 @@ "resolutions": {