From 2c6cb97d55af5635e04fdf78615eebe94ceea2dd Mon Sep 17 00:00:00 2001 From: Jason Separovic Date: Tue, 14 Jun 2022 20:13:44 -0700 Subject: [PATCH 1/3] Add functionality to disable builtin commands --- src/js/components/Terminal/index.js | 4 ++-- src/js/components/types.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/components/Terminal/index.js b/src/js/components/Terminal/index.js index 33393d2..3689d60 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', 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, }; From 5ee27d1e151eb8a733b9529ebb27fa6102639bf4 Mon Sep 17 00:00:00 2001 From: Jason Separovic Date: Tue, 14 Jun 2022 21:38:23 -0700 Subject: [PATCH 2/3] add types --- index.d.ts | 1 + 1 file changed, 1 insertion(+) 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; }> {} } From a342c6dd93fb7bb0ce49c4634420b5687660cfdb Mon Sep 17 00:00:00 2001 From: Jason Separovic Date: Wed, 22 Jun 2022 21:53:22 -0700 Subject: [PATCH 3/3] add updateLine and getLines --- src/js/components/Terminal/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/js/components/Terminal/index.js b/src/js/components/Terminal/index.js index 3689d60..bdddbb5 100644 --- a/src/js/components/Terminal/index.js +++ b/src/js/components/Terminal/index.js @@ -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;