|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -import fs from 'node:fs' |
4 | | -import { stat, writeFile, unlink } from 'node:fs/promises' |
| 3 | +import { stat, writeFile, unlink, appendFile, readFile } from 'node:fs/promises' |
5 | 4 | import readline from 'node:readline' |
6 | 5 | import Adapter from '../Adapter.mjs' |
7 | 6 | import { TextMessage } from '../Message.mjs' |
@@ -44,15 +43,17 @@ class Shell extends Adapter { |
44 | 43 | robot.logger[level] = async (...args) => { |
45 | 44 | const color = levelColors[level] || '' |
46 | 45 | const msg = `${color}[${level}]${reset} ${args.map(a => typeof a === 'object' ? JSON.stringify(a) : a).join(' ')}` |
47 | | - this.#rl.prompt() |
48 | 46 | await this.send({ user: { name: 'Logger', room: 'Shell' } }, msg) |
49 | 47 | } |
50 | 48 | }) |
| 49 | + this.robot.on('scripts have loaded', () => { |
| 50 | + this.#rl.prompt() |
| 51 | + }) |
51 | 52 | } |
52 | 53 |
|
53 | 54 | async send (envelope, ...strings) { |
54 | | - Array.from(strings).forEach(str => console.log(bold(str))) |
55 | 55 | this.#rl.prompt() |
| 56 | + Array.from(strings).forEach(str => console.log(bold(str))) |
56 | 57 | } |
57 | 58 |
|
58 | 59 | async emote (envelope, ...strings) { |
@@ -120,14 +121,13 @@ class Shell extends Adapter { |
120 | 121 |
|
121 | 122 | this.#rl.on('history', async (history) => { |
122 | 123 | if (history.length === 0) return |
123 | | - await fs.promises.appendFile(historyPath, `${history[0]}\n`) |
| 124 | + await appendFile(historyPath, `${history[0]}\n`) |
124 | 125 | }) |
125 | 126 |
|
126 | | - const existingHistory = (await fs.promises.readFile(historyPath, 'utf8')).split('\n') |
| 127 | + const existingHistory = (await readFile(historyPath, 'utf8')).split('\n') |
127 | 128 | existingHistory.reverse().forEach(line => this.#rl.history.push(line)) |
128 | 129 |
|
129 | 130 | try { |
130 | | - this.#rl.prompt() |
131 | 131 | this.emit('connected', this) |
132 | 132 | } catch (error) { |
133 | 133 | console.log(error) |
|
0 commit comments