A clean UI library in node.js for the command line
Note: This is still work in progress. Please use it with care!
npm install yacliui
This package supports Node 8 and above
It's a library. So import it into your scripts first:
const ui = require('yacliui')
See the Example Script for more info.
Type: Function
Prints a capitalized green headline with alignment
Type: String
The Headline string to show.
Type: String
Default: left
You can either use left
, center
or right
for the alignment.
ui.headline('Nicely formatted headline')
Type: Function
You can print a simple message with or without a timestamp, status string and colored status code.
Type: String
Type: String|Number
Type: Boolean
ui.message('Message without anything')
ui.message('Message with time code', true)
ui message('Message with time code and status string', '15ms', true)
ui.message('Message with time code and status code (warning)', 301, true)
Type: Function
Shortcut for an info message in white with or without time stamp.
ui.info('Info message in white')
Type: Function
Shortcut for an warning message in yellow with or without time stamp.
ui.warning('Warning message in yellow')
Type: Function
Shortcut for an error message in red with or without time stamp.
ui.error('Error message in red', true) // with time stamp
Type: Function
Shows a message how many items of a specific topic have been found.
Please note that the topic is an array of two strings: The singular
and the plural
! This only works in English since the function automatically uses »has been found« or »have been found«.
Type: Number
The number of items.
Type: Array
An Array of the singular and plural word of the topic, such as:
const topic = ['item', 'items']
ui.found(1, ['apple', 'apples'])
// Output: 1 apple has been found.
ui.found(6, ['apple', 'apples'])
// Output: 6 apples have been found.
Type: Function
This function is basically the same as ui.found()
, but shows how many items of a topic have been found in a number of items in another topic.
The options are the same like in the function above, but twice. You can leave the first topic array empty if you like.
ui.foundof(7, [], 10, ['apple', 'apples'])
// Output: 7 of 10 apples have been found.
ui.foundOf(3, ['piece', 'pieces'], 10, ['apple', 'apples'])
// Output: 3 pieces of 10 apples have been found.
See the Example Script for more info.
Type: Function
Show an array as an unordered or ordered list.
Type: Array
List entries as an array of strings.
Type: Boolean
Default: false
Show an ordered list instead of an unordered one.
ui.list(['first', 'second', 'third'], { ordered: true })
Show a definition list of an array of objects with term and definition:
Type: Array
Definition list entries as an array of objects. The objects contain term
and definition
:
{
term: 'UI',
definition: 'User Interface'
}
Type: Boolean
Default: false
Show an ordered definition list instead of an unordered one. This shows three rows instead of two.
Type: Number
Default: 2
Padding between term and definition.
ui.definitionList([
{
term: 'First term',
definition: 'First definition'
},
{
term: 'First term',
definition: 'First definition'
}
], { padding: 4 })
See the Example Script for more info.
Note: For now I use the popular library Prompts for the input section. I will code this later myself, so there is not another big dependency.
Type: Async Function
Returns: String
Prompts a question and will return either the initial answer or the string the user has put in.
Type: String
The question the user will be asked.
Type: String
The default value of an answer the user can confirm with enter.
(async () => {
var answer = await ui.ask('What is your name?', 'Anonymous')
console.log('Your name is ' + answer + '.')
})()
Type: Async Function
Returns: Boolean
Prompts any question the user can answer with yes
or no
.
Type: String
The question the user will be asked.
Type: Boolean
The default value of an answer the user can confirm with enter.
(async () => {
var pretty = await ui.confirm('Are you pretty?', true)
if (pretty) {
console.log('Yes, you are pretty!')
} else {
console.log('You are ugly as hell!')
}
})()
See the Example Script for more info.
Type: Function
Prints a huge 3x5 font for numbers like temperatue or time. Please note, that this function is still under development!
Type: Number|String
The number to be displayed. Please note that by now only Numbers
are fully functioning!
Type: Number
Default: 4
The maximum of digits to be displayed.
Type: Number
Default: 2
The maximum of decimals to be displayed.
Type: Boolean
Default: true
If this option is true
, the number of displayed characters always stay the same. If a number isn't in range of opts.max_digits
and opts.max_decimals
the number will be rounded within their boundaries.
If opts.fixed
is false
, only opts.max_decimals
will be considered.
Type: String
Default: green
This is the color the whole number will be displayed in. You can use any definition of the color library chalk, e.g. blue.dim
or white.bgRed
.
ui.digits(12.479, {
max_decimals: 2,
color: 'blue.dim'
})