Poorly documented miscellaneous terminal utilities that I use sometimes.
progressBar(width, percent[, characters])
widthCharacter length of barpercentProgress, number between0and1characters(optional) Character set to use, at least 3 characters
// Default progress bar, 10 chars wide @ 50%
const bar1 = tt.progressBar(10, 0.5)
console.log(bar1)
// Different character set
const bar2 = tt.progressBar(10, 0.5, tt.PROGRESS_BAR.PIPS)
console.log(bar2)createAnimatedBar(config)
configProgress bar settings:config.widthCharacter length of barconfig.duration(optional) Animation duration in millisecondsconfig.characters(optional) Character set to use, at least 3 charactersconfig.ease(optional) Easing function to use (default linear)
const bar = tt.createAnimatedBar({
width: 10,
characters: tt.PROGRESS_BAR.FINE,
ease: tt.EASING.CUBIC_OUT,
duration: 500,
})
bar.update(0.25)
console.log(bar.toString())spinner([characters[, speed]])
characters(optional) Character set to usespeed(optional) Time in milliseconds between steps
// Default spinner - automatically steps based on internal clock
const spinner1 = tt.spinner()
console.log(spinner.value)
// Alternative character set and speed (100ms)
const spinner2 = tt.spinner(tt.PROGRESS_SPIN.BRAILLE_LINEAR, 100)
console.log(spinner2.value)barChart(series, config)
seriesArray of numeric valuesconfigBar chart settings:config.widthChart width (characters)config.heightChart height (in lines)config.min(optional) Minimum value to clamp points toconfig.max(optional) Maximum value to clamp points toconfig.characters(optional) Character set to use
const series = [10, 55, 21, 8, 76]
// One-line graph, 10 characters wide
const graph1 = tt.barChart(series, { width: 10, height: 1 })
console.log(graph1[0])
// Custom characters, min/max values
const graph2 = tt.barChart(series, {
width: 10,
height: 5,
min: 0,
max: 100,
characters: tt.GRAPH.BRAILLE,
})
console.log(graph2.join('\n'))createLogBox([config])
configLog box options, all optional:config.heightMaximum number of linesconfig.fadeDurationAnimation duration in millisecondsconfig.fadeDelayDelay before animation starts (milliseconds)config.fadeModeIf set to"succession", messages only begin animating when they're succeeded by anotherconfig.fillIf true, content is initialized with empty lines based onheightconfig.easeCustom easing function to use
// Create a log box with default options
const logBox = tt.createLogBox()
logBox.log('First message!')
// Add another message every second
setInterval(() => logBox.log('Message'), 1000)
// Redraw the log box every 20ms
setInterval(() => {
console.clear()
console.log(logBox.render().join('\n'))
}, 20)drawBox(config)
configBox settings:config.contentArray of strings making up the body of the boxconfig.label(optional) Box title, fit into the borderconfig.labelPosition(optional) Label position ("top" | "bottom")config.width(optional) Fixed outer width of the box in charactersconfig.height(optional) Fixed outer height of the box in linesconfig.vAlign(optional) Vertical alignment of content ("top" | "bottom")config.hAlign(optional) Horizontal alignment of content ("left" | "right")config.characters(optional) Custom character set to use for borders
// Draw a single box
const box = tt.drawBox({
label: 'One',
width: 20,
height: 5,
content: [
'First line',
'Second line',
],
})
console.log(box.join('\n'))
// Draw two boxes side-by-side
const box2 = tt.drawBox({
label: 'Two',
width: 20,
height: 5,
content: [
'Another box!',
],
})
console.log(tt.joinLines(box, box2).join('\n'))