From 390d187b978588ff48107e8790e3bc9f1d628888 Mon Sep 17 00:00:00 2001 From: Joey Guerra Date: Fri, 24 May 2024 14:09:18 -0500 Subject: [PATCH] fix(Shell): Sometimes up-arrow wasn't showing history --- src/adapters/Shell.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/adapters/Shell.mjs b/src/adapters/Shell.mjs index 07fa1781e..a8ace1815 100644 --- a/src/adapters/Shell.mjs +++ b/src/adapters/Shell.mjs @@ -76,10 +76,8 @@ class Shell extends Adapter { break } if (input.length > 0) { - fs.appendFileSync(historyPath, `${input}\n`) + this.#rl.history.push(input) } - const history = fs.readFileSync(historyPath, 'utf-8').split('\n').reverse() - this.#rl.history = history let userId = process.env.HUBOT_SHELL_USER_ID || '1' if (userId.match(/A\d+z/)) { userId = parseInt(userId) @@ -89,6 +87,9 @@ class Shell extends Adapter { await this.receive(new TextMessage(user, input, 'messageId')) this.#rl.prompt() }) + this.#rl.on('history', async (history) => { + await fs.promises.writeFile(historyPath, history.reverse().join('\n')) + }) try { this.#rl.prompt() this.emit('connected', this)