Skip to content

Commit

Permalink
fix: nested promises, revert wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Sep 7, 2023
1 parent 0052be1 commit 98fe7c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-goats-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/cli-kit": patch
---

Fix nested promises in `say`
5 changes: 5 additions & 0 deletions .changeset/polite-deers-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/cli-kit": patch
---

Revert Houston wrapping
15 changes: 7 additions & 8 deletions src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import color from 'chalk';
import { createLogUpdate } from 'log-update';
import { random, randomBetween, sleep, useAscii } from '../utils/index.js'
import { action } from '../prompt/util/action.js';
import { strip, wrap } from '../prompt/util/clear.js';
import { strip } from '../prompt/util/clear.js';

type Message = string | Promise<string>;

Expand Down Expand Up @@ -49,13 +49,10 @@ export const say = async (msg: Message | Message[] = [], { clear = false, hat =
const [h, v] = walls;
const [tl, tr, bl, br] = corners;
const head = h.repeat(3 - strip(hat).split('').length);
const prefix = ' '.repeat(9);
const [message, secondMessage = '', ...lines] = wrap(`${prefix}${msg}`, prefix).split('\n');
return [
`${tl}${h.repeat(2)}${hat}${head}${tr} ${color.bold(color.cyan('Houston:'))}`,
`${v} ${eye} ${color.cyanBright(mouth)} ${eye} ${message.trimStart()}`,
`${bl}${h.repeat(5)}${br} ${secondMessage.trimStart()}`,
...lines
`${v} ${eye} ${color.cyanBright(mouth)} ${eye} ${msg}`,
`${bl}${h.repeat(5)}${br}`,
].join('\n')
};

Expand All @@ -65,7 +62,8 @@ export const say = async (msg: Message | Message[] = [], { clear = false, hat =
let msg = [];
let eye = random(eyes);
let j = 0;
for (const word of [''].concat(_message)) {
for (let word of [''].concat(_message)) {
word = await word;
if (word) msg.push(word);
const mouth = random(mouths);
if (j % 7 === 0) eye = random(eyes);
Expand All @@ -75,7 +73,8 @@ export const say = async (msg: Message | Message[] = [], { clear = false, hat =
j++;
}
if (!cancelled) await sleep(100);
const text = '\n' + face(_message.join(' '), { mouth: useAscii() ? 'u' : '◡', eye: useAscii() ? '^' : '◠' });
const tmp = await Promise.all(_message).then(res => res.join(' '))
const text = '\n' + face(tmp, { mouth: useAscii() ? 'u' : '◡', eye: useAscii() ? '^' : '◠' });
logUpdate(text);
if (!cancelled) await sleep(randomBetween(1200, 1400));
i++;
Expand Down

0 comments on commit 98fe7c3

Please sign in to comment.