From c417af86531b6ae4b8b3c359a0481e1c7beeb3ab Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Thu, 25 Aug 2022 16:15:03 -0700 Subject: [PATCH 1/6] Made maxOutput prop --- docs/CONFIG.md | 1 + src/Terminal.jsx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 205ee835..985f1bf1 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -50,6 +50,7 @@ The terminal has several options you can use to change the behaviour of it. All | readOnly | Hides the entire prompt, thus setting the terminal to read-only mode. | Boolean | `false` | | styleEchoBack | Inherit style for command echoes (Terminal outputs of any commands entered) from prompt (Fully or partially, i.e. label or text only), or style them as regular messages. Omitting this prop enables default behaviour. | String<'labelOnly'/'textOnly'/'fullInherit'/'messageInherit'\> | `undefined` | | welcomeMessage | The terminal welcome message. Set to `false` to disable, `true` to show the default, or supply a string (Or an array of them) to set a custom one. | Boolean/String/Array | `false` | +| maxOutput | The maximum amount of output lines in the terminal. Set to integer to cap output lines at that amount, set to false for there to be no cap. | Boolean/Number | `false` | ### Re-styling diff --git a/src/Terminal.jsx b/src/Terminal.jsx index 49bbe720..4d7f9ca1 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -90,7 +90,8 @@ export default class Terminal extends Component { const { stdout } = this.state if (this.props.locked) stdout.pop() - + if (stdout.length > this.props.maxOutput && typeof this.props.maxOutput === "number") stdout.shift() + stdout.push({ message, isEcho: options?.isEcho || false }) /* istanbul ignore next: Covered by interactivity tests */ From 455d673e9e3f0da1d6a1bf772fa883ce831e1663 Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Mon, 3 Oct 2022 10:15:54 -0700 Subject: [PATCH 2/6] removed boolean, and fixed fence post error --- docs/CONFIG.md | 2 +- src/Terminal.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 985f1bf1..5f4c750e 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -50,7 +50,7 @@ The terminal has several options you can use to change the behaviour of it. All | readOnly | Hides the entire prompt, thus setting the terminal to read-only mode. | Boolean | `false` | | styleEchoBack | Inherit style for command echoes (Terminal outputs of any commands entered) from prompt (Fully or partially, i.e. label or text only), or style them as regular messages. Omitting this prop enables default behaviour. | String<'labelOnly'/'textOnly'/'fullInherit'/'messageInherit'\> | `undefined` | | welcomeMessage | The terminal welcome message. Set to `false` to disable, `true` to show the default, or supply a string (Or an array of them) to set a custom one. | Boolean/String/Array | `false` | -| maxOutput | The maximum amount of output lines in the terminal. Set to integer to cap output lines at that amount, set to false for there to be no cap. | Boolean/Number | `false` | +| maxOutput | The maximum amount of output lines in the terminal. Set to integer to cap output lines at that amount, set to 0 for there to be no cap. | Number | `0` | ### Re-styling diff --git a/src/Terminal.jsx b/src/Terminal.jsx index 4d7f9ca1..18b9a22d 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -90,7 +90,7 @@ export default class Terminal extends Component { const { stdout } = this.state if (this.props.locked) stdout.pop() - if (stdout.length > this.props.maxOutput && typeof this.props.maxOutput === "number") stdout.shift() + if (stdout.length + 1 > this.props.maxOutput && this.props.maxOutput > 0) stdout.shift() stdout.push({ message, isEcho: options?.isEcho || false }) From 3bee4da543b676b6abfd65f79c21900155329faf Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Mon, 3 Oct 2022 10:17:36 -0700 Subject: [PATCH 3/6] added clarification --- docs/CONFIG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 5f4c750e..9378e71d 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -50,7 +50,7 @@ The terminal has several options you can use to change the behaviour of it. All | readOnly | Hides the entire prompt, thus setting the terminal to read-only mode. | Boolean | `false` | | styleEchoBack | Inherit style for command echoes (Terminal outputs of any commands entered) from prompt (Fully or partially, i.e. label or text only), or style them as regular messages. Omitting this prop enables default behaviour. | String<'labelOnly'/'textOnly'/'fullInherit'/'messageInherit'\> | `undefined` | | welcomeMessage | The terminal welcome message. Set to `false` to disable, `true` to show the default, or supply a string (Or an array of them) to set a custom one. | Boolean/String/Array | `false` | -| maxOutput | The maximum amount of output lines in the terminal. Set to integer to cap output lines at that amount, set to 0 for there to be no cap. | Number | `0` | +| maxOutput | The maximum amount of output lines in the terminal. Set to integer to cap output lines at that amount, set to 0 for there to be no cap. Omitting this prop enables default behaviour. | Number | `0` | ### Re-styling From 5152ecdece96f639fd4f51823f2f351a12fde519 Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Mon, 3 Oct 2022 10:21:01 -0700 Subject: [PATCH 4/6] Made cleaner --- src/Terminal.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Terminal.jsx b/src/Terminal.jsx index 18b9a22d..d15234cc 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -90,7 +90,7 @@ export default class Terminal extends Component { const { stdout } = this.state if (this.props.locked) stdout.pop() - if (stdout.length + 1 > this.props.maxOutput && this.props.maxOutput > 0) stdout.shift() + if (stdout.length >= this.props.maxOutput && this.props.maxOutput > 0) stdout.shift() stdout.push({ message, isEcho: options?.isEcho || false }) From 9ac86cb6b52c10f409fedf2676c09eacb5f9ce27 Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Mon, 3 Oct 2022 11:49:20 -0700 Subject: [PATCH 5/6] updated proptypes --- src/defs/types/Terminal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/defs/types/Terminal.js b/src/defs/types/Terminal.js index 3747a182..7243a104 100644 --- a/src/defs/types/Terminal.js +++ b/src/defs/types/Terminal.js @@ -39,7 +39,8 @@ const optionTypes = { noEchoBack: PropTypes.bool, noHistory: PropTypes.bool, noAutoScroll: PropTypes.bool, - noNewlineParsing: PropTypes.bool + noNewlineParsing: PropTypes.bool, + maxOutput: PropTypes.number } const labelTypes = { From eef273a801545e6d6189fa0f446ef1bb9ec4862d Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Sun, 20 Nov 2022 04:04:58 -0700 Subject: [PATCH 6/6] fixed assumption that this.props.maxOutput exists --- src/Terminal.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Terminal.jsx b/src/Terminal.jsx index d15234cc..525970f6 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -90,7 +90,7 @@ export default class Terminal extends Component { const { stdout } = this.state if (this.props.locked) stdout.pop() - if (stdout.length >= this.props.maxOutput && this.props.maxOutput > 0) stdout.shift() + if (this.props.maxOutput && stdout.length >= this.props.maxOutput) stdout.shift() stdout.push({ message, isEcho: options?.isEcho || false })