diff --git a/src/commands/executor.ts b/src/commands/executor.ts index 3894372..e3f22a5 100644 --- a/src/commands/executor.ts +++ b/src/commands/executor.ts @@ -5,9 +5,10 @@ export default function createExecutor(functions: any) { const [cmd, ...args] = options; if(cmd in functions) { const toInvoke: (...args: any[]) => void | Promise = functions[cmd as keyof typeof functions]; - await toInvoke(...args); + return await toInvoke(...args); } else { console.log('Unknown command', cmd); + return; } } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 98a2994..3f91f4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,7 +61,7 @@ export const exec = async (s: string, echo = true) => { } } - await executor(...args); + return await executor(...args); }; export const kernel = { @@ -92,7 +92,8 @@ export const kernel = { throw new Error('FUNCTION_DOES_NOT_EXIST_ON_INVOCATION_TARGET'); } const bound = instance.functions[fn].bind(instance.privateScope); - await bound(...args); + const result = await bound(...args); + return result; }, async script(path: string) { const fullPath = resolve(path); @@ -138,9 +139,12 @@ const executor = createExecutor(kernel); serverline.init({ prompt: chalk.cyan('λ ') }); serverline.setCompletion(Object.keys(kernel)); - serverline.on('line', (a: string) => { + serverline.on('line', async (a: string) => { if(a.trim() === "") return; - exec(a, false); + const res = await exec(a, false); + if(res !== undefined) { + console.log(chalk.ansi256(211)('< ' + res)); + } }); serverline.on('SIGINT', () => exec('quit')); console.log('For help, type help'); diff --git a/src/modules/n-arm-bandit/bandit.ts b/src/modules/n-arm-bandit/bandit.ts index 161c525..f254312 100644 --- a/src/modules/n-arm-bandit/bandit.ts +++ b/src/modules/n-arm-bandit/bandit.ts @@ -17,5 +17,5 @@ function randomNormal(width: number = 1, offset: number = 0) { } export function pull() { - console.log(randomNormal(this.config.variance, this.config.base)); + return randomNormal(this.config.variance, this.config.base); } \ No newline at end of file