Skip to content

Commit

Permalink
feat: add an ability to initialize with custom history
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrl committed Jul 20, 2023
1 parent 51ade4e commit fccfb4c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const initTerminal = ({
welcomeMessage,
prompt = '$: ',
historyLength = 50,
history = [],
enableHelp = true,
commands
}: TerminalSettings) => {
Expand All @@ -30,7 +31,7 @@ const initTerminal = ({
const { commandContainer, input, inputContainer } = buildTree(host, prompt)

const terminal: TerminalInstance = {
history: [],
history,
lastHistoryIndex: 0,
isProcessRunning: false,
settings,
Expand Down
1 change: 1 addition & 0 deletions src/types/terminalSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export type TerminalSettings = {
welcomeMessage?: string,
prompt?: string
historyLength?: number
history?: string[],
enableHelp?: boolean
}

0 comments on commit fccfb4c

Please sign in to comment.