Skip to content

Commit

Permalink
allow houston to line wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Sep 7, 2023
1 parent 04ac311 commit 4c8e088
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-pumpkins-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/cli-kit": patch
---

Allow Houston to line wrap
5 changes: 5 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { say } from './dist/index.js'

await say([
'Hello world lorem ipsum et dolor sic amor sucks to suck mother fucker'
])
9 changes: 6 additions & 3 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 } from '../prompt/util/clear.js';
import { strip, wrap } from '../prompt/util/clear.js';

type Message = string | Promise<string>;

Expand Down Expand Up @@ -49,10 +49,13 @@ 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} ${msg}`,
`${bl}${h.repeat(5)}${br}`,
`${v} ${eye} ${color.cyanBright(mouth)} ${eye} ${message.trimStart()}`,
`${bl}${h.repeat(5)}${br} ${secondMessage.trimStart()}`,
...lines
].join('\n')
};

Expand Down
2 changes: 1 addition & 1 deletion src/prompt/util/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const wrap = (str: string, indent = '', max = process.stdout.columns) =>
for (const raw of words) {
const len = strip(raw).length;
if (i + len > max) {
i = 0;
i = indent.length;
lines.push('\n' + indent, raw);
} else {
lines.push(raw);
Expand Down

0 comments on commit 4c8e088

Please sign in to comment.