Design Converter
Education
Developer Advocate
Last updated on Nov 8, 2023
Last updated on Nov 6, 2023
React Terminal UI is a powerful open-source tool that allows developers to create terminal-like interfaces in their web applications. It's a React component library that provides a high level of customization, including the ability to create custom themes.
1import React from 'react'; 2import Terminal from 'react-terminal-ui'; 3
Component libraries in React, like React Terminal UI, provide pre-written, reusable components that can significantly speed up development time. They also ensure consistency across different parts of your application.
To start with React Terminal UI, you must install it as one of your project's development dependencies.
1npm install react-terminal-ui 2
React Terminal UI has a few built-in themes, such as Material Light, Dark, and Ocean. You can easily apply these themes to your terminal.
1import React from 'react'; 2import Terminal from 'react-terminal-ui'; 3import 'react-terminal-ui/dist/index.css'; 4 5function App() { 6 return ( 7 <Terminal theme="material-light" /> 8 ); 9} 10 11export default App; 12
Let's create a simple terminal application. We'll define a few commands and their corresponding actions.
1import React from 'react'; 2import Terminal from 'react-terminal-ui'; 3 4const commands = { 5 'greet': () => 'Hello, world!', 6 'date': () => new Date().toString(), 7}; 8 9function App() { 10 return ( 11 <Terminal commands={commands} /> 12 ); 13} 14 15export default App; 16
In the above code, a command is an object where each key-value pair represents a command and its corresponding action. When a user enters a command in the terminal, the action associated with that command is executed.
If a user enters an unidentified command, we can display a custom error message.
1const commands = { 2 'greet': () => 'Hello, world!', 3 'date': () => new Date().toString(), 4 'default': () => 'Unidentified command executed', 5}; 6
You can customize the welcome message and the prompt that appears before each command.
1function App() { 2 return ( 3 <Terminal 4 commands={commands} 5 welcomeMessage="Welcome to my custom terminal!" 6 prompt="my-terminal> " 7 /> 8 ); 9} 10
Creating custom themes in React Terminal UI involves passing a theme parameter to the Terminal component. This parameter should be an object where each key-value pair represents a CSS property and its value.
1const myCustomTheme = { 2 background: '#282c34', 3 promptSymbolColor: '#61dafb', 4 commandColor: '#61dafb', 5 outputColor: '#ffffff', 6}; 7 8function App() { 9 return ( 10 <Terminal 11 commands={commands} 12 theme={myCustomTheme} 13 /> 14 ); 15} 16
In the above code, a theme is a prop that accepts either a string representing one of the in-built themes or an object representing a custom theme.
Each key-value pair in the theme object represents a CSS property and its value. The keys should be in camelCase format.
You can display control buttons and a top bar in your terminal by setting the showControlButtons prop to true.
1function App() { 2 return ( 3 <Terminal 4 commands={commands} 5 theme={myCustomTheme} 6 showControlButtons={true} 7 /> 8 ); 9} 10
React Terminal UI is highly customizable, allowing you to add new features to your terminal application as per your requirements.
If you encounter any issues while using React Terminal UI, you can check the official documentation or raise a GitHub issue.
MUI (formerly Material-UI) is a popular React component library that provides a wide range of pre-designed components. It can be used with React Terminal UI to create beautiful and consistent user interfaces.
React Terminal UI is a powerful tool that allows developers to create highly customizable terminal-like interfaces in their web applications. With its support for custom themes and commands, it provides a high level of flexibility and control, making it a valuable addition.
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.