-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User input and interface for TexToImage tool
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |