New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

terminal-next

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terminal-next

--- Next gen terminal helper, slim, extensible, easy to use. Fully promise based, callbacks are not a thing anymore. Some widgets do not support non-tty terminals.

latest
Source
npmnpm
Version
1.2.2
Version published
Maintainers
2
Created
Source

Terminal Next

Next gen terminal helper, slim, extensible, easy to use. Fully promise based, callbacks are not a thing anymore. Some widgets do not support non-tty terminals.

Zero dependencies.

npm node-current

Requirements

Node v14+, cannot run in browser

Docs

Read documentation here

Installation

For yarn:

yarn add terminal-next

For npm:

npm i terminal-next

Basic usage:

Examples can be found here

either compile them or use ts-node to execute immediately

import { Terminal }    from 'terminal-next';

// optionally pass stdin and/or stdout, if not provided
// process.stdin and process.stdout will be used
const t = new Terminal();

t.red('Red text').newline();

// fully customizable text output
t.text('Some text', {fg: 'cyan', bg: 'red', dim: true});

TextInput

Typical text input prompt

import { Terminal, TextInput }    from 'terminal-next';
const t = new Terminal();

// you can use promises instead of await
(async () => {
	const ti = new TextInput(t, 'Your name?');
	const answ = await ti.start();
	t.text(answ);
})();

Confirm

Simple yes/no confirmation

import { Terminal, Confirm }    from 'terminal-next';
const t = new Terminal();

(async () => {
	const ti = new Confirm(t, 'Super?');
	const answ = await ti.start();
	t.text(answ.toString()).newline();
})();

Select

Single option select widget

import { Terminal, Select }    from 'terminal-next';
const t = new Terminal();

(async () => {
	const options = [
		{title: 'Option 1', value: '111'},
		{title: 'Option 2', value: '222'},
		{title: 'Some other option', value: '333'},
	];
	const select = new Select(t, options);
	const result = await select.start();
	t.text('answer: ' + result);
})();

Spinner

Spinner with a text

import { Terminal, Spinner }    from 'terminal-next';

const t = new Terminal(process.stdout, process.stdin);

(async () => {
	const spinner = new Spinner(t, 'test');
	// you define tick rate yourself or just tick whenever a progress is made
	const itv = setInterval(async () => {
		await spinner.draw();
	}, 100);

	setTimeout(()=> {
		clearInterval(itv);
	}, 3000);
})();

ProgressBar

import { Terminal, ProgressBar }    from 'terminal-next';

const t = new Terminal();

(async () => {
	const pb = new ProgressBar(t, 100);
	await pb.draw();

	let prog = 0;
	const itv = setInterval(async () => {
		await pb.setProgress(prog);
		prog++;
		if (prog > 100) {
			clearInterval(itv);
			// important, in order to stop terminal from flickering, 
			// show cursor after this is done
			t.showCursor();
		}
	}, 50);
})();

Table

import { Terminal, Table }    from 'terminal-next';

const t = new Terminal();

(async () => {
	t.clear();

	const data = [
		['id', 'name', 'email', 'active', 'banned'],
		['1', 'Marian', 'mtest@tst.com', 'true', 'false'],
		['2', 'Adam', 'adam@gmail.com', 'true', 'true'],
		['3', 'Gertruda', 'g.rtruda@wp.pl', 'false', 'false']
	];
	const table = new Table(t);
	table.setData(data);
	table.draw();
})();

More widgets?

You can either construct them yourself or make PR if you think there is a widget that is really important to have. Either way, create issue in this project.

Keywords

terminal

FAQs

Package last updated on 18 Jun 2021

Did you know?

Socket

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.

Install

Related posts