Introducing PrimeReact v11-alpha 🎉Discover Now

Terminal

An unstyled terminal component for building command-line style interfaces with full control over layout and styling.

Build fully custom terminal interfaces with complete control over layout and styling.

Welcome to PrimeReact Terminal. Type "help" for available commands.
$ 
basic-demo

Pre-styled Versions

Choose a pre-styled library to use Terminal with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Root, Welcome, CommandList, Command, CommandValue, CommandPromptLabel, CommandResponse, Prompt, PromptLabel, PromptValue
  • Synchronous and asynchronous command execution via onCommand
  • Built-in command history navigation with Arrow Up
  • Clears terminal when onCommand returns null
  • Default content rendering — CommandList and Prompt render their children automatically when none are provided

Usage#

import { Terminal } from 'primereact/terminal';
<Terminal.Root>
    <Terminal.Welcome />
    <Terminal.CommandList />
    <Terminal.Prompt>
        <Terminal.PromptLabel />
        <Terminal.PromptValue />
    </Terminal.Prompt>
</Terminal.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Terminal.Root as="section"></Terminal.Root>
<Terminal.CommandList as="ul"></Terminal.CommandList>

Default elements: Root=div, Welcome=div, CommandList=div, Command=div, CommandValue=span, CommandPromptLabel=span, CommandResponse=div, Prompt=div, PromptLabel=span, PromptValue=input.

Render Function Children#

Root accepts a render function as children, providing access to the component instance.

<Terminal.Root prompt="$" onCommand={commandHandler}>
    {(instance) => <span>{instance.state.commands.length} commands executed</span>}
</Terminal.Root>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

TerminalRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalRootInstance—
The instance to pass to the component.
ptSafeRecord<TerminalRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
promptstring—
Prompt text for each command.
onCommandTerminalCommandHandler—
Callback function invoked when a command is entered. Return value determines the response: - React.ReactNode: Displayed as command response - null: Clears the terminal - undefined: No response shown Supports async functions for delayed responses.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"root"

Defines passthrough(pt) options of Terminal component.

labeltypedescription
rootTerminalRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
commandListTerminalRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the commandList's DOM element.
commandsTerminalRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the commands' DOM element.
commandValueTerminalRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the command value's DOM element.
commandResponseTerminalRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the command response's DOM element.
promptTerminalRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the prompt's DOM element.
promptValueTerminalRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the prompt value's DOM element.
promptLabelTerminalRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the prompt label's DOM element.

TerminalWelcome#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalWelcomeInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalWelcomeInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalWelcomeInstance—
The instance to pass to the component.
ptSafeRecord<TerminalWelcomePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalWelcomeInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"welcome"

Defines passthrough(pt) options of TerminalWelcome component.

labeltypedescription
rootTerminalWelcomePassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TerminalCommandList#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalCommandListInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalCommandListInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalCommandListInstance—
The instance to pass to the component.
ptSafeRecord<TerminalCommandListPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalCommandListInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"commandlist"

Defines passthrough(pt) options of TerminalCommandList component.

labeltypedescription
rootTerminalCommandListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TerminalCommand#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalCommandInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalCommandInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalCommandInstance—
The instance to pass to the component.
ptSafeRecord<TerminalCommandPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalCommandInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
indexnumber—
Index of the command in the list.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"command"

Defines passthrough(pt) options of TerminalCommand component.

labeltypedescription
rootTerminalCommandPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TerminalCommandValue#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalCommandValueInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalCommandValueInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalCommandValueInstance—
The instance to pass to the component.
ptSafeRecord<TerminalCommandValuePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalCommandValueInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"commandvalue"

Defines passthrough(pt) options of TerminalCommandValue component.

labeltypedescription
rootTerminalCommandValuePassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

TerminalCommandPromptLabel#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalCommandPromptLabelInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalCommandPromptLabelInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalCommandPromptLabelInstance—
The instance to pass to the component.
ptSafeRecord<TerminalCommandPromptLabelPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalCommandPromptLabelInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"commandpromptlabel"

Defines passthrough(pt) options of TerminalCommandPromptLabel component.

labeltypedescription
rootTerminalCommandPromptLabelPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

TerminalCommandResponse#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalCommandResponseInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalCommandResponseInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalCommandResponseInstance—
The instance to pass to the component.
ptSafeRecord<TerminalCommandResponsePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalCommandResponseInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"commandresponse"

Defines passthrough(pt) options of TerminalCommandResponse component.

labeltypedescription
rootTerminalCommandResponsePassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TerminalPrompt#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalPromptInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalPromptInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalPromptInstance—
The instance to pass to the component.
ptSafeRecord<TerminalPromptPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalPromptInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"prompt"

Defines passthrough(pt) options of TerminalPrompt component.

labeltypedescription
rootTerminalPromptPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TerminalPromptLabel#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalPromptLabelInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalPromptLabelInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalPromptLabelInstance—
The instance to pass to the component.
ptSafeRecord<TerminalPromptLabelPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalPromptLabelInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"promptlabel"

Defines passthrough(pt) options of TerminalPromptLabel component.

labeltypedescription
rootTerminalPromptLabelPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

TerminalPromptValue#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TerminalPromptValueInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TerminalPromptValueInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTerminalPromptValueInstance—
The instance to pass to the component.
ptSafeRecord<TerminalPromptValuePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TerminalPromptValueInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"terminal"
data-part"promptvalue"

Defines passthrough(pt) options of TerminalPromptValue component.

labeltypedescription
rootTerminalPromptValuePassThroughType<InputHTMLAttributes<HTMLInputElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

The command response element has aria-live="polite" so that new responses are announced by the screen reader. Clicking anywhere on the terminal root focuses the input element.

Keyboard Support#

KeyFunction
tabMoves focus through the input element.
enterExecutes the command when focus is on the input element.
arrow upRecalls the previous command from history.