diff --git a/index.d.ts b/index.d.ts index 7d2deea..6e1d8d5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,5 +25,6 @@ declare module 'terminal-in-react' { handleMaximise?: (toggleMaximise: () => void) => void; handleMinimise?: (toggleMinimise: () => void) => void; }; + disableBuiltin?: boolean; }> {} } diff --git a/src/js/components/Terminal/index.js b/src/js/components/Terminal/index.js index 33393d2..bdddbb5 100644 --- a/src/js/components/Terminal/index.js +++ b/src/js/components/Terminal/index.js @@ -75,7 +75,7 @@ class Terminal extends Component { this.pluginData = {}; - this.defaultCommands = { + this.defaultCommands = props.disableBuiltin ? {} : { // eslint-disable-line react/sort-comp show: this.showMsg, clear: { @@ -101,7 +101,7 @@ class Terminal extends Component { }, }; - this.defaultDesciptions = { + this.defaultDesciptions = props.disableBuiltin ? {} : { show: (props.msg && props.msg.length > 0) ? 'show the msg' : false, clear: 'clear the screen', help: 'list all the commands', @@ -389,6 +389,8 @@ class Terminal extends Component { pluginMap(this.props.plugins, (PluginClass, config) => { try { const api = { + updateLine: this.updateLine.bind(this, instance), + getLines: this.getLines.bind(this, instance), printLine: this.printLine.bind(this, instance), removeLine: this.removeLine.bind(this, instance), runCommand: this.runCommand.bind(this, instance), @@ -758,6 +760,17 @@ class Terminal extends Component { } } + getLines = (instance) => { + const { summary } = instance.state; + return summary; + } + + updateLine = (instance, lineNumber, value) => { + const { summary } = instance.state; + summary[lineNumber] = value; + instance.setState({ summary }); + } + // Print the summary (input -> output) printLine = (instance, inp, std = true) => { let print = true; diff --git a/src/js/components/types.js b/src/js/components/types.js index d965880..6f9298b 100644 --- a/src/js/components/types.js +++ b/src/js/components/types.js @@ -54,6 +54,7 @@ export const TerminalPropTypes = { }), afterChange: PropTypes.func, commandWasRun: PropTypes.func, + disableBuiltin: PropTypes.bool, }; export const TerminalContextTypes = { @@ -95,4 +96,5 @@ export const TerminalDefaultProps = { promptSymbol: '>', plugins: [], shortcuts: {}, + disableBuiltin: false, };