Son CV dans un terminal web en Javascript! https://terminal-cv.gregandev.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

68 lines
1.6 KiB

// @flow
import type {BuildProgressEvent} from '@parcel/types';
import path from 'path';
import chalk from 'chalk';
import stringWidth from 'string-width';
import termSize from 'term-size';
import stripAnsi from 'strip-ansi';
export type PadAlign = 'left' | 'right';
let terminalSize = termSize();
process.stdout.on('resize', function() {
terminalSize = termSize();
});
export function getProgressMessage(event: BuildProgressEvent): ?string {
switch (event.phase) {
case 'transforming':
return `Building ${path.basename(event.filePath)}...`;
case 'bundling':
return 'Bundling...';
case 'packaging':
return `Packaging ${event.bundle.displayName}...`;
case 'optimizing':
return `Optimizing ${event.bundle.displayName}...`;
}
return null;
}
export function getTerminalWidth(): any {
return terminalSize;
}
// Pad a string with spaces on either side
export function pad(
text: string,
length: number,
align: PadAlign = 'left',
): string {
let pad = ' '.repeat(length - stringWidth(text));
if (align === 'right') {
return pad + text;
}
return text + pad;
}
export function formatFilename(
filename: string,
color: (s: string) => string = chalk.reset,
): string {
let dir = path.relative(process.cwd(), path.dirname(filename));
return (
chalk.dim(dir + (dir ? path.sep : '')) + color(path.basename(filename))
);
}
export function countLines(message: string): number {
let {columns} = terminalSize;
return stripAnsi(message)
.split('\n')
.reduce((p, line) => p + Math.ceil((stringWidth(line) || 1) / columns), 0);
}