const calcDb = db('calc', {history: []});
function createResult(calculationResult, input) {
return {name: calculationResult, description: input, value: {calculationResult, input}}
}
const {calculationResult, input, ...rest} = await arg("calculate:", async (input) => {
const choices = [];
if (input) {
choices.push(createResult((await exec(`bc <<<"${input.replace(/\,/g, ".")}" -l`)).replace(/^\./, "0."), input))
}
return choices.concat(calcDb.get('history').value())
})
if (calculationResult) {
const history = calcDb.get('history').value();
history.unshift(createResult(calculationResult, input));
calcDb.set('history', history.filter(({description}, index) => index === 0 || description !== input).slice(0, 10)).write()
}
copy(calculationResult)