Skip to content

Commit

Permalink
User input and interface for TexToImage tool
Browse files Browse the repository at this point in the history
  • Loading branch information
HGRgamer committed Jan 13, 2025
1 parent 17c4619 commit 15123ab
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions TexToImage/src/final.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const {latexToImage} = require('./latexToImage');
const readline = require('readline');

function getInput() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

let inputs = {};

return new Promise((resolve, reject) => {
rl.question('Enter the LATEX string: ', (latex) => {
inputs.latex = latex;
rl.question('Enter the output file path: ', (outputPath) => {
inputs.outputPath = outputPath;

rl.question('Enter width (optional): ', (width) => {
inputs.width = width ? parseInt(width) : undefined;

rl.question('Enter height (optional): ', (height) => {
inputs.height = height ? parseInt(height) : undefined;

rl.close();
resolve(inputs);
});
});
});
});
});
}

async function takeUserInput() {
try {
const inputs = await getInput();

const { latex, outputPath, width, height } = inputs;

if (!latex) {
throw new Error('Latex string is required.');
}
if (!outputPath) {
throw new Error('Output file path is required.');
}

await latexToImage(latex, outputPath, { width, height });

console.log(`Image successfully created at ${outputPath}`);
} catch (error) {
console.error('Error:', error.message);
}
}
//for now lets just call the function here
takeUserInput();

module.exports = takeUserInput;

0 comments on commit 15123ab

Please sign in to comment.