Skip to content

Commit

Permalink
feat: improved line wrapping (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
golota60 committed Jun 9, 2021
1 parent 44cdc22 commit 2b91f01
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/consistent-type-assertions": "off",
"unicorn/prefer-node-protocol": "off"
"unicorn/prefer-node-protocol": "off",
"unicorn/no-new-array": "off"
}
},
"bin": {
Expand All @@ -55,13 +56,11 @@
},
"dependencies": {
"chalk": "^2.4.2",
"columnify": "^1.5.4",
"inquirer": "^7.0.0",
"systeminformation": "^5.6.4",
"yargs": "^14.2.0"
},
"devDependencies": {
"@types/columnify": "^1.5.0",
"@types/getos": "^3.0.0",
"@types/inquirer": "^6.5.0",
"@types/jest": "^26.0.23",
Expand Down
77 changes: 46 additions & 31 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os from 'os';
import chalk from 'chalk';
import columnify from 'columnify';
import {RGBColors} from '../interfaces/general';

export const errorMessage =
Expand Down Expand Up @@ -198,20 +197,36 @@ export const returnColoredText = (
}
};

export const printInTwoColumns = (col1: string, col2: string): void => {
const data = [
{
logo: col1,
specs: col2
}
];
console.log(
columnify(data, {
preserveNewLines: true,
config: {logo: {showHeaders: false}, specs: {showHeaders: false}}
})
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-unused-expressions */
export const printInColumns = (...cols: string[]): void => {
// Split every line by \n
const colsSplit = cols.map(element => element.split('\n'));
// Find the vertically longest argument
// Length of which is going the be the iterator on how many times we have to print a line
// eslint-disable-next-line unicorn/no-array-reduce
const verticallyLongestArg = colsSplit.reduce(
(acc, value) => (value.length > acc ? value.length : acc),
0
);
const argsNumber = cols.length;
const mergedArgs = [] as string[];
for (const [i, _] of [...new Array(verticallyLongestArg)].entries()) {
let nextLine = '';
for (const [i2, _2] of [...new Array(argsNumber)].entries()) {
if (nextLine === '') {
colsSplit[i2];
}

nextLine += colsSplit[i2][i];
}

mergedArgs.push(nextLine);
}

// TODO: Improve the algorithm so that it auto adjusts the amount of spaces in every row
console.log(mergedArgs.join('\n'));
};
/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-unused-expressions */

export const printData = (
{logo, data}: {logo: string; data: string},
Expand All @@ -220,7 +235,7 @@ export const printData = (
if (hideLogo) {
console.log(data);
} else {
printInTwoColumns(logo, data);
printInColumns(logo, data);
}
};

Expand Down Expand Up @@ -270,20 +285,20 @@ export const getColoredBoxes = () => {
)}`;
};

export const yayfetchASCII = `-/-\` \`-//-\` \`-/-
-////\` .//////. \`////-
\`/////\` \`:////////:\` \`/////\`
\`/////\` ./////:://///. \`/////\`
\`/////\` -/////. ./////- \`/////\`
./////--://///- -/////:-://///.
./////////////====:////////////.
./////////:=======://///////.
.///////:\` \`:///////.
.//////\` ://///.
./////\` \`/////.
.////:\` \`:////.
.////:\` \`:////.
.////:\` :////.
.////: :////.
-////. .////.
.:/. .:\\.`;
export const yayfetchASCII = `-/-\` \`-//-\` \`-/-
-////\` .//////. \`////-
\`/////\` \`:////////:\` \`/////\`
\`/////\` ./////:://///. \`/////\`
\`/////\` -/////. ./////- \`/////\`
./////--://///- -/////:-://///.
./////////////====:////////////.
./////////:=======://///////.
.///////:\` \`:///////.
.//////\` ://///.
./////\` \`/////.
.////:\` \`:////.
.////:\` \`:////.
.////:\` :////.
.////: :////.
-////. .////.
.:/. .:\\. `;
2 changes: 1 addition & 1 deletion src/yayfetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async function returnPickedData(
}

/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-implicit-any-catch */
const args = yargs
const _args = yargs
.command('$0', '', async () => {
try {
if (yargs.argv.color && yargs.argv.rgb) {
Expand Down

0 comments on commit 2b91f01

Please sign in to comment.