@native-sdk/cli 0.5.4 → 0.6.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/build/app.zig +50 -1
- package/build.zig +588 -32
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +3 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +280 -8
- package/packages/core/sdk/core.ts +481 -2
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +599 -3
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +39 -2
- package/skill-data/ts-core/SKILL.md +4 -2
- package/src/app_runner/root.zig +32 -10
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +527 -13
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +280 -7
- package/src/platform/macos/appkit_host.h +104 -6
- package/src/platform/macos/appkit_host.m +1368 -74
- package/src/platform/macos/cef_host.mm +110 -1
- package/src/platform/macos/root.zig +287 -7
- package/src/platform/null_platform.zig +398 -4
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +386 -14
- package/src/platform/windows/root.zig +298 -9
- package/src/platform/windows/webview2_host.cpp +330 -5
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +524 -5
- package/src/primitives/canvas/ui_markup.zig +195 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
- package/src/primitives/canvas/ui_markup_contract.zig +88 -5
- package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +149 -0
- package/src/primitives/canvas/ui_markup_view.zig +191 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
- package/src/primitives/canvas/ui_schema.zig +97 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -11
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +16 -0
- package/src/runtime/api.zig +76 -6
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +1 -0
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +268 -26
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +73 -2
- package/src/runtime/effects.zig +6389 -54
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +14 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +25 -4
- package/src/runtime/gpu_surface_events.zig +475 -15
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +25 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_journal.zig +367 -61
- package/src/runtime/session_record.zig +16 -0
- package/src/runtime/session_replay.zig +395 -11
- package/src/runtime/session_tests.zig +114 -19
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/tests.zig +6 -0
- package/src/runtime/ts_core_host.zig +980 -140
- package/src/runtime/ts_core_host_tests.zig +1059 -1
- package/src/runtime/ts_ui_app.zig +16 -5
- package/src/runtime/ui_app.zig +2338 -67
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +268 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_storage.zig +45 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +1 -0
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/templates.zig +25 -7
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
//! Geometric box-drawing: U+2500-259F synthesized as rects, lines, and
|
|
2
|
+
//! arcs at EXACT cell bounds, the way dedicated terminals render them.
|
|
3
|
+
//! Font glyphs are sized to the em box, not the padded cell, so borders
|
|
4
|
+
//! drawn from glyphs show seams between rows and columns; a synthesized
|
|
5
|
+
//! segment runs edge-to-edge and shares the same midline arithmetic in
|
|
6
|
+
//! every cell, so adjacent pieces join seamlessly at any size.
|
|
7
|
+
//!
|
|
8
|
+
//! Coverage: the full light/heavy line set (dashes render solid), the
|
|
9
|
+
//! pure-double lines and corners (corners as two NESTED L joins, the
|
|
10
|
+
//! double frame a terminal face draws), double tees/crosses with the
|
|
11
|
+
//! crossing bar riding through the joint rather than breaking (the one
|
|
12
|
+
//! simplification; mixed single-double variants fall back to their
|
|
13
|
+
//! single shapes), rounded corners as true quarter arcs, diagonals,
|
|
14
|
+
//! half lines, block elements, shades, and quadrants.
|
|
15
|
+
|
|
16
|
+
const std = @import("std");
|
|
17
|
+
const canvas = @import("root.zig");
|
|
18
|
+
const geometry = @import("geometry");
|
|
19
|
+
|
|
20
|
+
pub fn isBoxDrawing(cp: u21) bool {
|
|
21
|
+
return cp >= 0x2500 and cp <= 0x259F;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// A horizontal run of the SAME code point that draws one seamless
|
|
25
|
+
/// full-width piece can merge into a single command.
|
|
26
|
+
pub fn mergesHorizontally(cp: u21) bool {
|
|
27
|
+
return switch (cp) {
|
|
28
|
+
0x2500, 0x2501, 0x2550 => true, // ─ ━ ═
|
|
29
|
+
0x2580...0x2588 => true, // ▀ and the lower blocks ▁..█
|
|
30
|
+
0x2591, 0x2592, 0x2593, 0x2594 => true, // shades and ▔
|
|
31
|
+
else => false,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const Weight = enum { none, light, heavy, double };
|
|
36
|
+
|
|
37
|
+
const Sides = struct {
|
|
38
|
+
up: Weight = .none,
|
|
39
|
+
down: Weight = .none,
|
|
40
|
+
left: Weight = .none,
|
|
41
|
+
right: Weight = .none,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/// The two-bit weight patterns of the U+251C-254B tees and crosses
|
|
45
|
+
/// follow no single formula; explicit tables keep them honest.
|
|
46
|
+
fn lineSides(cp: u21) ?Sides {
|
|
47
|
+
const L = Weight.light;
|
|
48
|
+
const H = Weight.heavy;
|
|
49
|
+
const D = Weight.double;
|
|
50
|
+
return switch (cp) {
|
|
51
|
+
0x2500, 0x254C => .{ .left = L, .right = L }, // ─ ╌
|
|
52
|
+
0x2501, 0x254D => .{ .left = H, .right = H }, // ━ ╍
|
|
53
|
+
0x2502, 0x254E => .{ .up = L, .down = L }, // │ ╎
|
|
54
|
+
0x2503, 0x254F => .{ .up = H, .down = H }, // ┃ ╏
|
|
55
|
+
0x2504, 0x2508 => .{ .left = L, .right = L }, // dashed ─
|
|
56
|
+
0x2505, 0x2509 => .{ .left = H, .right = H }, // dashed ━
|
|
57
|
+
0x2506, 0x250A => .{ .up = L, .down = L }, // dashed │
|
|
58
|
+
0x2507, 0x250B => .{ .up = H, .down = H }, // dashed ┃
|
|
59
|
+
0x250C => .{ .down = L, .right = L }, // ┌
|
|
60
|
+
0x250D => .{ .down = L, .right = H }, // ┍
|
|
61
|
+
0x250E => .{ .down = H, .right = L }, // ┎
|
|
62
|
+
0x250F => .{ .down = H, .right = H }, // ┏
|
|
63
|
+
0x2510 => .{ .down = L, .left = L }, // ┐
|
|
64
|
+
0x2511 => .{ .down = L, .left = H }, // ┑
|
|
65
|
+
0x2512 => .{ .down = H, .left = L }, // ┒
|
|
66
|
+
0x2513 => .{ .down = H, .left = H }, // ┓
|
|
67
|
+
0x2514 => .{ .up = L, .right = L }, // └
|
|
68
|
+
0x2515 => .{ .up = L, .right = H }, // ┕
|
|
69
|
+
0x2516 => .{ .up = H, .right = L }, // ┖
|
|
70
|
+
0x2517 => .{ .up = H, .right = H }, // ┗
|
|
71
|
+
0x2518 => .{ .up = L, .left = L }, // ┘
|
|
72
|
+
0x2519 => .{ .up = L, .left = H }, // ┙
|
|
73
|
+
0x251A => .{ .up = H, .left = L }, // ┚
|
|
74
|
+
0x251B => .{ .up = H, .left = H }, // ┛
|
|
75
|
+
0x251C => .{ .up = L, .down = L, .right = L }, // ├
|
|
76
|
+
0x251D => .{ .up = L, .down = L, .right = H }, // ┝
|
|
77
|
+
0x251E => .{ .up = H, .down = L, .right = L }, // ┞
|
|
78
|
+
0x251F => .{ .up = L, .down = H, .right = L }, // ┟
|
|
79
|
+
0x2520 => .{ .up = H, .down = H, .right = L }, // ┠
|
|
80
|
+
0x2521 => .{ .up = H, .down = L, .right = H }, // ┡
|
|
81
|
+
0x2522 => .{ .up = L, .down = H, .right = H }, // ┢
|
|
82
|
+
0x2523 => .{ .up = H, .down = H, .right = H }, // ┣
|
|
83
|
+
0x2524 => .{ .up = L, .down = L, .left = L }, // ┤
|
|
84
|
+
0x2525 => .{ .up = L, .down = L, .left = H }, // ┥
|
|
85
|
+
0x2526 => .{ .up = H, .down = L, .left = L }, // ┦
|
|
86
|
+
0x2527 => .{ .up = L, .down = H, .left = L }, // ┧
|
|
87
|
+
0x2528 => .{ .up = H, .down = H, .left = L }, // ┨
|
|
88
|
+
0x2529 => .{ .up = H, .down = L, .left = H }, // ┩
|
|
89
|
+
0x252A => .{ .up = L, .down = H, .left = H }, // ┪
|
|
90
|
+
0x252B => .{ .up = H, .down = H, .left = H }, // ┫
|
|
91
|
+
0x252C => .{ .left = L, .right = L, .down = L }, // ┬
|
|
92
|
+
0x252D => .{ .left = H, .right = L, .down = L }, // ┭
|
|
93
|
+
0x252E => .{ .left = L, .right = H, .down = L }, // ┮
|
|
94
|
+
0x252F => .{ .left = H, .right = H, .down = L }, // ┯
|
|
95
|
+
0x2530 => .{ .left = L, .right = L, .down = H }, // ┰
|
|
96
|
+
0x2531 => .{ .left = H, .right = L, .down = H }, // ┱
|
|
97
|
+
0x2532 => .{ .left = L, .right = H, .down = H }, // ┲
|
|
98
|
+
0x2533 => .{ .left = H, .right = H, .down = H }, // ┳
|
|
99
|
+
0x2534 => .{ .left = L, .right = L, .up = L }, // ┴
|
|
100
|
+
0x2535 => .{ .left = H, .right = L, .up = L }, // ┵
|
|
101
|
+
0x2536 => .{ .left = L, .right = H, .up = L }, // ┶
|
|
102
|
+
0x2537 => .{ .left = H, .right = H, .up = L }, // ┷
|
|
103
|
+
0x2538 => .{ .left = L, .right = L, .up = H }, // ┸
|
|
104
|
+
0x2539 => .{ .left = H, .right = L, .up = H }, // ┹
|
|
105
|
+
0x253A => .{ .left = L, .right = H, .up = H }, // ┺
|
|
106
|
+
0x253B => .{ .left = H, .right = H, .up = H }, // ┻
|
|
107
|
+
0x253C => .{ .up = L, .down = L, .left = L, .right = L }, // ┼
|
|
108
|
+
0x253D => .{ .up = L, .down = L, .left = H, .right = L }, // ┽
|
|
109
|
+
0x253E => .{ .up = L, .down = L, .left = L, .right = H }, // ┾
|
|
110
|
+
0x253F => .{ .up = L, .down = L, .left = H, .right = H }, // ┿
|
|
111
|
+
0x2540 => .{ .up = H, .down = L, .left = L, .right = L }, // ╀
|
|
112
|
+
0x2541 => .{ .up = L, .down = H, .left = L, .right = L }, // ╁
|
|
113
|
+
0x2542 => .{ .up = H, .down = H, .left = L, .right = L }, // ╂
|
|
114
|
+
0x2543 => .{ .up = H, .down = L, .left = H, .right = L }, // ╃
|
|
115
|
+
0x2544 => .{ .up = H, .down = L, .left = L, .right = H }, // ╄
|
|
116
|
+
0x2545 => .{ .up = L, .down = H, .left = H, .right = L }, // ╅
|
|
117
|
+
0x2546 => .{ .up = L, .down = H, .left = L, .right = H }, // ╆
|
|
118
|
+
0x2547 => .{ .up = H, .down = L, .left = H, .right = H }, // ╇
|
|
119
|
+
0x2548 => .{ .up = L, .down = H, .left = H, .right = H }, // ╈
|
|
120
|
+
0x2549 => .{ .up = H, .down = H, .left = H, .right = L }, // ╉
|
|
121
|
+
0x254A => .{ .up = H, .down = H, .left = L, .right = H }, // ╊
|
|
122
|
+
0x254B => .{ .up = H, .down = H, .left = H, .right = H }, // ╋
|
|
123
|
+
0x2550 => .{ .left = D, .right = D }, // ═
|
|
124
|
+
0x2551 => .{ .up = D, .down = D }, // ║
|
|
125
|
+
0x2552 => .{ .down = L, .right = D }, // ╒
|
|
126
|
+
0x2553 => .{ .down = D, .right = L }, // ╓
|
|
127
|
+
0x2554 => .{ .down = D, .right = D }, // ╔
|
|
128
|
+
0x2555 => .{ .down = L, .left = D }, // ╕
|
|
129
|
+
0x2556 => .{ .down = D, .left = L }, // ╖
|
|
130
|
+
0x2557 => .{ .down = D, .left = D }, // ╗
|
|
131
|
+
0x2558 => .{ .up = L, .right = D }, // ╘
|
|
132
|
+
0x2559 => .{ .up = D, .right = L }, // ╙
|
|
133
|
+
0x255A => .{ .up = D, .right = D }, // ╚
|
|
134
|
+
0x255B => .{ .up = L, .left = D }, // ╛
|
|
135
|
+
0x255C => .{ .up = D, .left = L }, // ╜
|
|
136
|
+
0x255D => .{ .up = D, .left = D }, // ╝
|
|
137
|
+
0x255E => .{ .up = L, .down = L, .right = D }, // ╞
|
|
138
|
+
0x255F => .{ .up = D, .down = D, .right = L }, // ╟
|
|
139
|
+
0x2560 => .{ .up = D, .down = D, .right = D }, // ╠
|
|
140
|
+
0x2561 => .{ .up = L, .down = L, .left = D }, // ╡
|
|
141
|
+
0x2562 => .{ .up = D, .down = D, .left = L }, // ╢
|
|
142
|
+
0x2563 => .{ .up = D, .down = D, .left = D }, // ╣
|
|
143
|
+
0x2564 => .{ .left = D, .right = D, .down = L }, // ╤
|
|
144
|
+
0x2565 => .{ .left = L, .right = L, .down = D }, // ╥
|
|
145
|
+
0x2566 => .{ .left = D, .right = D, .down = D }, // ╦
|
|
146
|
+
0x2567 => .{ .left = D, .right = D, .up = L }, // ╧
|
|
147
|
+
0x2568 => .{ .left = L, .right = L, .up = D }, // ╨
|
|
148
|
+
0x2569 => .{ .left = D, .right = D, .up = D }, // ╩
|
|
149
|
+
0x256A => .{ .up = L, .down = L, .left = D, .right = D }, // ╪
|
|
150
|
+
0x256B => .{ .up = D, .down = D, .left = L, .right = L }, // ╫
|
|
151
|
+
0x256C => .{ .up = D, .down = D, .left = D, .right = D }, // ╬
|
|
152
|
+
0x2574 => .{ .left = L }, // ╴
|
|
153
|
+
0x2575 => .{ .up = L }, // ╵
|
|
154
|
+
0x2576 => .{ .right = L }, // ╶
|
|
155
|
+
0x2577 => .{ .down = L }, // ╷
|
|
156
|
+
0x2578 => .{ .left = H }, // ╸
|
|
157
|
+
0x2579 => .{ .up = H }, // ╹
|
|
158
|
+
0x257A => .{ .right = H }, // ╺
|
|
159
|
+
0x257B => .{ .down = H }, // ╻
|
|
160
|
+
0x257C => .{ .left = L, .right = H }, // ╼
|
|
161
|
+
0x257D => .{ .up = L, .down = H }, // ╽
|
|
162
|
+
0x257E => .{ .left = H, .right = L }, // ╾
|
|
163
|
+
0x257F => .{ .up = H, .down = L }, // ╿
|
|
164
|
+
else => null,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// Paint one box-drawing cell (or a merged horizontal run of the same
|
|
169
|
+
/// The MOST commands `paint` can emit for one code point — the per-cell
|
|
170
|
+
/// charge the grid painter's row preflight uses, kept adjacent to the
|
|
171
|
+
/// paint switch so the two cannot drift. Pure lines emit one bar (two
|
|
172
|
+
/// for a double), joints emit per side (two per double side), nested
|
|
173
|
+
/// double corners four, rounded corners a path plus its straight run,
|
|
174
|
+
/// the crossing diagonal two, quadrants one rect per lit quarter, and
|
|
175
|
+
/// every block/shade/fraction one.
|
|
176
|
+
pub fn maxCommands(cp: u21) usize {
|
|
177
|
+
if (doubleCorner(cp) != null) return 4;
|
|
178
|
+
if (lineSides(cp)) |sides| {
|
|
179
|
+
// The pure-line shortcuts emit one bar (two for a double).
|
|
180
|
+
if (sides.up == .none and sides.down == .none and sides.left == sides.right and sides.left != .none) {
|
|
181
|
+
return if (sides.left == .double) 2 else 1;
|
|
182
|
+
}
|
|
183
|
+
if (sides.left == .none and sides.right == .none and sides.up == sides.down and sides.up != .none) {
|
|
184
|
+
return if (sides.up == .double) 2 else 1;
|
|
185
|
+
}
|
|
186
|
+
var total: usize = 0;
|
|
187
|
+
for ([_]Weight{ sides.up, sides.down, sides.left, sides.right }) |weight| {
|
|
188
|
+
total += switch (weight) {
|
|
189
|
+
.none => 0,
|
|
190
|
+
.light, .heavy => 1,
|
|
191
|
+
.double => 2,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return total;
|
|
195
|
+
}
|
|
196
|
+
return switch (cp) {
|
|
197
|
+
0x256D, 0x256E, 0x256F, 0x2570 => 2, // arc + straight run
|
|
198
|
+
0x2573 => 2, // the crossing diagonal
|
|
199
|
+
0x2596...0x259F => 3, // at most three lit quarters in the set
|
|
200
|
+
else => 1, // lines, blocks, shades, fractions
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/// A pure-double corner's turn: which vertical and horizontal side the
|
|
205
|
+
/// two nested L joins open toward.
|
|
206
|
+
const DoubleCorner = struct { down: bool, right: bool };
|
|
207
|
+
|
|
208
|
+
fn doubleCorner(cp: u21) ?DoubleCorner {
|
|
209
|
+
return switch (cp) {
|
|
210
|
+
0x2554 => .{ .down = true, .right = true }, // ╔
|
|
211
|
+
0x2557 => .{ .down = true, .right = false }, // ╗
|
|
212
|
+
0x255A => .{ .down = false, .right = true }, // ╚
|
|
213
|
+
0x255D => .{ .down = false, .right = false }, // ╝
|
|
214
|
+
else => null,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/// Two nested L joins: the OUTER horizontal bar (the one on the closed
|
|
219
|
+
/// side of the turn) meets the OUTER vertical bar at the outer
|
|
220
|
+
/// intersection and the inner pair meets at the inner one, so `╔═╗`
|
|
221
|
+
/// renders the double frame a terminal face draws — no bar rides
|
|
222
|
+
/// through the joint, no inward stubs. Four bars, four commands.
|
|
223
|
+
fn paintDoubleCorner(builder: *canvas.Builder, id_base: u64, keyed: bool, rect: geometry.RectF, corner: DoubleCorner, t: f32, color: canvas.Color) !void {
|
|
224
|
+
const cx = rect.x + rect.width / 2;
|
|
225
|
+
const cy = rect.y + rect.height / 2;
|
|
226
|
+
// Bar centerlines: vertical bars at cx +- t, horizontal at cy +- t.
|
|
227
|
+
// The OUTER pair sits opposite the openings (a down+right corner's
|
|
228
|
+
// outer bars are the top horizontal and the left vertical).
|
|
229
|
+
const outer_x = if (corner.right) cx - t else cx + t;
|
|
230
|
+
const inner_x = if (corner.right) cx + t else cx - t;
|
|
231
|
+
const outer_y = if (corner.down) cy - t else cy + t;
|
|
232
|
+
const inner_y = if (corner.down) cy + t else cy - t;
|
|
233
|
+
var id = id_base;
|
|
234
|
+
// Horizontal bars run toward the horizontal opening, starting at
|
|
235
|
+
// their matching vertical bar's far edge so each joint is solid.
|
|
236
|
+
for ([2][2]f32{ .{ outer_y, outer_x }, .{ inner_y, inner_x } }) |pair| {
|
|
237
|
+
const bar_y = pair[0];
|
|
238
|
+
const from_x = pair[1];
|
|
239
|
+
const x0 = if (corner.right) from_x - t / 2 else rect.x;
|
|
240
|
+
const x1 = if (corner.right) rect.x + rect.width else from_x + t / 2;
|
|
241
|
+
try builder.fillRect(.{
|
|
242
|
+
.id = if (keyed) id else 0,
|
|
243
|
+
.rect = geometry.RectF.init(x0, bar_y - t / 2, x1 - x0, t),
|
|
244
|
+
.fill = .{ .color = color },
|
|
245
|
+
});
|
|
246
|
+
id +%= 1;
|
|
247
|
+
}
|
|
248
|
+
// Vertical bars run toward the vertical opening the same way.
|
|
249
|
+
for ([2][2]f32{ .{ outer_x, outer_y }, .{ inner_x, inner_y } }) |pair| {
|
|
250
|
+
const bar_x = pair[0];
|
|
251
|
+
const from_y = pair[1];
|
|
252
|
+
const y0 = if (corner.down) from_y - t / 2 else rect.y;
|
|
253
|
+
const y1 = if (corner.down) rect.y + rect.height else from_y + t / 2;
|
|
254
|
+
try builder.fillRect(.{
|
|
255
|
+
.id = if (keyed) id else 0,
|
|
256
|
+
.rect = geometry.RectF.init(bar_x - t / 2, y0, t, y1 - y0),
|
|
257
|
+
.fill = .{ .color = color },
|
|
258
|
+
});
|
|
259
|
+
id +%= 1;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/// seamless code point) as geometry filling `rect` edge-to-edge. Emits
|
|
264
|
+
/// at most four commands with ids `id_base..id_base+3`; `thickness` is
|
|
265
|
+
/// the light-line weight in canvas points.
|
|
266
|
+
pub fn paint(
|
|
267
|
+
builder: *canvas.Builder,
|
|
268
|
+
id_base: u64,
|
|
269
|
+
rect: geometry.RectF,
|
|
270
|
+
cp: u21,
|
|
271
|
+
color: canvas.Color,
|
|
272
|
+
thickness: f32,
|
|
273
|
+
) !void {
|
|
274
|
+
const t = @max(1, thickness);
|
|
275
|
+
const cx = rect.x + rect.width / 2;
|
|
276
|
+
const cy = rect.y + rect.height / 2;
|
|
277
|
+
// The anonymous-id convention (`widgetPartId` returns 0 for id 0):
|
|
278
|
+
// a zero base emits EVERY command with id 0 — no derived 1..3 ids
|
|
279
|
+
// that would collide across an identity-less grid's cells.
|
|
280
|
+
const keyed = id_base != 0;
|
|
281
|
+
|
|
282
|
+
// Pure-double corners draw as two NESTED L joins — the outer pair of
|
|
283
|
+
// bars turning at the outer intersection, the inner pair at the
|
|
284
|
+
// inner one — the shape a real terminal face draws, instead of both
|
|
285
|
+
// bars riding through the joint (which reads as a hash crossing with
|
|
286
|
+
// inward stubs).
|
|
287
|
+
if (doubleCorner(cp)) |corner| {
|
|
288
|
+
try paintDoubleCorner(builder, id_base, keyed, rect, corner, t, color);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (lineSides(cp)) |sides| {
|
|
293
|
+
var id = id_base;
|
|
294
|
+
// Pure horizontals and verticals emit ONE edge-to-edge bar (two
|
|
295
|
+
// for a double): the common border pieces cost a single command
|
|
296
|
+
// and are seamless by construction.
|
|
297
|
+
if (sides.up == .none and sides.down == .none and sides.left == sides.right and sides.left != .none) {
|
|
298
|
+
_ = try paintSegment(builder, id, keyed, sides.left, t, .{ .x = rect.x, .y = cy, .len = rect.width, .horizontal = true }, color);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (sides.left == .none and sides.right == .none and sides.up == sides.down and sides.up != .none) {
|
|
302
|
+
_ = try paintSegment(builder, id, keyed, sides.up, t, .{ .x = cx, .y = rect.y, .len = rect.height, .horizontal = false }, color);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// Doubles draw as two parallel light lines at center +/- t; the
|
|
306
|
+
// single weights draw one centered bar (heavy at double width).
|
|
307
|
+
// Every segment overlaps the cell center so joints are solid,
|
|
308
|
+
// and runs to the cell edge so neighbors abut exactly.
|
|
309
|
+
if (sides.left != .none) id = try paintSegment(builder, id, keyed, sides.left, t, .{ .x = rect.x, .y = cy, .len = cx - rect.x + barHalf(sides.left, t), .horizontal = true }, color);
|
|
310
|
+
if (sides.right != .none) id = try paintSegment(builder, id, keyed, sides.right, t, .{ .x = cx - barHalf(sides.right, t), .y = cy, .len = rect.x + rect.width - cx + barHalf(sides.right, t), .horizontal = true }, color);
|
|
311
|
+
if (sides.up != .none) id = try paintSegment(builder, id, keyed, sides.up, t, .{ .x = cx, .y = rect.y, .len = cy - rect.y + barHalf(sides.up, t), .horizontal = false }, color);
|
|
312
|
+
if (sides.down != .none) id = try paintSegment(builder, id, keyed, sides.down, t, .{ .x = cx, .y = cy - barHalf(sides.down, t), .len = rect.y + rect.height - cy + barHalf(sides.down, t), .horizontal = false }, color);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
switch (cp) {
|
|
317
|
+
// Rounded corners: a true quarter arc joining the two cell
|
|
318
|
+
// edges through the center, the shape box-heavy TUIs lean on.
|
|
319
|
+
0x256D, 0x256E, 0x256F, 0x2570 => {
|
|
320
|
+
const r = @min(rect.width, rect.height) / 2;
|
|
321
|
+
// Allocated from the builder's OWN path-element store, never
|
|
322
|
+
// a stack local: `strokePath` retains the slice by reference
|
|
323
|
+
// (it never copies), so a stack array would dangle the moment
|
|
324
|
+
// this frame returns and the retained/diffed renderer read it
|
|
325
|
+
// back as overwritten memory.
|
|
326
|
+
const elements = try builder.allocPathElements(3);
|
|
327
|
+
switch (cp) {
|
|
328
|
+
// ╭ bottom edge to right edge
|
|
329
|
+
0x256D => {
|
|
330
|
+
elements[0] = .{ .verb = .move_to, .points = .{ .{ .x = cx, .y = rect.y + rect.height }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
331
|
+
elements[1] = .{ .verb = .line_to, .points = .{ .{ .x = cx, .y = cy + r / 2 }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
332
|
+
elements[2] = .{ .verb = .quad_to, .points = .{ .{ .x = cx, .y = cy }, .{ .x = cx + r / 2, .y = cy }, geometry.PointF.zero() } };
|
|
333
|
+
},
|
|
334
|
+
// ╮ bottom edge to left edge
|
|
335
|
+
0x256E => {
|
|
336
|
+
elements[0] = .{ .verb = .move_to, .points = .{ .{ .x = cx, .y = rect.y + rect.height }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
337
|
+
elements[1] = .{ .verb = .line_to, .points = .{ .{ .x = cx, .y = cy + r / 2 }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
338
|
+
elements[2] = .{ .verb = .quad_to, .points = .{ .{ .x = cx, .y = cy }, .{ .x = cx - r / 2, .y = cy }, geometry.PointF.zero() } };
|
|
339
|
+
},
|
|
340
|
+
// ╯ top edge to left edge
|
|
341
|
+
0x256F => {
|
|
342
|
+
elements[0] = .{ .verb = .move_to, .points = .{ .{ .x = cx, .y = rect.y }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
343
|
+
elements[1] = .{ .verb = .line_to, .points = .{ .{ .x = cx, .y = cy - r / 2 }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
344
|
+
elements[2] = .{ .verb = .quad_to, .points = .{ .{ .x = cx, .y = cy }, .{ .x = cx - r / 2, .y = cy }, geometry.PointF.zero() } };
|
|
345
|
+
},
|
|
346
|
+
// ╰ top edge to right edge
|
|
347
|
+
else => {
|
|
348
|
+
elements[0] = .{ .verb = .move_to, .points = .{ .{ .x = cx, .y = rect.y }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
349
|
+
elements[1] = .{ .verb = .line_to, .points = .{ .{ .x = cx, .y = cy - r / 2 }, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
350
|
+
elements[2] = .{ .verb = .quad_to, .points = .{ .{ .x = cx, .y = cy }, .{ .x = cx + r / 2, .y = cy }, geometry.PointF.zero() } };
|
|
351
|
+
},
|
|
352
|
+
}
|
|
353
|
+
try builder.strokePath(.{ .id = if (keyed) id_base else 0, .elements = elements, .stroke = .{ .fill = .{ .color = color }, .width = t }, .cap = .butt });
|
|
354
|
+
// The straight remainder to the horizontal edge.
|
|
355
|
+
const run: geometry.RectF = switch (cp) {
|
|
356
|
+
0x256D => geometry.RectF.init(cx + r / 2, cy - t / 2, rect.x + rect.width - (cx + r / 2), t),
|
|
357
|
+
0x256E => geometry.RectF.init(rect.x, cy - t / 2, cx - r / 2 - rect.x, t),
|
|
358
|
+
0x256F => geometry.RectF.init(rect.x, cy - t / 2, cx - r / 2 - rect.x, t),
|
|
359
|
+
else => geometry.RectF.init(cx + r / 2, cy - t / 2, rect.x + rect.width - (cx + r / 2), t),
|
|
360
|
+
};
|
|
361
|
+
try builder.fillRect(.{ .id = if (keyed) id_base +% 1 else 0, .rect = run, .fill = .{ .color = color } });
|
|
362
|
+
},
|
|
363
|
+
// Diagonals.
|
|
364
|
+
0x2571 => try builder.drawLine(.{ .id = if (keyed) id_base else 0, .from = .{ .x = rect.x, .y = rect.y + rect.height }, .to = .{ .x = rect.x + rect.width, .y = rect.y }, .stroke = .{ .fill = .{ .color = color }, .width = t } }),
|
|
365
|
+
0x2572 => try builder.drawLine(.{ .id = if (keyed) id_base else 0, .from = .{ .x = rect.x, .y = rect.y }, .to = .{ .x = rect.x + rect.width, .y = rect.y + rect.height }, .stroke = .{ .fill = .{ .color = color }, .width = t } }),
|
|
366
|
+
0x2573 => {
|
|
367
|
+
try builder.drawLine(.{ .id = if (keyed) id_base else 0, .from = .{ .x = rect.x, .y = rect.y + rect.height }, .to = .{ .x = rect.x + rect.width, .y = rect.y }, .stroke = .{ .fill = .{ .color = color }, .width = t } });
|
|
368
|
+
try builder.drawLine(.{ .id = if (keyed) id_base +% 1 else 0, .from = .{ .x = rect.x, .y = rect.y }, .to = .{ .x = rect.x + rect.width, .y = rect.y + rect.height }, .stroke = .{ .fill = .{ .color = color }, .width = t } });
|
|
369
|
+
},
|
|
370
|
+
// Block elements: fractional rects, edge-to-edge.
|
|
371
|
+
0x2580 => try fillFraction(builder, id_base, rect, color, 1, .top, 0.5),
|
|
372
|
+
0x2581...0x2588 => try fillFraction(builder, id_base, rect, color, 1, .bottom, @as(f32, @floatFromInt(cp - 0x2580)) / 8.0),
|
|
373
|
+
0x2589...0x258F => try fillFraction(builder, id_base, rect, color, 1, .left, @as(f32, @floatFromInt(0x2590 - cp)) / 8.0),
|
|
374
|
+
0x2590 => try fillFraction(builder, id_base, rect, color, 1, .right, 0.5),
|
|
375
|
+
0x2591 => try fillFraction(builder, id_base, rect, color, 0.25, .bottom, 1),
|
|
376
|
+
0x2592 => try fillFraction(builder, id_base, rect, color, 0.5, .bottom, 1),
|
|
377
|
+
0x2593 => try fillFraction(builder, id_base, rect, color, 0.75, .bottom, 1),
|
|
378
|
+
0x2594 => try fillFraction(builder, id_base, rect, color, 1, .top, 0.125),
|
|
379
|
+
0x2595 => try fillFraction(builder, id_base, rect, color, 1, .right, 0.125),
|
|
380
|
+
// Quadrants: one rect per lit quarter.
|
|
381
|
+
0x2596...0x259F => {
|
|
382
|
+
const quads: u4 = switch (cp) { // bits: 1=upper-left 2=upper-right 4=lower-left 8=lower-right
|
|
383
|
+
0x2596 => 0b0100, // ▖
|
|
384
|
+
0x2597 => 0b1000, // ▗
|
|
385
|
+
0x2598 => 0b0001, // ▘
|
|
386
|
+
0x2599 => 0b1101, // ▙
|
|
387
|
+
0x259A => 0b1001, // ▚
|
|
388
|
+
0x259B => 0b0111, // ▛
|
|
389
|
+
0x259C => 0b1011, // ▜
|
|
390
|
+
0x259D => 0b0010, // ▝
|
|
391
|
+
0x259E => 0b0110, // ▞
|
|
392
|
+
else => 0b1110, // ▟
|
|
393
|
+
};
|
|
394
|
+
const hw = rect.width / 2;
|
|
395
|
+
const hh = rect.height / 2;
|
|
396
|
+
var id = id_base;
|
|
397
|
+
if (quads & 0b0001 != 0) {
|
|
398
|
+
try builder.fillRect(.{ .id = if (keyed) id else 0, .rect = geometry.RectF.init(rect.x, rect.y, hw, hh), .fill = .{ .color = color } });
|
|
399
|
+
id +%= 1;
|
|
400
|
+
}
|
|
401
|
+
if (quads & 0b0010 != 0) {
|
|
402
|
+
try builder.fillRect(.{ .id = if (keyed) id else 0, .rect = geometry.RectF.init(rect.x + hw, rect.y, hw, hh), .fill = .{ .color = color } });
|
|
403
|
+
id +%= 1;
|
|
404
|
+
}
|
|
405
|
+
if (quads & 0b0100 != 0) {
|
|
406
|
+
try builder.fillRect(.{ .id = if (keyed) id else 0, .rect = geometry.RectF.init(rect.x, rect.y + hh, hw, hh), .fill = .{ .color = color } });
|
|
407
|
+
id +%= 1;
|
|
408
|
+
}
|
|
409
|
+
if (quads & 0b1000 != 0) {
|
|
410
|
+
try builder.fillRect(.{ .id = if (keyed) id else 0, .rect = geometry.RectF.init(rect.x + hw, rect.y + hh, hw, hh), .fill = .{ .color = color } });
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
else => {},
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const Fraction = enum { top, bottom, left, right };
|
|
418
|
+
|
|
419
|
+
fn fillFraction(builder: *canvas.Builder, id: u64, rect: geometry.RectF, color: canvas.Color, opacity: f32, side: Fraction, fraction: f32) !void {
|
|
420
|
+
const shaded = canvas.Color.rgba(color.r, color.g, color.b, color.a * opacity);
|
|
421
|
+
const filled: geometry.RectF = switch (side) {
|
|
422
|
+
.top => geometry.RectF.init(rect.x, rect.y, rect.width, rect.height * fraction),
|
|
423
|
+
.bottom => geometry.RectF.init(rect.x, rect.y + rect.height * (1 - fraction), rect.width, rect.height * fraction),
|
|
424
|
+
.left => geometry.RectF.init(rect.x, rect.y, rect.width * fraction, rect.height),
|
|
425
|
+
.right => geometry.RectF.init(rect.x + rect.width * (1 - fraction), rect.y, rect.width * fraction, rect.height),
|
|
426
|
+
};
|
|
427
|
+
try builder.fillRect(.{ .id = id, .rect = filled, .fill = .{ .color = shaded } });
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const Segment = struct { x: f32, y: f32, len: f32, horizontal: bool };
|
|
431
|
+
|
|
432
|
+
/// The half-extent a crossing bar must overlap at the cell center so
|
|
433
|
+
/// perpendicular joints are solid.
|
|
434
|
+
fn barHalf(weight: Weight, t: f32) f32 {
|
|
435
|
+
return switch (weight) {
|
|
436
|
+
.none => 0,
|
|
437
|
+
.light => t / 2,
|
|
438
|
+
.heavy => t,
|
|
439
|
+
.double => t * 1.5,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
fn paintSegment(builder: *canvas.Builder, id: u64, keyed: bool, weight: Weight, t: f32, seg: Segment, color: canvas.Color) !u64 {
|
|
444
|
+
switch (weight) {
|
|
445
|
+
.none => return id,
|
|
446
|
+
.light, .heavy => {
|
|
447
|
+
const w = if (weight == .heavy) t * 2 else t;
|
|
448
|
+
const rect = if (seg.horizontal)
|
|
449
|
+
geometry.RectF.init(seg.x, seg.y - w / 2, seg.len, w)
|
|
450
|
+
else
|
|
451
|
+
geometry.RectF.init(seg.x - w / 2, seg.y, w, seg.len);
|
|
452
|
+
try builder.fillRect(.{ .id = if (keyed) id else 0, .rect = rect, .fill = .{ .color = color } });
|
|
453
|
+
return id +% 1;
|
|
454
|
+
},
|
|
455
|
+
.double => {
|
|
456
|
+
// Two parallel light bars at center +/- t: pure double runs
|
|
457
|
+
// (═ ║ and the pure-double corners) join seamlessly because
|
|
458
|
+
// every cell computes the same offsets.
|
|
459
|
+
var next = id;
|
|
460
|
+
for ([2]f32{ -t, t }) |offset| {
|
|
461
|
+
const rect = if (seg.horizontal)
|
|
462
|
+
geometry.RectF.init(seg.x, seg.y + offset - t / 2, seg.len, t)
|
|
463
|
+
else
|
|
464
|
+
geometry.RectF.init(seg.x + offset - t / 2, seg.y, t, seg.len);
|
|
465
|
+
try builder.fillRect(.{ .id = if (keyed) next else 0, .rect = rect, .fill = .{ .color = color } });
|
|
466
|
+
next +%= 1;
|
|
467
|
+
}
|
|
468
|
+
return next;
|
|
469
|
+
},
|
|
470
|
+
}
|
|
471
|
+
}
|