Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// output 'mixed' using bold, underlined & red, exposing the style-mixing syntax
term.bold.underline.red("mixed");
// printf() style formatting 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);
// Since v0.16.x, style markup are supported as a shorthand.
// Those two lines produce the same result.
term("My name is ")
.red("Jack")(" and I'm ")
.green("32\n");
term("My name is ^rJack^ and I'm ^g32\n");
// 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 additional 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);
// Get some user input
term.magenta("Enter your name: ");
term.inputField((error: any, input: any) => {
(async () => {
for await (const snapshot of renderToString(
{element}
,
{
width: terminal.width,
}
).start()) {
dynamicContentSnapshot = snapshot || '';
if (dynamicContentFirstRender) {
dynamicContentFirstRender = false;
terminal(snapshot);
const { y } = await getCursorLocation();
dynamicContentBottom = y;
} else {
const dynamicConentHeight = (snapshot || '').split('\n').length;
dynamicContentTop = dynamicContentBottom - dynamicConentHeight + 1;
terminal.moveTo(0, dynamicContentTop);
terminal.eraseDisplayBelow();
terminal(snapshot);
const { y } = await getCursorLocation();
// eslint-disable-next-line require-atomic-updates
return;
}
hasPrinted.add(entry);
const cat = categories[entry.category];
term.colorRgb(...cat.color)(`${cat.name} `);
term.colorRgb(255, 255, 255)(`${entry.text}\n`);
});
if (bottomBar !== true) {
return;
}
// Set up bottom bar
const titleText = ` ${title.text} `;
const statusText = ` ${status.text} `;
const neededSpacing = term.width - titleText.length - statusText.length;
let spacing = "";
while (spacing.length < neededSpacing) {
spacing += " ";
}
term("\n");
term.up(1);
term.down(1);
term.underline.colorRgb(...title.color)(titleText);
term.underline.colorRgb(255, 255, 255)(spacing);
term.underline.colorRgb(...status.color)(statusText);
term.up(1);
term.column(1);
term.styleReset();
});
}
const padLine = ( text, char = ' ' ) => {
return `${ padEnd( text, term.width, char ) }\n`;
};
function reflowAndDiff(container: View, renderer: Renderer) {
container.setLayoutStyle({ width: '100%', height: '100%' });
const layout = container.layoutNode.computeLayout({
width: terminal.width,
height: terminal.height,
});
container.notifyOnLayoutHook(layout, { offsetX: 0, offsetY: 0 });
return renderer.renderDiff(container, layout);
}
companyBarContentArray.forEach(item => {
const newString = item.trim() + " "
if (barContentString.length + newString.length > term.width) {
companyBarContent += barContentString + "\n"
barContentString = newString.trim()
} else {
barContentString += item.trim() + " "
}
})
companyBarContent += barContentString
x: 1,
y: 0,
wrap: false,
attr: theme.header.title,
};
let title = get_title();
b_header.put(options, title);
options.x = options.x + title.length;
options.attr = theme.header.standard;
b_header.put(options, ' v%s', VERSION);
let w_label = 'W:';
let w = String(term.width);
let h_label = ' H:';
let h = String(term.height);
let node_env_label = 'NODE_ENV: ';
let node_env = String(process.env.NODE_ENV);
let all = w_label + w + h_label + h + theme.header.seperator.char + node_env_label + node_env;
options.x = justify_r(term, all) - 1;
options.attr = theme.header.label;
b_header.put(options, w_label);
options.x = options.x + w_label.length;
options.attr = theme.header.standard;
b_header.put(options, w);
options.x = options.x + w.length;
playerBarContentArray.forEach(item => {
const newString = " " + item.trim()
if (barContentString.length + newString.length > term.width) {
playerBarContent += barContentString + "\n"
barContentString = newString.trim()
} else {
barContentString += " " + item.trim()
}
})
playerBarContent += barContentString
function cropLine(line) {
return line.slice(0, term.width);
}