Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
crt-terminal-test
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 } 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
- state
and api
of useEventQueue
(command: string) => void
- function to be called every time new command is submittedprompt?: string
- prompt symbol before command input
cursorSymbol?: string
- function to be called every time new command is submitted
maxHistoryCommands?: number
- max number of commands to be memorized in commands history
banner?: PrintableItem
- message to be printed after Terminal
is mounted
loader?: Partial<LoaderConfig>
- loader config, consist of:
slides: string[]
- array of consecutive loader statesloaderSpeed: number
- interval between state changesprinter?: Partial<PrinterConfig>
- printer config, consist of:
printerSpeed: number
- interval between state changescharactersPerTick: number
- characters to print on each tickeffects?
enabling or disabling following effects:
scanner?: boolean
- scanner linepixels?: boolean
- "pixels" effectscreenEffects?: boolean
- screen shakingtextEffects?: boolean
- text glow pulsingThe main part of public interface through which component communicates with outer world. useEventQueue
exports event creators in handlers
field of return 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 one is finishedclear: () => void
- clears terminal "screen" with respect to printing queuefocus: () => void
- focuses terminal inputlock: (payload: boolean) => void
- locks/unlocks terminal input preventing any user attempt to enter a commandloading: (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 loaderYou can use these handlers everywhere to fully control behavior of tour terminal.
If you don't like event creators, you can use enqueue
from api
field of return object. In this case you also need to import enums PrinterEvents
and TerminalEvents
. Important! To avoid possible bugs, you should pass newly created object into enqueue
method
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
with array of Words
. There are two types of lines:
TextLine
(larger x-padding, no y-padding)CommandLine
(smaller x-padding, y-padding).Important! Each Lines
and Words
have common optional fields:
dataAttribute
- data-crt-terminal
attributeclassName
id
Word is essentially a new span
inside line. Word can be multilined, but aware of span intereactions whe one of them is multilined. Each word has characters
filed with content of a word. There are quite few 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 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
MIT Licensed. Copyright (c) Dmitriy Lipin 2022.
FAQs
Retro looking CRT terminal for web
We found that crt-terminal-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.