
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
crt-terminal
Advanced tools
Simple retro styled React-hooks-based terminal shell.
The best way to use crt-terminal is to install it from npm and include it into your app.
yarn add crt-terminal
npm install crt-terminal
Then you need to import Terminal
, useEventQueue
(or implement your own EventQueue) and line/words helpers (or corresponding enum with IDs).
Important! For better experience Terminal
should be wrapped into a fixed size container.
import React from 'react';
import { Terminal, useEventQueue, textLine, textWord, commandWord } from 'crt-terminal';
const bannerText = `
Hello world!
And not only world
`;
export default function App() {
const eventQueue = useEventQueue();
const { print } = eventQueue.handlers;
return (
<div style={{ width: '1000px', height: '600px' }}>
<Terminal
queue={eventQueue}
banner={[textLine({ words: [textWord({ characters: bannerText })] })]}
onCommand={(command) =>
print([
textLine({
words: [
textWord({ characters: 'You entered command: ' }),
commandWord({ characters: command, prompt: '>' }),
],
}),
])
}
/>
</div>
);
}
queue: QueueInterface
- object returned by useEventQueue
, contains state
and api
fields;(command: string) => void
- function to be called every time new command is submitted;prompt?: string
- prompt symbol before command input; default: >\xa0
;
cursorSymbol?: string
- cursor symbol inside command input; default: \xa0
;
maxHistoryCommands?: number
- max number of commands to be memorized in commands history; default: 10
;
banner?: PrintableItem
- message to be printed after Terminal
is mounted; default: undefined
.
loader?: Partial<LoaderConfig>
- loader config, consist of:
slides: string[]
- array of consecutive loader states; default: ['.', '..', '...']
;loaderSpeed: number
- interval between state changes; default: 1000
;printer?: Partial<PrinterConfig>
- printer config, consist of:
printerSpeed: number
- interval between state changes; default: 20
;charactersPerTick: number
- characters to print on each tick; default: 5
;onPrintStatusChange?: (nextPrintState: boolean) => void
- callback which reports printer status (printing / not printing);effects?
enabling or disabling following effects:
scanner?: boolean
- scanner line; default: true
;pixels?: boolean
- "pixels" effect; default: true
;screenEffects?: boolean
- screen shaking; default: true
;textEffects?: boolean
- text glow, pulsing; default: true
;Event Queue is the main part of public interface through which component communicates with outer world. useEventQueue
exports event creators in handlers
field of returned object, namely:
print: (payload: PrintableItem) => void
- prints a message on terminal "screen". Important! Print is async operation, so your next message will be printed as soon as the previous ones are done printing;clear: () => void
- clears terminal "screen" with respect to printing queue;focus: () => void
- focuses terminal input;lock: (payload: boolean) => void
- locks/unlocks terminal input preventing any user attempt to enter a command;loading: (payload: boolean) => void
- starts/ends loader. Important! Loading start locks input automatically, if it is not locked yet. Loading end unlocks input automatically, if it was locked by loader.You can use these handlers everywhere to fully control behavior of your terminal.
If you don't like event creators, you can use enqueue
function from api
field of the object returned by useEventQueue
. In this case you also need to import enums PrinterEvents
and TerminalEvents
. Important! To avoid possible bugs, you should pass a newly created object every time enqueue
method is called.
As one can notice print
handler prints a PrintableItem
. PrintableItem
or sentence is an array of Lines
. Line is essentially a new div
on the screen, each line has field words
containing array of Words
. There are two types of lines:
TextLine
(larger x-padding, no y-padding)CommandLine
(smaller x-padding, has y-padding).Important! Each Lines
and Words
have common optional fields:
data-crt-terminal
- can be defined for customization, better search, etc.className
id
Word is essentially a new span
inside a line. Word can be multilined. Each word has characters
filed containing content of a word. There are following types of words:
AnchorWord
- <a>
element with optional href
and onClick
fieldsTextWord
- <span>
elementButtonWord
- <button>
element with optional onClick
fieldCommandWord
- <span>
element with required prompt
fieldThere are two ways of creating Lines
and Words
:
textWord
, buttonWord
, commandWord
, anchorWord
, commandLine
, textLine
WordTypes
, LineTypes
enumsEvery element inside terminal has special fixed style, to which you can safely refer to. You can also add your own className
for lines and words.
Command history saves entered commands, but no more then maxHistoryCommands
. You can get previous/next saved command by pressing Arrow Up
/ Arrow Down
It is a turborepo-based monorepo set up for testing and developing. Library itself is inside packages/crt-terminal, demo app is inside apps/web; to start locally just yarn dev
in root folder.
MIT Licensed. Copyright (c) Dmitriy Lipin 2022.
FAQs
Retro looking CRT terminal for web
We found that crt-terminal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.