@effect-tui/core 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/anim.d.ts +4 -0
- package/dist/anim.d.ts.map +1 -0
- package/dist/anim.js +5 -0
- package/dist/anim.js.map +1 -0
- package/dist/ansi.d.ts +69 -0
- package/dist/ansi.d.ts.map +1 -0
- package/dist/ansi.js +72 -0
- package/dist/ansi.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +18 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +247 -0
- package/dist/keys.js.map +1 -0
- package/dist/layout/linearStack.d.ts +17 -0
- package/dist/layout/linearStack.d.ts.map +1 -0
- package/dist/layout/linearStack.js +86 -0
- package/dist/layout/linearStack.js.map +1 -0
- package/dist/motion-value.d.ts +58 -0
- package/dist/motion-value.d.ts.map +1 -0
- package/dist/motion-value.js +250 -0
- package/dist/motion-value.js.map +1 -0
- package/dist/present/display.d.ts +58 -0
- package/dist/present/display.d.ts.map +1 -0
- package/dist/present/display.js +168 -0
- package/dist/present/display.js.map +1 -0
- package/dist/present/writers/fullscreen.d.ts +19 -0
- package/dist/present/writers/fullscreen.d.ts.map +1 -0
- package/dist/present/writers/fullscreen.js +55 -0
- package/dist/present/writers/fullscreen.js.map +1 -0
- package/dist/present/writers/inline.d.ts +20 -0
- package/dist/present/writers/inline.d.ts.map +1 -0
- package/dist/present/writers/inline.js +92 -0
- package/dist/present/writers/inline.js.map +1 -0
- package/dist/render/buffer.d.ts +31 -0
- package/dist/render/buffer.d.ts.map +1 -0
- package/dist/render/buffer.js +183 -0
- package/dist/render/buffer.js.map +1 -0
- package/dist/render/color-utils.d.ts +18 -0
- package/dist/render/color-utils.d.ts.map +1 -0
- package/dist/render/color-utils.js +58 -0
- package/dist/render/color-utils.js.map +1 -0
- package/dist/render/diff.d.ts +30 -0
- package/dist/render/diff.d.ts.map +1 -0
- package/dist/render/diff.js +83 -0
- package/dist/render/diff.js.map +1 -0
- package/dist/render/measure.d.ts +15 -0
- package/dist/render/measure.d.ts.map +1 -0
- package/dist/render/measure.js +65 -0
- package/dist/render/measure.js.map +1 -0
- package/dist/render/palette.d.ts +46 -0
- package/dist/render/palette.d.ts.map +1 -0
- package/dist/render/palette.js +108 -0
- package/dist/render/palette.js.map +1 -0
- package/dist/render/surface.d.ts +77 -0
- package/dist/render/surface.d.ts.map +1 -0
- package/dist/render/surface.js +198 -0
- package/dist/render/surface.js.map +1 -0
- package/dist/runtime/backend_node.d.ts +36 -0
- package/dist/runtime/backend_node.d.ts.map +1 -0
- package/dist/runtime/backend_node.js +66 -0
- package/dist/runtime/backend_node.js.map +1 -0
- package/dist/spring-physics.d.ts +36 -0
- package/dist/spring-physics.d.ts.map +1 -0
- package/dist/spring-physics.js +113 -0
- package/dist/spring-physics.js.map +1 -0
- package/dist/spring.d.ts +73 -0
- package/dist/spring.d.ts.map +1 -0
- package/dist/spring.js +136 -0
- package/dist/spring.js.map +1 -0
- package/dist/ui/containers/canvas.d.ts +13 -0
- package/dist/ui/containers/canvas.d.ts.map +1 -0
- package/dist/ui/containers/canvas.js +16 -0
- package/dist/ui/containers/canvas.js.map +1 -0
- package/dist/ui/containers/geometry-reader.d.ts +17 -0
- package/dist/ui/containers/geometry-reader.d.ts.map +1 -0
- package/dist/ui/containers/geometry-reader.js +24 -0
- package/dist/ui/containers/geometry-reader.js.map +1 -0
- package/dist/ui/containers/hstack.d.ts +12 -0
- package/dist/ui/containers/hstack.d.ts.map +1 -0
- package/dist/ui/containers/hstack.js +28 -0
- package/dist/ui/containers/hstack.js.map +1 -0
- package/dist/ui/containers/scroll.d.ts +28 -0
- package/dist/ui/containers/scroll.d.ts.map +1 -0
- package/dist/ui/containers/scroll.js +97 -0
- package/dist/ui/containers/scroll.js.map +1 -0
- package/dist/ui/containers/shared.d.ts +12 -0
- package/dist/ui/containers/shared.d.ts.map +1 -0
- package/dist/ui/containers/shared.js +19 -0
- package/dist/ui/containers/shared.js.map +1 -0
- package/dist/ui/containers/vstack.d.ts +12 -0
- package/dist/ui/containers/vstack.d.ts.map +1 -0
- package/dist/ui/containers/vstack.js +28 -0
- package/dist/ui/containers/vstack.js.map +1 -0
- package/dist/ui/containers/zstack.d.ts +14 -0
- package/dist/ui/containers/zstack.d.ts.map +1 -0
- package/dist/ui/containers/zstack.js +36 -0
- package/dist/ui/containers/zstack.js.map +1 -0
- package/dist/ui/core/geometry-store.d.ts +22 -0
- package/dist/ui/core/geometry-store.d.ts.map +1 -0
- package/dist/ui/core/geometry-store.js +29 -0
- package/dist/ui/core/geometry-store.js.map +1 -0
- package/dist/ui/core/geometry.d.ts +34 -0
- package/dist/ui/core/geometry.d.ts.map +1 -0
- package/dist/ui/core/geometry.js +14 -0
- package/dist/ui/core/geometry.js.map +1 -0
- package/dist/ui/core/view.d.ts +25 -0
- package/dist/ui/core/view.d.ts.map +1 -0
- package/dist/ui/core/view.js +34 -0
- package/dist/ui/core/view.js.map +1 -0
- package/dist/ui/index.d.ts +44 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +39 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/inlinetext.d.ts +24 -0
- package/dist/ui/inlinetext.d.ts.map +1 -0
- package/dist/ui/inlinetext.js +131 -0
- package/dist/ui/inlinetext.js.map +1 -0
- package/dist/ui/install.d.ts +22 -0
- package/dist/ui/install.d.ts.map +1 -0
- package/dist/ui/install.js +66 -0
- package/dist/ui/install.js.map +1 -0
- package/dist/ui/markdown.d.ts +40 -0
- package/dist/ui/markdown.d.ts.map +1 -0
- package/dist/ui/markdown.js +351 -0
- package/dist/ui/markdown.js.map +1 -0
- package/dist/ui/modifiers/border.d.ts +33 -0
- package/dist/ui/modifiers/border.d.ts.map +1 -0
- package/dist/ui/modifiers/border.js +82 -0
- package/dist/ui/modifiers/border.js.map +1 -0
- package/dist/ui/modifiers/fill.d.ts +14 -0
- package/dist/ui/modifiers/fill.d.ts.map +1 -0
- package/dist/ui/modifiers/fill.js +25 -0
- package/dist/ui/modifiers/fill.js.map +1 -0
- package/dist/ui/modifiers/frame.d.ts +23 -0
- package/dist/ui/modifiers/frame.d.ts.map +1 -0
- package/dist/ui/modifiers/frame.js +54 -0
- package/dist/ui/modifiers/frame.js.map +1 -0
- package/dist/ui/modifiers/offset.d.ts +15 -0
- package/dist/ui/modifiers/offset.d.ts.map +1 -0
- package/dist/ui/modifiers/offset.js +21 -0
- package/dist/ui/modifiers/offset.js.map +1 -0
- package/dist/ui/modifiers/opacity.d.ts +15 -0
- package/dist/ui/modifiers/opacity.d.ts.map +1 -0
- package/dist/ui/modifiers/opacity.js +95 -0
- package/dist/ui/modifiers/opacity.js.map +1 -0
- package/dist/ui/modifiers/padding.d.ts +20 -0
- package/dist/ui/modifiers/padding.d.ts.map +1 -0
- package/dist/ui/modifiers/padding.js +36 -0
- package/dist/ui/modifiers/padding.js.map +1 -0
- package/dist/ui/modifiers/styled.d.ts +14 -0
- package/dist/ui/modifiers/styled.d.ts.map +1 -0
- package/dist/ui/modifiers/styled.js +26 -0
- package/dist/ui/modifiers/styled.js.map +1 -0
- package/dist/ui/primitives/rectangle.d.ts +15 -0
- package/dist/ui/primitives/rectangle.d.ts.map +1 -0
- package/dist/ui/primitives/rectangle.js +23 -0
- package/dist/ui/primitives/rectangle.js.map +1 -0
- package/dist/ui/primitives/spacer.d.ts +13 -0
- package/dist/ui/primitives/spacer.d.ts.map +1 -0
- package/dist/ui/primitives/spacer.js +16 -0
- package/dist/ui/primitives/spacer.js.map +1 -0
- package/dist/ui/primitives/text.d.ts +15 -0
- package/dist/ui/primitives/text.d.ts.map +1 -0
- package/dist/ui/primitives/text.js +79 -0
- package/dist/ui/primitives/text.js.map +1 -0
- package/dist/ui/primitives/wrapped-text.d.ts +30 -0
- package/dist/ui/primitives/wrapped-text.d.ts.map +1 -0
- package/dist/ui/primitives/wrapped-text.js +117 -0
- package/dist/ui/primitives/wrapped-text.js.map +1 -0
- package/dist/ui/shinytext.d.ts +66 -0
- package/dist/ui/shinytext.d.ts.map +1 -0
- package/dist/ui/shinytext.js +99 -0
- package/dist/ui/shinytext.js.map +1 -0
- package/dist/ui/text/layout.d.ts +35 -0
- package/dist/ui/text/layout.d.ts.map +1 -0
- package/dist/ui/text/layout.js +102 -0
- package/dist/ui/text/layout.js.map +1 -0
- package/dist/ui/textinput.d.ts +140 -0
- package/dist/ui/textinput.d.ts.map +1 -0
- package/dist/ui/textinput.js +402 -0
- package/dist/ui/textinput.js.map +1 -0
- package/dist/ui/view-constructors.d.ts +72 -0
- package/dist/ui/view-constructors.d.ts.map +1 -0
- package/dist/ui/view-constructors.js +74 -0
- package/dist/ui/view-constructors.js.map +1 -0
- package/package.json +57 -0
- package/src/anim.ts +5 -0
- package/src/ansi.ts +83 -0
- package/src/index.ts +21 -0
- package/src/keys.ts +302 -0
- package/src/layout/linearStack.ts +115 -0
- package/src/motion-value.ts +335 -0
- package/src/present/display.ts +206 -0
- package/src/present/writers/fullscreen.ts +58 -0
- package/src/present/writers/inline.ts +101 -0
- package/src/render/buffer.ts +200 -0
- package/src/render/color-utils.ts +60 -0
- package/src/render/diff.ts +95 -0
- package/src/render/measure.ts +74 -0
- package/src/render/palette.ts +113 -0
- package/src/render/surface.ts +238 -0
- package/src/runtime/backend_node.ts +80 -0
- package/src/spring-physics.ts +151 -0
- package/src/spring.ts +234 -0
- package/src/ui/__snapshots__/wrappedtext.test.ts.snap +57 -0
- package/src/ui/containers/canvas.ts +18 -0
- package/src/ui/containers/geometry-reader.ts +32 -0
- package/src/ui/containers/hstack.ts +33 -0
- package/src/ui/containers/scroll.ts +106 -0
- package/src/ui/containers/shared.ts +27 -0
- package/src/ui/containers/vstack.ts +34 -0
- package/src/ui/containers/zstack.ts +37 -0
- package/src/ui/core/geometry-store.ts +42 -0
- package/src/ui/core/geometry.ts +30 -0
- package/src/ui/core/view.ts +49 -0
- package/src/ui/index.ts +84 -0
- package/src/ui/inlinetext.ts +135 -0
- package/src/ui/install.ts +110 -0
- package/src/ui/markdown.test.ts +74 -0
- package/src/ui/markdown.ts +388 -0
- package/src/ui/modifiers/border.ts +100 -0
- package/src/ui/modifiers/fill.ts +28 -0
- package/src/ui/modifiers/frame.ts +74 -0
- package/src/ui/modifiers/offset.ts +23 -0
- package/src/ui/modifiers/opacity.ts +93 -0
- package/src/ui/modifiers/padding.ts +53 -0
- package/src/ui/modifiers/styled.ts +31 -0
- package/src/ui/primitives/rectangle.ts +25 -0
- package/src/ui/primitives/spacer.ts +18 -0
- package/src/ui/primitives/text.ts +85 -0
- package/src/ui/primitives/wrapped-text.ts +131 -0
- package/src/ui/shinytext.ts +159 -0
- package/src/ui/text/layout.ts +119 -0
- package/src/ui/textinput.ts +496 -0
- package/src/ui/view-constructors.ts +96 -0
- package/src/ui/wrappedtext.test.ts +138 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
+
import { Surface, Palette } from "../render/surface"
|
|
3
|
+
import { WrappedText } from "./primitives/wrapped-text"
|
|
4
|
+
|
|
5
|
+
describe("WrappedText", () => {
|
|
6
|
+
describe("basic word wrapping", () => {
|
|
7
|
+
it("should wrap text at word boundaries", () => {
|
|
8
|
+
const node = new WrappedText("hello world test", { wordWrap: true })
|
|
9
|
+
const surface = new Surface(8, 3)
|
|
10
|
+
const palette = new Palette()
|
|
11
|
+
|
|
12
|
+
// Measure should calculate height based on wrapped lines
|
|
13
|
+
const measure = node.measure(8, 10)
|
|
14
|
+
expect(measure.w).toBe(8) // Takes full width available
|
|
15
|
+
expect(measure.h).toBe(3) // "hello world" splits into 3 lines at width 8
|
|
16
|
+
|
|
17
|
+
// Render and check output
|
|
18
|
+
node.render(surface, palette, { x: 0, y: 0, w: 8, h: 3 })
|
|
19
|
+
const output = surface.toString()
|
|
20
|
+
|
|
21
|
+
expect(output).toMatchSnapshot()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it("should handle single words longer than width", () => {
|
|
25
|
+
const node = new WrappedText("verylongword", { wordWrap: true, breakWords: true })
|
|
26
|
+
const surface = new Surface(6, 3)
|
|
27
|
+
const palette = new Palette()
|
|
28
|
+
|
|
29
|
+
const measure = node.measure(6, 10)
|
|
30
|
+
expect(measure.w).toBe(6)
|
|
31
|
+
expect(measure.h).toBe(2) // "verylo" + "ngword"
|
|
32
|
+
|
|
33
|
+
node.render(surface, palette, { x: 0, y: 0, w: 6, h: 3 })
|
|
34
|
+
const output = surface.toString()
|
|
35
|
+
|
|
36
|
+
expect(output).toMatchSnapshot()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("should preserve explicit line breaks", () => {
|
|
40
|
+
const node = new WrappedText("line1\nline2\nline3")
|
|
41
|
+
const surface = new Surface(10, 5)
|
|
42
|
+
const palette = new Palette()
|
|
43
|
+
|
|
44
|
+
const measure = node.measure(10, 10)
|
|
45
|
+
expect(measure.w).toBe(10) // Takes full width available
|
|
46
|
+
expect(measure.h).toBe(3) // 3 lines from explicit breaks
|
|
47
|
+
|
|
48
|
+
node.render(surface, palette, { x: 0, y: 0, w: 10, h: 5 })
|
|
49
|
+
const output = surface.toString()
|
|
50
|
+
|
|
51
|
+
expect(output).toMatchSnapshot()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe("measurement calculations", () => {
|
|
56
|
+
it("should calculate height correctly for wrapped text", () => {
|
|
57
|
+
const node = new WrappedText("a b c d e f g h")
|
|
58
|
+
|
|
59
|
+
// At width 3, should wrap to multiple lines
|
|
60
|
+
const measure3 = node.measure(3, 10)
|
|
61
|
+
expect(measure3.h).toBeGreaterThan(1)
|
|
62
|
+
|
|
63
|
+
// At width 20, should fit on one line
|
|
64
|
+
const measure20 = node.measure(20, 10)
|
|
65
|
+
expect(measure20.h).toBe(1)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("should respect max height constraint", () => {
|
|
69
|
+
const node = new WrappedText("a b c d e f g h i j k l m n")
|
|
70
|
+
|
|
71
|
+
const measure = node.measure(3, 2) // force to 2 lines max
|
|
72
|
+
expect(measure.h).toBe(2)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe("wrapping strategies", () => {
|
|
77
|
+
it("should default to word wrap", () => {
|
|
78
|
+
const node = new WrappedText("hello world")
|
|
79
|
+
const surface = new Surface(8, 2)
|
|
80
|
+
const palette = new Palette()
|
|
81
|
+
|
|
82
|
+
node.render(surface, palette, { x: 0, y: 0, w: 8, h: 2 })
|
|
83
|
+
const output = surface.toString()
|
|
84
|
+
|
|
85
|
+
// Should break at word boundary, not in middle of "world"
|
|
86
|
+
expect(output).toContain("hello")
|
|
87
|
+
expect(output).toContain("world")
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it("should break words when breakWords is enabled", () => {
|
|
91
|
+
const node = new WrappedText("supercalifragilisticexpialidocious", {
|
|
92
|
+
wordWrap: true,
|
|
93
|
+
breakWords: true,
|
|
94
|
+
})
|
|
95
|
+
const surface = new Surface(10, 5)
|
|
96
|
+
const palette = new Palette()
|
|
97
|
+
|
|
98
|
+
const measure = node.measure(10, 10)
|
|
99
|
+
expect(measure.h).toBeGreaterThan(1)
|
|
100
|
+
|
|
101
|
+
node.render(surface, palette, { x: 0, y: 0, w: 10, h: 5 })
|
|
102
|
+
const output = surface.toString()
|
|
103
|
+
|
|
104
|
+
expect(output).toMatchSnapshot()
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it("should handle empty text", () => {
|
|
108
|
+
const node = new WrappedText("")
|
|
109
|
+
const surface = new Surface(10, 1)
|
|
110
|
+
const palette = new Palette()
|
|
111
|
+
|
|
112
|
+
const measure = node.measure(10, 10)
|
|
113
|
+
expect(measure.w).toBe(10) // Takes full width available
|
|
114
|
+
expect(measure.h).toBe(1) // Always at least 1 line
|
|
115
|
+
|
|
116
|
+
node.render(surface, palette, { x: 0, y: 0, w: 10, h: 1 })
|
|
117
|
+
const output = surface.toString()
|
|
118
|
+
|
|
119
|
+
// Empty text should render as empty string (no content)
|
|
120
|
+
expect(output).toBe("")
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
describe("styling", () => {
|
|
125
|
+
it("should apply styles to wrapped text", () => {
|
|
126
|
+
const node = new WrappedText("hello world", { wordWrap: true }).fg("red").bold(true)
|
|
127
|
+
|
|
128
|
+
const surface = new Surface(8, 3)
|
|
129
|
+
const palette = new Palette()
|
|
130
|
+
|
|
131
|
+
node.render(surface, palette, { x: 0, y: 0, w: 8, h: 3 })
|
|
132
|
+
|
|
133
|
+
// Check that style was applied (we can't easily test SGR codes in snapshots,
|
|
134
|
+
// but this ensures the style system is integrated)
|
|
135
|
+
expect(node).toBeDefined()
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|