Security News
RubyGems.org Adds New Maintainer Role
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.
terminal-kit
Advanced tools
Terminal utilities with supports for colors (even 256 colors), styles, inputs, mouse and many more...
The terminal-kit npm package provides a comprehensive set of tools for creating rich terminal applications. It offers functionalities for handling terminal input and output, creating interactive user interfaces, and managing terminal capabilities.
Terminal Output
This feature allows you to output text to the terminal. The code sample demonstrates how to print 'Hello, world!' to the terminal using terminal-kit.
const term = require('terminal-kit').terminal;
term('Hello, world!\n');
Interactive Menus
This feature allows you to create interactive menus. The code sample shows how to create a single-column menu with three options and handle the user's selection.
const term = require('terminal-kit').terminal;
term.singleColumnMenu(['Option 1', 'Option 2', 'Option 3'], function(error, response) {
term('
').eraseLineAfter.green('You selected: %s
', response.selectedText);
});
Text Input
This feature allows you to capture text input from the user. The code sample demonstrates how to prompt the user to enter their name and then display it.
const term = require('terminal-kit').terminal;
term('Enter your name: ');
term.inputField(function(error, input) {
term.green('
Your name is: %s
', input);
});
Progress Bars
This feature allows you to create and manage progress bars. The code sample shows how to create a progress bar that updates every 100 milliseconds until it reaches 100%.
const term = require('terminal-kit').terminal;
const ProgressBar = require('terminal-kit').ProgressBar;
const progressBar = new ProgressBar({
width: 80,
title: 'Progress',
eta: true,
percent: true
});
let progress = 0;
const interval = setInterval(() => {
progress += 0.01;
progressBar.update(progress);
if (progress >= 1) {
clearInterval(interval);
term.green('
Done!
');
}
}, 100);
Blessed is a high-level terminal interface library for node.js. It provides a wide range of widgets and supports complex layouts, making it suitable for creating advanced terminal applications. Compared to terminal-kit, blessed offers more built-in widgets and a more extensive API for layout management.
Ink is a React-like library for building command-line interfaces using React components. It allows you to use the familiar React paradigm to create terminal applications. Compared to terminal-kit, ink leverages the React ecosystem, making it a good choice for developers who are already comfortable with React.
Vorpal is a framework for building interactive CLI applications. It provides a command-line interface with built-in support for commands, arguments, and options. Compared to terminal-kit, vorpal focuses more on creating command-line tools rather than rich terminal UIs.
Terminal utilities for node.js, it supports 'xterm' compatible terminal and the Linux Console. It does not depend on ncurses.
// Require the lib
var term = require( 'terminal-kit' ) ;
// The term() function simply output a string to stdout, using current style
// output "Hello world!" in default terminal's colors
term( 'Hello world!\n' ) ;
// This output 'red' in red
term.red( 'red' ) ;
// This output 'bold' in bold
term.bold( 'bold' ) ;
// output 'mixed' using bold, underlined & red, exposing the style-mixing syntax
term.bold.underline.red( 'mixed' ) ;
// printf() style formating everywhere: this will output 'My name is Jack, I'm 32.' in green
term.green( "My name is %s, I'm %d.\n" , 'Jack' , 32 ) ;
// Width and height of the terminal
term( 'The terminal size is %dx%d' , term.width , term.height ) ;
// Move the cursor at the upper-left corner
term.moveTo( 1 , 1 ) ;
// We can always pass additionnal arguments that will be displayed...
term.moveTo( 1 , 1 , 'Upper-left corner' ) ;
// ... and formated
term.moveTo( 1 , 1 , "My name is %s, I'm %d.\n" , 'Jack' , 32 ) ;
// ... or even combined with other styles
term.moveTo.cyan( 1 , 1 , "My name is %s, I'm %d.\n" , 'Jack' , 32 ) ;
Use Node Package Manager:
npm install terminal-kit
Standard methods map low-level terminal capabilities.
For all the functions below, additionnal arguments can be provided.
If a boolean is provided, it will turn the feature on or off.
For example term.red( true )
turn all subsequent output in red, while term.red( false )
disable red and go back to default color.
Without arguments, it is always the same as true, e.g. term.red()
do the same thing than term.red()
.
Some function cannot be turned off, they just perform an action.
For example term.reset()
reset the terminal, usually to its default.
This is not reversible, thus term.reset( false )
does nothing.
If the additional argument is a string, then it will be sent to the output directly after turning on the feature... then the feature is turn off.
That's it:
term.red( 'Hello world!' )
... is the same as:
term.red( true ) ; term( 'Hello world!' ) ; term.red( false ) ;
.
Also those string support a printf()-like formating syntax.
So we can do term.red( "My name is %s, I'm %d." , 'Jack' , 32 )
to output "My name is Jack, I'm 32.".
All those functions are chainable, and their arguments can be combined.
We can do:
term.moveTo.red( 1 , 1 , "My name is %s, I'm %d.\n" , 'Jack' , 32 )
which will move the cursor to (1,1), then output "My name is Jack, I'm 32." in red.
Advanced methods are high-level librairie functions.
Function( error , codename , name , pid )
where:
This method detect on which terminal your application run. It does *NOT* use the $TERM environment variable. It iterates through parent process until a known terminal is found, or process of PID 1 is reached (the init process).
Obviously, it does not works over SSH.
Function( error , term )
where:
This is a shortcut that call .getParentTerminalInfo()
then use .createTerminal()
with the correct arguments.
This will give you a terminal object with the best support that this lib is able to give to you.
It does not works over SSH.
Example *NOT* using .getDetectedTerminal()
:
var term = require( 'terminal-kit' ) ;
term.cyan( 'Hello world!' ) ;
This will give you a terminal object based on the $TERM environment variable, that works fine in most case. But please consider that most of modern terminal report them as an xterm or an xterm-256color terminal. They claim being xterm-compatible, but most of them support only 33% to 50% of xterm features, and even major terminal like gnome-terminal or Konsole are terrible.
Example using .getDetectedTerminal()
:
require( 'terminal-kit' ).getDetectedTerminal( function( error , term ) {
term.cyan( 'Terminal name: %s\n' , term.appName ) ;
term.cyan( 'Terminal app: %s\n' , term.app ) ;
term.cyan( 'Terminal generic: %s\n' , term.generic ) ;
term.cyan( 'Config file: %s\n' , term.termconfigFile ) ;
} ) ;
This will give you the best compatibility possible, at the cost of a callback.
boolean
true if the alternate screen buffer should not be usedBasically, this method try to achieve the same goal than the native terminal capability alternate screen buffer. If alternate screen buffer is disabled on your terminal, it will provide a clean fallback, clearing the screen and positionning the cursor at the upper-left corner.
This function turns input grabbing on, keyboard entries will not be echoed, and every input will generate an event
on the term
object.
Quick example:
var term = require( 'terminal-kit' ) ;
function terminate()
{
term.grabInput( false ) ;
setTimeout( function() { process.exit() } , 100 ) ;
}
term.bold.cyan( 'Type anything on the keyboard...\n' ) ;
term.green( 'Hit CTRL-C to quit.\n\n' ) ;
term.grabInput( { mouse: 'button' } ) ;
term.on( 'key' , function( name , matches , data ) {
console.log( "'key' event:" , name ) ;
if ( matches.indexOf( 'CTRL_C' ) >= 0 ) { terminate() ; }
} ) ;
term.on( 'terminal' , function( name , data ) {
console.log( "'terminal' event:" , name , data ) ;
} ) ;
term.on( 'mouse' , function( name , data ) {
console.log( "'mouse' event:" , name , data ) ;
} ) ;
Event are fired on your term
object.
The 'key' event is emited whenever the user type something on the keyboard.
If name
is a single char, this is a regular UTF8 character, entered by the user.
If the user type a word, each UTF8 character will produce its own 'key' event.
If name
is a multiple chars string, then it is a SPECIAL key.
List of SPECIAL keys:
ESCAPE ENTER BACKSPACE NUL TAB SHIFT_TAB
UP DOWN RIGHT LEFT
INSERT DELETE HOME END PAGE_UP PAGE_DOWN
KP_NUMLOCK KP_DIVIDE KP_MULTIPLY KP_MINUS KP_PLUS KP_DELETE KP_ENTER
KP_0 KP_1 KP_2 KP_3 KP_4 KP_5 KP_6 KP_7 KP_8 KP_9
F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
SHIFT_UP SHIFT_DOWN SHIFT_RIGHT SHIFT_LEFT
ALT_UP ALT_DOWN ALT_RIGHT ALT_LEFT
CTRL_UP CTRL_DOWN CTRL_RIGHT CTRL_LEFT
And modifier on regular A-Z key:
CTRL_A ALT_A CTRL_ALT_A
CTRL_B ALT_B CTRL_ALT_B
CTRL_C ALT_C CTRL_ALT_C
...
Sometime, a key matches multiple combination. For example CTRL-M on linux boxes is always the same as ENTER.
So the event will provide as the 'name' argument the most useful/common, here ENTER.
However the 'matches' argument will contain [ ENTER , CTRL_M ]
.
Also notice that some terminal will support less keys. For example, the Linux Console does not support SHIFT/CTRL/ALT + Arrows keys, it will produce a normal arrow key. There is no workaround here, the underlying keyboard driver simply does not support this.
KP_* keys needs applicationKeypad()
, e.g. without it KP_1 will report '1' or END.
Some terminal does not support applicationKeypad()
at all, sometime turning numlock off can works, sometime not,
so it is nearly impossible to differenciate (for example) a KP_1 from an END, or a KP_7 from a HOME.
The 'terminal' event is emited for terminal generic information.
The argument 'name' can be:
CURSOR_LOCATION: it is emited in response of a requestCursorLocation(), data contains 'x' & 'y', the coordinate of the cursor.
SCREEN_RESIZE: it is emited when a terminal resizing is detected, most of time node.js will be notified of screen resizing, and so this event will be emited, data contains 'width' & 'height', the size of the screen in characters
SCREEN_SIZE: rarely useful it is emited in response of a requestScreenSize(), data contains 'width' & 'height', the size of the screen in characters, and 'resized' (true/false) if the size has changed without node.js being notified
FOCUS_IN: it is emited if the terminal gains focus (if supported by your terminal)
FOCUS_OUT: it is emited if the terminal loses focus (if supported by your terminal)
Activated when grabInput() is used with the 'mouse' options, e.g. { mouse: 'button' }
, { mouse: 'drag' }
or { mouse: 'motion' }
.
The argument 'name' can be:
{ mouse: 'motion' }
is given to grabInput(), every move of the mouse will fire this event,
if { mouse: 'drag' }
is given, it will be fired if the mouse move while a button is pressedFAQs
256 colors, keys and mouse, input field, progress bars, screen buffer (including 32-bit composition and image loading), text buffer, and many more... Whether you just need colors and styles, build a simple interactive command line tool or a complexe termi
The npm package terminal-kit receives a total of 98,239 weekly downloads. As such, terminal-kit popularity was classified as popular.
We found that terminal-kit demonstrated a healthy version release cadence and project activity because the last version was released less than 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
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.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.