diff --git a/.changeset/flat-pumpkins-accept.md b/.changeset/flat-pumpkins-accept.md new file mode 100644 index 0000000..efe8632 --- /dev/null +++ b/.changeset/flat-pumpkins-accept.md @@ -0,0 +1,5 @@ +--- +"@astrojs/cli-kit": patch +--- + +Allow Houston to line wrap diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..826a992 --- /dev/null +++ b/index.mjs @@ -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' +]) diff --git a/src/messages/index.ts b/src/messages/index.ts index a9f89dc..ca82e38 100644 --- a/src/messages/index.ts +++ b/src/messages/index.ts @@ -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; @@ -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') }; diff --git a/src/prompt/util/clear.ts b/src/prompt/util/clear.ts index 4eabe28..7028148 100644 --- a/src/prompt/util/clear.ts +++ b/src/prompt/util/clear.ts @@ -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);