feat(runtime): add wrap='hard' mode to Text component
Hard wrap breaks text at exact width boundaries without respecting
word boundaries. Uses wrap-ansi with { hard: true, trim: false }.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user