diff --git a/packages/runtime/src/components/Text.ts b/packages/runtime/src/components/Text.ts index ffd7dd9..f1ebdf9 100644 --- a/packages/runtime/src/components/Text.ts +++ b/packages/runtime/src/components/Text.ts @@ -1,7 +1,13 @@ import { defineComponent, getCurrentInstance, h, type PropType } from "vue"; type Color = string | [number, number, number]; -type WrapMode = "wrap" | "truncate" | "truncate-end" | "truncate-middle" | "truncate-start"; +type WrapMode = + | "wrap" + | "hard" + | "truncate" + | "truncate-end" + | "truncate-middle" + | "truncate-start"; export const Text = defineComponent({ name: "Text", diff --git a/packages/runtime/src/host/nodes.ts b/packages/runtime/src/host/nodes.ts index df1b5e8..9cce9a7 100644 --- a/packages/runtime/src/host/nodes.ts +++ b/packages/runtime/src/host/nodes.ts @@ -16,7 +16,7 @@ export interface TextProps { underline?: boolean; strikethrough?: boolean; inverse?: boolean; - wrap?: "wrap" | "truncate" | "truncate-end" | "truncate-middle" | "truncate-start"; + wrap?: "wrap" | "hard" | "truncate" | "truncate-end" | "truncate-middle" | "truncate-start"; } interface NodeBase { diff --git a/packages/runtime/src/host/text-measure.ts b/packages/runtime/src/host/text-measure.ts index 7ca0533..bb4a0ac 100644 --- a/packages/runtime/src/host/text-measure.ts +++ b/packages/runtime/src/host/text-measure.ts @@ -24,6 +24,10 @@ export function wrapText(text: string, width: number, mode: WrapMode = "wrap"): return wrapAnsi(text, width, { hard: true, trim: true, wordWrap: true }).split("\n"); } + if (mode === "hard") { + return wrapAnsi(text, width, { hard: true, trim: false }).split("\n"); + } + // truncate variants: collapse newlines, then slice from the appropriate side. const single = text.replace(/\n/g, " "); if (stringWidth(single) <= width) return [single];