Skip to content

Commit eab39e1

Browse files
authored
feat: add an ability to initialize with custom history (#41)
1 parent 51ade4e commit eab39e1

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ An object that's being passed to every command function & returned by `initTermi
109109
| `enableHelp`: boolean | Toggle default `help` command that lists all the available commands and their descriptions. | true |
110110
| `prompt`: string | Terminal prompt | '$: ' |
111111
| `historyLength`: number | A maximum amount of commands that can be stored in the terminal history | 50 |
112+
| `history`: string[] | A default value for terminal history (can be used to preserve history across sessions) | [] |
112113
| `commands`: object | `commands` object | |
113114

114115
### commands object

src/api/init.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const initTerminal = ({
1515
welcomeMessage,
1616
prompt = '$: ',
1717
historyLength = 50,
18+
history = [],
1819
enableHelp = true,
1920
commands
2021
}: TerminalSettings) => {
@@ -30,7 +31,7 @@ const initTerminal = ({
3031
const { commandContainer, input, inputContainer } = buildTree(host, prompt)
3132

3233
const terminal: TerminalInstance = {
33-
history: [],
34+
history,
3435
lastHistoryIndex: 0,
3536
isProcessRunning: false,
3637
settings,

src/types/terminalSettings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export type TerminalSettings = {
66
welcomeMessage?: string,
77
prompt?: string
88
historyLength?: number
9+
history?: string[],
910
enableHelp?: boolean
1011
}

0 commit comments

Comments
 (0)