From eab39e1ce0f9eb11e3157ae4235166b54887d78c Mon Sep 17 00:00:00 2001 From: Mikhail Korolev Date: Thu, 20 Jul 2023 20:35:20 +0200 Subject: [PATCH] feat: add an ability to initialize with custom history (#41) --- README.md | 1 + src/api/init.ts | 3 ++- src/types/terminalSettings.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 453dafa..20f1048 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ An object that's being passed to every command function & returned by `initTermi | `enableHelp`: boolean | Toggle default `help` command that lists all the available commands and their descriptions. | true | | `prompt`: string | Terminal prompt | '$: ' | | `historyLength`: number | A maximum amount of commands that can be stored in the terminal history | 50 | +| `history`: string[] | A default value for terminal history (can be used to preserve history across sessions) | [] | | `commands`: object | `commands` object | | ### commands object diff --git a/src/api/init.ts b/src/api/init.ts index 2de54d2..9a0a35f 100644 --- a/src/api/init.ts +++ b/src/api/init.ts @@ -15,6 +15,7 @@ const initTerminal = ({ welcomeMessage, prompt = '$: ', historyLength = 50, + history = [], enableHelp = true, commands }: TerminalSettings) => { @@ -30,7 +31,7 @@ const initTerminal = ({ const { commandContainer, input, inputContainer } = buildTree(host, prompt) const terminal: TerminalInstance = { - history: [], + history, lastHistoryIndex: 0, isProcessRunning: false, settings, diff --git a/src/types/terminalSettings.ts b/src/types/terminalSettings.ts index 38003d6..0b220f5 100644 --- a/src/types/terminalSettings.ts +++ b/src/types/terminalSettings.ts @@ -6,5 +6,6 @@ export type TerminalSettings = { welcomeMessage?: string, prompt?: string historyLength?: number + history?: string[], enableHelp?: boolean }