Core widgets
TermText
The TermText widget is a simple text widget that can be used to display text in a terminal. Unlike other terminal libraries it natively supports most text layout CSS properties such as text-align
or white-space
.
If using React you won't need to explicitly use <term:text>
in most cases: the renderer will convert all JSX text nodes into TermText widgets. However, if you wish to attach CSS properties to the text, using the <term:text>
may be required unless those properties are inheritable.
Example
import {useEffectfunction useEffect(effect: EffectCallback, deps?: DependencyList): void
Accepts a function that contains imperative, possibly effectful code., useStatefunction useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>] (+1 overload)
Returns a stateful value, and a function to update it.} from 'react';
import {renderfunction render(element: React.ReactNode): Promise<void> (+1 overload)
Render a React element into the terminal. Return a promise that resolves when the screen is closed.} from 'terminosaurus/react';
function BouncingContainerfunction BouncingContainer(): React.JSX.Element
() {
const [widthconst width: number
, setWidthconst setWidth: React.Dispatch<React.SetStateAction<number>>
] = useStateuseState<number>(initialState: number | (() => number)): [number, React.Dispatch<React.SetStateAction<number>>] (+1 overload)
Returns a stateful value, and a function to update it.(10);
useEffectfunction useEffect(effect: React.EffectCallback, deps?: React.DependencyList | undefined): void
Accepts a function that contains imperative, possibly effectful code.(() => {
let currentlet current: number
= 10;
let directionlet direction: number
= 1;
const intervalconst interval: NodeJS.Timeout
= setIntervalfunction setInterval<[]>(callback: () => void, ms?: number | undefined): NodeJS.Timeout (+2 overloads)
Schedules repeated execution of `callback` every `delay` milliseconds.
When `delay` is larger than `2147483647` or less than `1`, the `delay` will be
set to `1`. Non-integer delays are truncated to an integer.
If `callback` is not a function, a `TypeError` will be thrown.
This method has a custom variant for promises that is available using `timersPromises.setInterval()`.(() => {
directionlet direction: number
= currentlet current: number
>= 60 ? -1 : currentlet current: number
<= 10 ? 1 : directionlet direction: number
;
setWidthconst setWidth: (value: React.SetStateAction<number>) => void
(currentlet current: number
+= directionlet direction: number
);
}, 50);
setWidthconst setWidth: (value: React.SetStateAction<number>) => void
(currentlet current: number
);
return () => clearIntervalfunction clearInterval(intervalId: string | number | NodeJS.Timeout | undefined): void (+1 overload)
Cancels a `Timeout` object created by `setInterval()`.(intervalconst interval: NodeJS.Timeout
);
}, []);
return (
<termJSX.IntrinsicElements['term:text']: {
key?: string | undefined;
ref?: React.Ref<TermText> | undefined;
} & Partial<AllPropertiesInputs> & {
text?: string | undefined;
disabled?: boolean | undefined;
decorated?: boolean | undefined;
} & AllReactEventsFor<...> & HasChildren
:textJSX.IntrinsicElements['term:text']: {
key?: string | undefined;
ref?: React.Ref<TermText> | undefined;
} & Partial<AllPropertiesInputs> & {
text?: string | undefined;
disabled?: boolean | undefined;
decorated?: boolean | undefined;
} & AllReactEventsFor<...> & HasChildren
borderborder?: "inherit" | "simple" | "strong" | "modern" | {} | [[string | null], [string | null, string | null], [string | null, string | null, string | null, string | null], [...], [...]] | "double" | "block" | "rounded" | undefined
={`modern`} widthwidth?: string | number | undefined
={widthconst width: number
} whiteSpacewhiteSpace?: "inherit" | "normal" | "noWrap" | "pre" | "preWrap" | "preLine" | undefined
={`preLine`}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent faucibus mollis turpis luctus dignissim. Cras quis nisl euismod, efficitur quam eget, euismod metus. Nunc eu elit non lacus suscipit tempus vitae nec sem. Pellentesque ultrices tortor at turpis ullamcorper porta. Maecenas sem mi, maximus a tempus id, tristique nec lacus. Mauris eget purus arcu. Donec id sem a est finibus aliquam.
</termJSX.IntrinsicElements['term:text']: {
key?: string | undefined;
ref?: React.Ref<TermText> | undefined;
} & Partial<AllPropertiesInputs> & {
text?: string | undefined;
disabled?: boolean | undefined;
decorated?: boolean | undefined;
} & AllReactEventsFor<...> & HasChildren
:textJSX.IntrinsicElements['term:text']: {
key?: string | undefined;
ref?: React.Ref<TermText> | undefined;
} & Partial<AllPropertiesInputs> & {
text?: string | undefined;
disabled?: boolean | undefined;
decorated?: boolean | undefined;
} & AllReactEventsFor<...> & HasChildren
>
);
}
renderfunction render(element: React.ReactNode): Promise<void> (+1 overload)
Render a React element into the terminal. Return a promise that resolves when the screen is closed.(<BouncingContainerfunction BouncingContainer(): React.JSX.Element
/>);