Skip to content

Commit

Permalink
feat: allow messages to be async
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Sep 7, 2023
1 parent deb9485 commit 171a7fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-jars-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/cli-kit": patch
---

Allow messages to be async
9 changes: 6 additions & 3 deletions src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { random, randomBetween, sleep, useAscii } from '../utils/index.js'
import { action } from '../prompt/util/action.js';
import { strip } from '../prompt/util/clear.js';

export const say = async (messages: string | string[] = [], { clear = false, hat = '', stdin = process.stdin, stdout = process.stdout } = {}) => {
type Message = string | Promise<string>;

export const say = async (msg: Message | Message[] = [], { clear = false, hat = '', stdin = process.stdin, stdout = process.stdout } = {}) => {
const messages = Array.isArray(msg) ? msg : [msg];
const rl = readline.createInterface({ input: stdin, escapeCodeTimeout: 50 });
const logUpdate = createLogUpdate(stdout, { showCursor: false });
readline.emitKeypressEvents(stdin, rl);
Expand Down Expand Up @@ -37,7 +40,6 @@ export const say = async (messages: string | string[] = [], { clear = false, hat
done();
})

const _messages = Array.isArray(messages) ? messages : [messages];
const eyes = useAscii() ? ['•', '•', 'o', 'o', '•', 'O', '^', '•'] : ['●', '●', '●', '●', '●', '○', '○', '•'];
const mouths = useAscii() ? ['•', 'O', '*', 'o', 'o', '•', '-'] : ['•', '○', '■', '▪', '▫', '▬', '▭', '-', '○'];
const walls = useAscii() ? ['—', '|'] : ['─', '│'];
Expand All @@ -54,7 +56,8 @@ export const say = async (messages: string | string[] = [], { clear = false, hat
].join('\n')
};

for (const message of _messages) {
for (let message of messages) {
message = await message
const _message = Array.isArray(message) ? message : message.split(' ');
let msg = [];
let eye = random(eyes);
Expand Down

0 comments on commit 171a7fe

Please sign in to comment.