ratatui_ruby 0.8.0 → 0.9.0

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.
Files changed (352) hide show
  1. checksums.yaml +4 -4
  2. data/.builds/ruby-3.2.yml +2 -2
  3. data/.builds/ruby-3.3.yml +2 -2
  4. data/.builds/ruby-3.4.yml +2 -2
  5. data/.builds/ruby-4.0.0.yml +2 -2
  6. data/.pre-commit-config.yaml +1 -1
  7. data/AGENTS.md +3 -3
  8. data/CHANGELOG.md +53 -1
  9. data/LICENSES/LGPL-3.0-or-later.txt +304 -0
  10. data/LICENSES/MIT-0.txt +16 -0
  11. data/README.md +33 -5
  12. data/Rakefile +1 -1
  13. data/doc/concepts/application_architecture.md +44 -3
  14. data/doc/concepts/application_testing.md +43 -1
  15. data/doc/concepts/async.md +32 -2
  16. data/doc/concepts/custom_widgets.md +247 -0
  17. data/doc/concepts/event_handling.md +32 -3
  18. data/doc/concepts/interactive_design.md +32 -2
  19. data/doc/contributors/auditing/parity.md +7 -1
  20. data/doc/contributors/design/ruby_frontend.md +85 -1
  21. data/doc/contributors/design/rust_backend.md +67 -1
  22. data/doc/contributors/developing_examples.md +56 -2
  23. data/doc/contributors/documentation_style.md +20 -3
  24. data/doc/contributors/future_work.md +169 -0
  25. data/doc/contributors/index.md +1 -1
  26. data/doc/contributors/v1.0.0_blockers.md +15 -175
  27. data/doc/getting_started/quickstart.md +22 -4
  28. data/doc/getting_started/why.md +1 -1
  29. data/doc/index.md +2 -1
  30. data/doc/troubleshooting/debugging.md +32 -2
  31. data/doc/troubleshooting/terminal_limitations.md +8 -2
  32. data/doc/troubleshooting/tui_output.md +42 -0
  33. data/examples/app_all_events/README.md +14 -2
  34. data/examples/app_all_events/app.rb +1 -1
  35. data/examples/app_all_events/model/app_model.rb +1 -1
  36. data/examples/app_all_events/model/event_color_cycle.rb +1 -1
  37. data/examples/app_all_events/model/event_entry.rb +1 -1
  38. data/examples/app_all_events/model/msg.rb +1 -1
  39. data/examples/app_all_events/model/timestamp.rb +1 -1
  40. data/examples/app_all_events/update.rb +1 -1
  41. data/examples/app_all_events/view/app_view.rb +1 -1
  42. data/examples/app_all_events/view/controls_view.rb +1 -1
  43. data/examples/app_all_events/view/counts_view.rb +1 -1
  44. data/examples/app_all_events/view/live_view.rb +1 -1
  45. data/examples/app_all_events/view/log_view.rb +1 -1
  46. data/examples/app_all_events/view.rb +1 -1
  47. data/examples/app_color_picker/README.md +20 -2
  48. data/examples/app_color_picker/app.rb +1 -1
  49. data/examples/app_color_picker/clipboard.rb +1 -1
  50. data/examples/app_color_picker/color.rb +1 -1
  51. data/examples/app_color_picker/controls.rb +1 -1
  52. data/examples/app_color_picker/copy_dialog.rb +1 -1
  53. data/examples/app_color_picker/export_pane.rb +1 -1
  54. data/examples/app_color_picker/harmony.rb +1 -1
  55. data/examples/app_color_picker/input.rb +1 -1
  56. data/examples/app_color_picker/main_container.rb +1 -1
  57. data/examples/app_color_picker/palette.rb +1 -1
  58. data/examples/app_login_form/README.md +8 -2
  59. data/examples/app_login_form/app.rb +1 -1
  60. data/examples/app_stateful_interaction/README.md +2 -2
  61. data/examples/app_stateful_interaction/app.rb +71 -17
  62. data/examples/timeout_demo.rb +1 -1
  63. data/examples/verify_quickstart_dsl/README.md +6 -0
  64. data/examples/verify_quickstart_dsl/app.rb +3 -3
  65. data/examples/verify_quickstart_layout/README.md +6 -0
  66. data/examples/verify_quickstart_layout/app.rb +3 -3
  67. data/examples/verify_quickstart_lifecycle/README.md +6 -0
  68. data/examples/verify_quickstart_lifecycle/app.rb +3 -3
  69. data/examples/verify_readme_usage/README.md +6 -0
  70. data/examples/verify_readme_usage/app.rb +3 -3
  71. data/examples/widget_barchart/README.md +6 -0
  72. data/examples/widget_barchart/app.rb +2 -2
  73. data/examples/widget_block/README.md +7 -1
  74. data/examples/widget_block/app.rb +2 -2
  75. data/examples/widget_box/README.md +6 -0
  76. data/examples/widget_box/app.rb +9 -6
  77. data/examples/widget_calendar/README.md +6 -0
  78. data/examples/widget_calendar/app.rb +2 -2
  79. data/examples/widget_canvas/README.md +4 -0
  80. data/examples/widget_canvas/app.rb +2 -2
  81. data/examples/widget_cell/README.md +6 -0
  82. data/examples/widget_cell/app.rb +2 -3
  83. data/examples/widget_center/README.md +4 -0
  84. data/examples/widget_center/app.rb +2 -2
  85. data/examples/widget_chart/README.md +6 -0
  86. data/examples/widget_chart/app.rb +2 -2
  87. data/examples/widget_gauge/README.md +6 -0
  88. data/examples/widget_gauge/app.rb +2 -2
  89. data/examples/widget_layout_split/README.md +6 -0
  90. data/examples/widget_layout_split/app.rb +3 -3
  91. data/examples/widget_line_gauge/README.md +6 -0
  92. data/examples/widget_line_gauge/app.rb +2 -2
  93. data/examples/widget_list/README.md +6 -0
  94. data/examples/widget_list/app.rb +2 -2
  95. data/examples/widget_map/README.md +8 -2
  96. data/examples/widget_map/app.rb +2 -2
  97. data/examples/widget_overlay/README.md +7 -1
  98. data/examples/widget_overlay/app.rb +2 -2
  99. data/examples/widget_popup/README.md +6 -0
  100. data/examples/widget_popup/app.rb +2 -2
  101. data/examples/widget_ratatui_logo/README.md +6 -0
  102. data/examples/widget_ratatui_logo/app.rb +2 -3
  103. data/examples/widget_ratatui_mascot/README.md +6 -0
  104. data/examples/widget_ratatui_mascot/app.rb +2 -2
  105. data/examples/widget_rect/README.md +12 -0
  106. data/examples/widget_rect/app.rb +40 -26
  107. data/examples/widget_render/README.md +6 -0
  108. data/examples/widget_render/app.rb +2 -2
  109. data/examples/widget_render/app.rbs +41 -0
  110. data/examples/widget_rich_text/README.md +6 -0
  111. data/examples/widget_rich_text/app.rb +2 -2
  112. data/examples/widget_scroll_text/README.md +6 -0
  113. data/examples/widget_scroll_text/app.rb +2 -2
  114. data/examples/widget_scrollbar/README.md +6 -0
  115. data/examples/widget_scrollbar/app.rb +2 -2
  116. data/examples/widget_sparkline/README.md +6 -0
  117. data/examples/widget_sparkline/app.rb +2 -2
  118. data/examples/widget_style_colors/README.md +6 -0
  119. data/examples/widget_style_colors/app.rb +2 -2
  120. data/examples/widget_table/README.md +8 -2
  121. data/examples/widget_table/app.rb +2 -2
  122. data/examples/widget_tabs/README.md +6 -0
  123. data/examples/widget_tabs/app.rb +2 -2
  124. data/examples/widget_text_width/README.md +6 -0
  125. data/examples/widget_text_width/app.rb +4 -4
  126. data/ext/ratatui_ruby/Cargo.lock +1 -1
  127. data/ext/ratatui_ruby/Cargo.toml +1 -1
  128. data/ext/ratatui_ruby/extconf.rb +2 -2
  129. data/ext/ratatui_ruby/src/rendering.rs +1 -1
  130. data/ext/ratatui_ruby/src/style.rs +0 -8
  131. data/ext/ratatui_ruby/src/widgets/chart.rs +0 -118
  132. data/ext/ratatui_ruby/src/widgets/list_state.rs +36 -0
  133. data/lib/ratatui_ruby/buffer/cell.rb +34 -2
  134. data/lib/ratatui_ruby/buffer.rb +2 -2
  135. data/lib/ratatui_ruby/cell.rb +34 -2
  136. data/lib/ratatui_ruby/event/focus_gained.rb +26 -2
  137. data/lib/ratatui_ruby/event/focus_lost.rb +26 -2
  138. data/lib/ratatui_ruby/event/key/character.rb +18 -2
  139. data/lib/ratatui_ruby/event/key/media.rb +2 -2
  140. data/lib/ratatui_ruby/event/key/modifier.rb +10 -2
  141. data/lib/ratatui_ruby/event/key/navigation.rb +2 -2
  142. data/lib/ratatui_ruby/event/key/system.rb +2 -2
  143. data/lib/ratatui_ruby/event/key.rb +114 -2
  144. data/lib/ratatui_ruby/event/mouse.rb +42 -2
  145. data/lib/ratatui_ruby/event/none.rb +10 -2
  146. data/lib/ratatui_ruby/event/paste.rb +34 -2
  147. data/lib/ratatui_ruby/event/resize.rb +34 -2
  148. data/lib/ratatui_ruby/event.rb +26 -2
  149. data/lib/ratatui_ruby/frame.rb +74 -2
  150. data/lib/ratatui_ruby/layout/constraint.rb +58 -2
  151. data/lib/ratatui_ruby/layout/layout.rb +47 -2
  152. data/lib/ratatui_ruby/layout/rect.rb +403 -2
  153. data/lib/ratatui_ruby/layout.rb +2 -2
  154. data/lib/ratatui_ruby/list_state.rb +113 -2
  155. data/lib/ratatui_ruby/output_guard.rb +26 -3
  156. data/lib/ratatui_ruby/schema/bar_chart/bar.rb +2 -2
  157. data/lib/ratatui_ruby/schema/bar_chart/bar_group.rb +2 -2
  158. data/lib/ratatui_ruby/schema/bar_chart.rb +50 -2
  159. data/lib/ratatui_ruby/schema/block.rb +21 -15
  160. data/lib/ratatui_ruby/schema/calendar.rb +2 -2
  161. data/lib/ratatui_ruby/schema/canvas.rb +10 -2
  162. data/lib/ratatui_ruby/schema/center.rb +10 -2
  163. data/lib/ratatui_ruby/schema/chart.rb +2 -28
  164. data/lib/ratatui_ruby/schema/clear.rb +10 -2
  165. data/lib/ratatui_ruby/schema/constraint.rb +58 -2
  166. data/lib/ratatui_ruby/schema/cursor.rb +10 -2
  167. data/lib/ratatui_ruby/schema/draw.rb +10 -2
  168. data/lib/ratatui_ruby/schema/gauge.rb +2 -2
  169. data/lib/ratatui_ruby/schema/layout.rb +18 -2
  170. data/lib/ratatui_ruby/schema/line_gauge.rb +2 -2
  171. data/lib/ratatui_ruby/schema/list.rb +10 -2
  172. data/lib/ratatui_ruby/schema/list_item.rb +10 -2
  173. data/lib/ratatui_ruby/schema/overlay.rb +10 -2
  174. data/lib/ratatui_ruby/schema/paragraph.rb +10 -2
  175. data/lib/ratatui_ruby/schema/ratatui_logo.rb +2 -2
  176. data/lib/ratatui_ruby/schema/ratatui_mascot.rb +2 -2
  177. data/lib/ratatui_ruby/schema/rect.rb +58 -2
  178. data/lib/ratatui_ruby/schema/row.rb +10 -2
  179. data/lib/ratatui_ruby/schema/scrollbar.rb +2 -2
  180. data/lib/ratatui_ruby/schema/shape/label.rb +10 -2
  181. data/lib/ratatui_ruby/schema/sparkline.rb +10 -2
  182. data/lib/ratatui_ruby/schema/style.rb +18 -2
  183. data/lib/ratatui_ruby/schema/table.rb +2 -2
  184. data/lib/ratatui_ruby/schema/tabs.rb +2 -2
  185. data/lib/ratatui_ruby/schema/text.rb +34 -2
  186. data/lib/ratatui_ruby/scrollbar_state.rb +10 -2
  187. data/lib/ratatui_ruby/style/style.rb +18 -2
  188. data/lib/ratatui_ruby/style.rb +2 -2
  189. data/lib/ratatui_ruby/table_state.rb +10 -2
  190. data/lib/ratatui_ruby/terminal_lifecycle.rb +18 -3
  191. data/lib/ratatui_ruby/test_helper/event_injection.rb +34 -2
  192. data/lib/ratatui_ruby/test_helper/snapshot.rb +74 -9
  193. data/lib/ratatui_ruby/test_helper/style_assertions.rb +98 -2
  194. data/lib/ratatui_ruby/test_helper/terminal.rb +50 -2
  195. data/lib/ratatui_ruby/test_helper/test_doubles.rb +18 -2
  196. data/lib/ratatui_ruby/test_helper.rb +10 -2
  197. data/lib/ratatui_ruby/tui/buffer_factories.rb +2 -2
  198. data/lib/ratatui_ruby/tui/canvas_factories.rb +2 -2
  199. data/lib/ratatui_ruby/tui/core.rb +2 -2
  200. data/lib/ratatui_ruby/tui/layout_factories.rb +32 -2
  201. data/lib/ratatui_ruby/tui/state_factories.rb +2 -2
  202. data/lib/ratatui_ruby/tui/style_factories.rb +2 -2
  203. data/lib/ratatui_ruby/tui/text_factories.rb +2 -2
  204. data/lib/ratatui_ruby/tui/widget_factories.rb +2 -2
  205. data/lib/ratatui_ruby/tui.rb +11 -3
  206. data/lib/ratatui_ruby/version.rb +3 -3
  207. data/lib/ratatui_ruby/widgets/bar_chart/bar.rb +2 -2
  208. data/lib/ratatui_ruby/widgets/bar_chart/bar_group.rb +2 -2
  209. data/lib/ratatui_ruby/widgets/bar_chart.rb +58 -2
  210. data/lib/ratatui_ruby/widgets/block.rb +37 -15
  211. data/lib/ratatui_ruby/widgets/calendar.rb +2 -2
  212. data/lib/ratatui_ruby/widgets/canvas.rb +10 -2
  213. data/lib/ratatui_ruby/widgets/cell.rb +10 -2
  214. data/lib/ratatui_ruby/widgets/center.rb +10 -2
  215. data/lib/ratatui_ruby/widgets/chart.rb +2 -28
  216. data/lib/ratatui_ruby/widgets/clear.rb +10 -2
  217. data/lib/ratatui_ruby/widgets/cursor.rb +10 -2
  218. data/lib/ratatui_ruby/widgets/gauge.rb +16 -2
  219. data/lib/ratatui_ruby/widgets/line_gauge.rb +16 -2
  220. data/lib/ratatui_ruby/widgets/list.rb +41 -2
  221. data/lib/ratatui_ruby/widgets/list_item.rb +10 -2
  222. data/lib/ratatui_ruby/widgets/overlay.rb +10 -2
  223. data/lib/ratatui_ruby/widgets/paragraph.rb +10 -2
  224. data/lib/ratatui_ruby/widgets/ratatui_logo.rb +2 -2
  225. data/lib/ratatui_ruby/widgets/ratatui_mascot.rb +2 -2
  226. data/lib/ratatui_ruby/widgets/row.rb +10 -2
  227. data/lib/ratatui_ruby/widgets/scrollbar.rb +2 -2
  228. data/lib/ratatui_ruby/widgets/shape/label.rb +10 -2
  229. data/lib/ratatui_ruby/widgets/sparkline.rb +10 -2
  230. data/lib/ratatui_ruby/widgets/table.rb +62 -2
  231. data/lib/ratatui_ruby/widgets/tabs.rb +2 -2
  232. data/lib/ratatui_ruby/widgets.rb +2 -2
  233. data/lib/ratatui_ruby.rb +90 -2
  234. data/sig/examples/app_all_events/view.rbs +7 -1
  235. data/sig/examples/app_all_events/view_state.rbs +7 -1
  236. data/sig/examples/app_color_picker/app.rbs +5 -0
  237. data/sig/examples/app_stateful_interaction/app.rbs +7 -1
  238. data/sig/examples/verify_quickstart_dsl/app.rbs +7 -1
  239. data/sig/examples/verify_quickstart_lifecycle/app.rbs +7 -1
  240. data/sig/examples/verify_readme_usage/app.rbs +7 -1
  241. data/sig/examples/widget_block_demo/app.rbs +6 -0
  242. data/sig/examples/widget_box_demo/app.rbs +7 -1
  243. data/sig/examples/widget_calendar_demo/app.rbs +7 -1
  244. data/sig/examples/widget_cell_demo/app.rbs +7 -1
  245. data/sig/examples/widget_chart_demo/app.rbs +7 -1
  246. data/sig/examples/widget_gauge_demo/app.rbs +7 -1
  247. data/sig/examples/widget_layout_split/app.rbs +7 -1
  248. data/sig/examples/widget_line_gauge_demo/app.rbs +7 -1
  249. data/sig/examples/widget_list_demo/app.rbs +5 -0
  250. data/sig/examples/widget_map_demo/app.rbs +7 -1
  251. data/sig/examples/widget_popup_demo/app.rbs +7 -1
  252. data/sig/examples/widget_ratatui_logo_demo/app.rbs +7 -1
  253. data/sig/examples/widget_ratatui_mascot_demo/app.rbs +7 -1
  254. data/sig/examples/widget_rect/app.rbs +7 -1
  255. data/sig/examples/widget_render/app.rbs +7 -1
  256. data/sig/examples/widget_rich_text/app.rbs +7 -1
  257. data/sig/examples/widget_scroll_text/app.rbs +7 -1
  258. data/sig/examples/widget_scrollbar_demo/app.rbs +7 -1
  259. data/sig/examples/widget_sparkline_demo/app.rbs +7 -1
  260. data/sig/examples/widget_style_colors/app.rbs +7 -1
  261. data/sig/examples/widget_table_demo/app.rbs +7 -1
  262. data/sig/examples/widget_text_width/app.rbs +7 -1
  263. data/sig/ratatui_ruby/event.rbs +7 -1
  264. data/sig/ratatui_ruby/frame.rbs +15 -3
  265. data/sig/ratatui_ruby/list_state.rbs +11 -1
  266. data/sig/ratatui_ruby/ratatui_ruby.rbs +8 -2
  267. data/sig/ratatui_ruby/schema/bar_chart/bar.rbs +7 -1
  268. data/sig/ratatui_ruby/schema/bar_chart/bar_group.rbs +6 -0
  269. data/sig/ratatui_ruby/schema/bar_chart.rbs +6 -0
  270. data/sig/ratatui_ruby/schema/block.rbs +7 -1
  271. data/sig/ratatui_ruby/schema/calendar.rbs +6 -0
  272. data/sig/ratatui_ruby/schema/canvas.rbs +6 -0
  273. data/sig/ratatui_ruby/schema/center.rbs +6 -0
  274. data/sig/ratatui_ruby/schema/chart.rbs +6 -9
  275. data/sig/ratatui_ruby/schema/constraint.rbs +6 -0
  276. data/sig/ratatui_ruby/schema/cursor.rbs +6 -0
  277. data/sig/ratatui_ruby/schema/draw.rbs +6 -0
  278. data/sig/ratatui_ruby/schema/gauge.rbs +9 -1
  279. data/sig/ratatui_ruby/schema/layout.rbs +6 -0
  280. data/sig/ratatui_ruby/schema/line_gauge.rbs +9 -1
  281. data/sig/ratatui_ruby/schema/list.rbs +9 -1
  282. data/sig/ratatui_ruby/schema/list_item.rbs +7 -1
  283. data/sig/ratatui_ruby/schema/overlay.rbs +6 -0
  284. data/sig/ratatui_ruby/schema/paragraph.rbs +6 -0
  285. data/sig/ratatui_ruby/schema/ratatui_logo.rbs +6 -0
  286. data/sig/ratatui_ruby/schema/ratatui_mascot.rbs +5 -0
  287. data/sig/ratatui_ruby/schema/rect.rbs +30 -0
  288. data/sig/ratatui_ruby/schema/row.rbs +7 -1
  289. data/sig/ratatui_ruby/schema/scrollbar.rbs +6 -0
  290. data/sig/ratatui_ruby/schema/sparkline.rbs +6 -0
  291. data/sig/ratatui_ruby/schema/style.rbs +7 -1
  292. data/sig/ratatui_ruby/schema/table.rbs +11 -1
  293. data/sig/ratatui_ruby/schema/tabs.rbs +6 -0
  294. data/sig/ratatui_ruby/schema/text.rbs +7 -1
  295. data/sig/ratatui_ruby/scrollbar_state.rbs +7 -1
  296. data/sig/ratatui_ruby/session.rbs +7 -1
  297. data/sig/ratatui_ruby/table_state.rbs +7 -1
  298. data/sig/ratatui_ruby/test_helper/event_injection.rbs +7 -1
  299. data/sig/ratatui_ruby/test_helper/snapshot.rbs +7 -1
  300. data/sig/ratatui_ruby/test_helper/style_assertions.rbs +7 -1
  301. data/sig/ratatui_ruby/test_helper/terminal.rbs +7 -1
  302. data/sig/ratatui_ruby/test_helper/test_doubles.rbs +7 -1
  303. data/sig/ratatui_ruby/test_helper.rbs +7 -1
  304. data/sig/ratatui_ruby/tui/buffer_factories.rbs +7 -1
  305. data/sig/ratatui_ruby/tui/canvas_factories.rbs +7 -1
  306. data/sig/ratatui_ruby/tui/core.rbs +7 -1
  307. data/sig/ratatui_ruby/tui/layout_factories.rbs +7 -1
  308. data/sig/ratatui_ruby/tui/state_factories.rbs +7 -1
  309. data/sig/ratatui_ruby/tui/style_factories.rbs +7 -1
  310. data/sig/ratatui_ruby/tui/text_factories.rbs +7 -1
  311. data/sig/ratatui_ruby/tui/widget_factories.rbs +7 -1
  312. data/sig/ratatui_ruby/tui.rbs +7 -1
  313. data/sig/ratatui_ruby/version.rbs +6 -0
  314. data/tasks/autodoc/examples.rb +1 -1
  315. data/tasks/autodoc/member.rb +1 -1
  316. data/tasks/autodoc/name.rb +1 -1
  317. data/tasks/bump/cargo_lockfile.rb +1 -1
  318. data/tasks/bump/changelog.rb +1 -1
  319. data/tasks/bump/header.rb +1 -1
  320. data/tasks/bump/history.rb +1 -1
  321. data/tasks/bump/links.rb +1 -1
  322. data/tasks/bump/manifest.rb +1 -1
  323. data/tasks/bump/ruby_gem.rb +1 -1
  324. data/tasks/bump/sem_ver.rb +1 -1
  325. data/tasks/bump/unreleased_section.rb +1 -1
  326. data/tasks/license/headers_md.rb +223 -0
  327. data/tasks/license/headers_rb.rb +210 -0
  328. data/tasks/license/license_utils.rb +130 -0
  329. data/tasks/license/snippets_md.rb +315 -0
  330. data/tasks/license/snippets_rdoc.rb +150 -0
  331. data/tasks/license.rake +91 -0
  332. data/tasks/rdoc_config.rb +1 -1
  333. data/tasks/resources/build.yml.erb +13 -7
  334. data/tasks/sourcehut.rake +3 -1
  335. data/tasks/terminal_preview/app_screenshot.rb +1 -1
  336. data/tasks/terminal_preview/crash_report.rb +1 -1
  337. data/tasks/terminal_preview/example_app.rb +1 -1
  338. data/tasks/terminal_preview/launcher_script.rb +1 -1
  339. data/tasks/terminal_preview/preview_collection.rb +1 -1
  340. data/tasks/terminal_preview/preview_timing.rb +1 -1
  341. data/tasks/terminal_preview/safety_confirmation.rb +1 -1
  342. data/tasks/terminal_preview/saved_screenshot.rb +1 -1
  343. data/tasks/terminal_preview/system_appearance.rb +1 -1
  344. data/tasks/terminal_preview/terminal_window.rb +1 -1
  345. data/tasks/terminal_preview/window_id.rb +1 -1
  346. data/tasks/website/index_page.rb +1 -1
  347. data/tasks/website/version.rb +1 -1
  348. data/tasks/website/version_menu.rb +1 -1
  349. data/tasks/website/versioned_documentation.rb +1 -1
  350. data/tasks/website/website.rb +1 -1
  351. metadata +13 -3
  352. data/doc/migration/v0_7_0.md +0 -236
@@ -0,0 +1,223 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
5
+ # SPDX-License-Identifier: AGPL-3.0-or-later
6
+ #++
7
+
8
+ # Script to ensure markdown files have correct SPDX file headers (CC-BY-SA-4.0).
9
+ #
10
+ # Usage: ruby tasks/license/headers_md.rb [path...]
11
+ #
12
+ # If no paths are given, processes all .md files via git ls-files.
13
+ #
14
+ # Rules:
15
+ # - Ensures file has CC-BY-SA-4.0 license header with YOUR copyright
16
+ # - Updates years for EXISTING contributors based on git blame + Co-Authored-By
17
+ # - Does NOT add new contributors from git history - only updates existing ones
18
+ # - Uses non-code-block lines for year calculation
19
+ # - Adds header with YOUR copyright if missing
20
+
21
+ require_relative "license_utils"
22
+
23
+ YOUR_NAME = "Kerrick Long"
24
+ YOUR_EMAIL = "me@kerricklong.com"
25
+ YOUR_IDENTIFIERS = [YOUR_NAME, YOUR_EMAIL].freeze
26
+ YOUR_COPYRIGHT = "#{YOUR_NAME} <#{YOUR_EMAIL}>"
27
+ LICENSE = "CC-BY-SA-4.0"
28
+
29
+ def find_code_blocks(lines)
30
+ blocks = []
31
+ i = 0
32
+
33
+ while i < lines.length
34
+ line = lines[i]
35
+
36
+ if line =~ /^(````*)(\w*)$/
37
+ fence_marker = $1
38
+ fence_start = i
39
+ re_end = /^#{Regexp.escape(fence_marker)}$/
40
+
41
+ j = i + 1
42
+ while j < lines.length
43
+ if lines[j] =~ re_end
44
+ blocks << { start: fence_start, end: j }
45
+ i = j
46
+ break
47
+ end
48
+ j += 1
49
+ end
50
+ end
51
+
52
+ i += 1
53
+ end
54
+
55
+ blocks
56
+ end
57
+
58
+ def get_non_code_line_ranges(lines)
59
+ header_end = 0
60
+ if lines[0]&.include?("<!--")
61
+ (0...(lines.length)).each do |i|
62
+ if lines[i].include?("-->")
63
+ header_end = i + 1
64
+ break
65
+ end
66
+ end
67
+ end
68
+
69
+ code_blocks = find_code_blocks(lines)
70
+ non_code_ranges = []
71
+ current_line = header_end
72
+
73
+ code_blocks.each do |block|
74
+ if current_line < block[:start]
75
+ non_code_ranges << [current_line + 1, block[:start]]
76
+ end
77
+ current_line = block[:end] + 1
78
+ end
79
+
80
+ if current_line < lines.length
81
+ non_code_ranges << [current_line + 1, lines.length]
82
+ end
83
+
84
+ non_code_ranges
85
+ end
86
+
87
+ def parse_existing_header(lines)
88
+ return nil unless lines[0]&.include?("<!--")
89
+
90
+ header_end = nil
91
+ copyrights = []
92
+ license = nil
93
+
94
+ (0...(lines.length)).each do |i|
95
+ line = lines[i]
96
+
97
+ if line =~ /SPDX-FileCopyrightText:\s*(\d{4})\s+(.+)$/
98
+ copyrights << { year: $1.to_i, holder: $2.strip }
99
+ # REUSE-IgnoreStart
100
+ elsif line =~ /SPDX-License-Identifier:\s*(.+)$/
101
+ # REUSE-IgnoreEnd
102
+ license = $1.strip
103
+ end
104
+
105
+ if line.include?("-->")
106
+ header_end = i
107
+ break
108
+ end
109
+ end
110
+
111
+ return nil if header_end.nil?
112
+ return nil if copyrights.empty? && license.nil?
113
+
114
+ { end_line: header_end, copyrights:, license: }
115
+ end
116
+
117
+ def process_file(filepath)
118
+ content = File.read(filepath)
119
+ lines = content.lines
120
+
121
+ non_code_ranges = get_non_code_line_ranges(lines)
122
+
123
+ # Get contributors from non-code lines for year lookups
124
+ all_contributors = {}
125
+ non_code_ranges.each do |start_line, end_line|
126
+ range_contributors = LicenseUtils.get_contributors_for_lines(filepath, start_line, end_line)
127
+ range_contributors.each do |contributor, year|
128
+ all_contributors[contributor] = [all_contributors[contributor] || 0, year].max
129
+ end
130
+ end
131
+
132
+ your_year = nil
133
+ all_contributors.each do |contributor, year|
134
+ if YOUR_IDENTIFIERS.any? { |id| contributor.include?(id) }
135
+ your_year = [your_year || 0, year].max
136
+ end
137
+ end
138
+ your_year ||= Date.today.year
139
+
140
+ existing = parse_existing_header(lines)
141
+
142
+ if existing
143
+ # Only update years for EXISTING contributors
144
+ needs_update = false
145
+ updated_copyrights = []
146
+
147
+ existing[:copyrights].each do |c|
148
+ git_year = nil
149
+ all_contributors.each do |contributor, year|
150
+ if c[:holder].split.any? { |word| contributor.include?(word) }
151
+ git_year = [git_year || 0, year].max
152
+ end
153
+ end
154
+
155
+ if git_year && git_year != c[:year]
156
+ puts " Updated #{c[:holder].split.first}'s copyright year: #{c[:year]} -> #{git_year}"
157
+ updated_copyrights << { year: git_year, holder: c[:holder] }
158
+ needs_update = true
159
+ else
160
+ updated_copyrights << c
161
+ end
162
+ end
163
+
164
+ # Check if YOUR year needs updating
165
+ your_existing = updated_copyrights.find { |c| YOUR_IDENTIFIERS.any? { |id| c[:holder].include?(id) } }
166
+ if your_existing.nil?
167
+ puts " Adding your copyright"
168
+ updated_copyrights << { year: your_year, holder: YOUR_COPYRIGHT }
169
+ needs_update = true
170
+ end
171
+
172
+ if existing[:license] != LICENSE
173
+ puts " Fixing license: #{existing[:license]} -> #{LICENSE}"
174
+ needs_update = true
175
+ end
176
+
177
+ if needs_update
178
+ # REUSE-IgnoreStart
179
+ header_lines = ["<!--\n"]
180
+ updated_copyrights.each do |c|
181
+ header_lines << " SPDX-FileCopyrightText: #{c[:year]} #{c[:holder]}\n"
182
+ end
183
+ header_lines << " SPDX-License-Identifier: #{LICENSE}\n"
184
+ header_lines << "-->\n"
185
+ # REUSE-IgnoreEnd
186
+
187
+ remaining = lines[(existing[:end_line] + 1)..]
188
+ File.write(filepath, header_lines.join + remaining.join)
189
+ puts "Updated: #{filepath}"
190
+ end
191
+ else
192
+ # No header - add one with YOUR copyright only
193
+ # REUSE-IgnoreStart
194
+ header = "<!--\n SPDX-FileCopyrightText: #{your_year} #{YOUR_COPYRIGHT}\n SPDX-License-Identifier: #{LICENSE}\n-->\n"
195
+ # REUSE-IgnoreEnd
196
+
197
+ File.write(filepath, header + content)
198
+ puts "Added header: #{filepath}"
199
+ end
200
+ end
201
+
202
+ def find_md_files(paths)
203
+ if paths.empty?
204
+ `git ls-files '*.md'`.split("\n")
205
+ else
206
+ paths.flat_map do |path|
207
+ if File.directory?(path)
208
+ `git ls-files '#{path}/**/*.md'`.split("\n")
209
+ else
210
+ path
211
+ end
212
+ end
213
+ end
214
+ end
215
+
216
+ if __FILE__ == $0
217
+ paths = ARGV.empty? ? [] : ARGV
218
+ files = find_md_files(paths)
219
+
220
+ files.each do |file|
221
+ process_file(file)
222
+ end
223
+ end
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
5
+ # SPDX-License-Identifier: AGPL-3.0-or-later
6
+ #++
7
+
8
+ # Script to ensure Ruby files have correct SPDX file headers.
9
+ #
10
+ # Usage: ruby tasks/license/headers_rb.rb [path...]
11
+ #
12
+ # If no paths are given, processes lib/, ext/, test/, examples/, tasks/, bin/.
13
+ #
14
+ # License selection by directory:
15
+ # - lib/, ext/, test/ → LGPL-3.0-or-later
16
+ # - examples/widget_*, examples/verify_* → MIT-0
17
+ # - examples/app_*, tasks/, bin/ → AGPL-3.0-or-later
18
+
19
+ require_relative "license_utils"
20
+
21
+ YOUR_NAME = "Kerrick Long"
22
+ YOUR_EMAIL = "me@kerricklong.com"
23
+ YOUR_IDENTIFIERS = [YOUR_NAME, YOUR_EMAIL].freeze
24
+ YOUR_COPYRIGHT = "#{YOUR_NAME} <#{YOUR_EMAIL}>"
25
+
26
+ def license_for_file(filepath)
27
+ case filepath
28
+ when %r{^(lib|sig/ratatui_ruby|ext|test)/}
29
+ "LGPL-3.0-or-later"
30
+ when %r{^(examples|sig/examples)/(widget_|verify_)}
31
+ "MIT-0"
32
+ else
33
+ "AGPL-3.0-or-later"
34
+ end
35
+ end
36
+
37
+ def parse_existing_header(lines)
38
+ # Returns { end_line:, copyrights: [{year:, holder:}], license: }
39
+ # REUSE-IgnoreStart
40
+ # Ruby files typically have:
41
+ # # frozen_string_literal: true
42
+ # (blank line)
43
+ # #--
44
+ # # SPDX-FileCopyrightText: YYYY Name
45
+ # # SPDX-License-Identifier: LICENSE
46
+ # #++
47
+ # REUSE-IgnoreEnd
48
+
49
+ copyrights = []
50
+ license = nil
51
+ header_end = nil
52
+ found_spdx = false
53
+
54
+ lines.each_with_index do |line, i|
55
+ if line =~ /^#\s*SPDX-FileCopyrightText:\s*(\d{4})\s+(.+)$/
56
+ copyrights << { year: $1.to_i, holder: $2.strip }
57
+ found_spdx = true
58
+ # REUSE-IgnoreStart
59
+ elsif line =~ /^#\s*SPDX-License-Identifier:\s*(.+)$/
60
+ # REUSE-IgnoreEnd
61
+ license = $1.strip
62
+ found_spdx = true
63
+ elsif line =~ /^#\+\+\s*$/ && found_spdx
64
+ header_end = i
65
+ break
66
+ end
67
+ end
68
+
69
+ return nil if copyrights.empty? && license.nil?
70
+
71
+ { end_line: header_end || 0, copyrights:, license: }
72
+ end
73
+
74
+ def process_file(filepath)
75
+ content = File.read(filepath)
76
+ lines = content.lines
77
+
78
+ target_license = license_for_file(filepath)
79
+
80
+ # Get contributors from git for year lookups
81
+ all_contributors = LicenseUtils.get_contributors_for_lines(filepath)
82
+ your_year = LicenseUtils.get_your_latest_year(filepath, YOUR_IDENTIFIERS)
83
+
84
+ existing = parse_existing_header(lines)
85
+
86
+ if existing
87
+ # File has existing header - only update years for EXISTING contributors
88
+ needs_update = false
89
+ updated_copyrights = []
90
+
91
+ existing[:copyrights].each do |c|
92
+ # Find this contributor's latest year from git
93
+ git_year = nil
94
+ all_contributors.each do |contributor, year|
95
+ if c[:holder].split.any? { |word| contributor.include?(word) }
96
+ git_year = [git_year || 0, year].max
97
+ end
98
+ end
99
+
100
+ if git_year && git_year != c[:year]
101
+ puts " Updated #{c[:holder].split.first}'s copyright year: #{c[:year]} -> #{git_year}"
102
+ updated_copyrights << { year: git_year, holder: c[:holder] }
103
+ needs_update = true
104
+ else
105
+ updated_copyrights << c
106
+ end
107
+ end
108
+
109
+ # Check if YOUR year needs updating (if you're a contributor)
110
+ your_existing = updated_copyrights.find { |c| YOUR_IDENTIFIERS.any? { |id| c[:holder].include?(id) } }
111
+ if your_existing.nil?
112
+ puts " Adding your copyright"
113
+ updated_copyrights << { year: your_year, holder: YOUR_COPYRIGHT }
114
+ needs_update = true
115
+ end
116
+
117
+ # Check license
118
+ if existing[:license] != target_license
119
+ puts " Fixing license: #{existing[:license]} -> #{target_license}"
120
+ needs_update = true
121
+ end
122
+
123
+ if needs_update
124
+ frozen_string = lines[0].include?("frozen_string_literal") ? lines[0] : nil
125
+
126
+ header_lines = []
127
+ header_lines << "# frozen_string_literal: true\n" unless frozen_string
128
+ header_lines << "\n" if frozen_string.nil? && !lines[0].strip.empty?
129
+ header_lines << "#--\n"
130
+
131
+ # REUSE-IgnoreStart
132
+ updated_copyrights.each do |c|
133
+ header_lines << "# SPDX-FileCopyrightText: #{c[:year]} #{c[:holder]}\n"
134
+ end
135
+ header_lines << "# SPDX-License-Identifier: #{target_license}\n"
136
+ # REUSE-IgnoreEnd
137
+ header_lines << "#++\n"
138
+
139
+ content_start = existing[:end_line] + 1
140
+ while content_start < lines.length && lines[content_start].strip.empty?
141
+ content_start += 1
142
+ end
143
+
144
+ remaining = lines[content_start..]
145
+
146
+ new_content = if frozen_string
147
+ "#{frozen_string}\n#{header_lines.join}\n#{remaining.join}"
148
+ else
149
+ "#{header_lines.join}\n#{remaining.join}"
150
+ end
151
+
152
+ File.write(filepath, new_content)
153
+ puts "Updated: #{filepath}"
154
+ end
155
+ else
156
+ # No header - add one with YOUR copyright only
157
+ frozen_line = lines[0]&.include?("frozen_string_literal") ? lines.shift : nil
158
+
159
+ header = []
160
+ header << "# frozen_string_literal: true\n\n" unless frozen_line
161
+ header << "#--\n"
162
+ # REUSE-IgnoreStart
163
+ header << "# SPDX-FileCopyrightText: #{your_year} #{YOUR_COPYRIGHT}\n"
164
+ header << "# SPDX-License-Identifier: #{target_license}\n"
165
+ # REUSE-IgnoreEnd
166
+ header << "#++\n\n"
167
+
168
+ if frozen_line
169
+ File.write(filepath, "#{frozen_line}\n#{header.join}#{lines.join}")
170
+ else
171
+ File.write(filepath, header.join + lines.join)
172
+ end
173
+ puts "Added header: #{filepath}"
174
+ end
175
+ end
176
+
177
+ def find_rb_files(paths)
178
+ if paths.empty?
179
+ # Process all relevant directories
180
+ dirs = %w[lib ext test examples tasks bin sig]
181
+ files = dirs.flat_map do |dir|
182
+ # Include both root files and subdirectory files, for both .rb and .rbs
183
+ %w[rb rbs].flat_map do |ext|
184
+ root_files = `git ls-files '#{dir}/*.#{ext}' 2>/dev/null`.split("\n")
185
+ sub_files = `git ls-files '#{dir}/**/*.#{ext}' 2>/dev/null`.split("\n")
186
+ root_files + sub_files
187
+ end
188
+ end
189
+ files.uniq
190
+ else
191
+ paths.flat_map do |path|
192
+ if File.directory?(path)
193
+ rb_files = `git ls-files '#{path}/**/*.rb'`.split("\n")
194
+ rbs_files = `git ls-files '#{path}/**/*.rbs'`.split("\n")
195
+ rb_files + rbs_files
196
+ else
197
+ path
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ if __FILE__ == $0
204
+ paths = ARGV.empty? ? [] : ARGV
205
+ files = find_rb_files(paths)
206
+
207
+ files.each do |file|
208
+ process_file(file)
209
+ end
210
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
5
+ # SPDX-License-Identifier: AGPL-3.0-or-later
6
+ #++
7
+
8
+ # Shared utility for detecting contributors from git blame and Co-Authored-By trailers.
9
+ #
10
+ # This module provides methods to:
11
+ # - Get all contributors (authors and co-authors) who touched specific lines
12
+ # - Track the latest year each contributor touched those lines
13
+ # - Parse Co-Authored-By trailers from commit messages
14
+
15
+ require "open3"
16
+ require "date"
17
+
18
+ module LicenseUtils
19
+ # Represents a contributor with their latest year of contribution
20
+ Contributor = Data.define(:name, :email, :year)
21
+
22
+ class << self
23
+ # Get all contributors who touched lines in a file (or range of lines).
24
+ # Returns a Hash of { "Name <email>" => year } mapping each contributor to their latest year.
25
+ #
26
+ # This considers both the commit author AND any Co-Authored-By trailers in commit messages.
27
+ def get_contributors_for_lines(filepath, start_line = nil, end_line = nil)
28
+ blame_cmd = if start_line && end_line
29
+ %W[git blame -L #{start_line},#{end_line} --porcelain -- #{filepath}]
30
+ else
31
+ %W[git blame --porcelain -- #{filepath}]
32
+ end
33
+
34
+ output, _status = Open3.capture2(*blame_cmd)
35
+
36
+ contributors = {} # "Name <email>" => year
37
+ commit_cache = {} # commit_hash => { year:, author:, co_authors: [] }
38
+
39
+ current_commit = nil
40
+
41
+ output.each_line do |line|
42
+ if line =~ /^([a-f0-9]{40})/
43
+ current_commit = $1
44
+ elsif line =~ /^author (.+)$/
45
+ commit_cache[current_commit] ||= {}
46
+ commit_cache[current_commit][:author_name] = $1
47
+ elsif line =~ /^author-mail <(.+)>$/
48
+ commit_cache[current_commit] ||= {}
49
+ commit_cache[current_commit][:author_email] = $1
50
+ elsif line =~ /^author-time (\d+)$/
51
+ commit_cache[current_commit] ||= {}
52
+ timestamp = $1.to_i
53
+ commit_cache[current_commit][:year] = Time.at(timestamp).year
54
+ end
55
+ end
56
+
57
+ # Now fetch co-authors for each unique commit
58
+ commit_cache.each do |commit_hash, data|
59
+ next if commit_hash == "0" * 40 # Skip uncommitted lines
60
+
61
+ # Get commit message for Co-Authored-By parsing
62
+ msg_output, _status = Open3.capture2("git", "log", "-1", "--format=%B", commit_hash)
63
+ co_authors = parse_co_authors(msg_output)
64
+ data[:co_authors] = co_authors
65
+
66
+ # Add author
67
+ if data[:author_name] && data[:author_email]
68
+ key = "#{data[:author_name]} <#{data[:author_email]}>"
69
+ year = data[:year] || Date.today.year
70
+ contributors[key] = [contributors[key] || 0, year].max
71
+ end
72
+
73
+ # Add co-authors with same year as commit
74
+ co_authors.each do |ca|
75
+ key = "#{ca[:name]} <#{ca[:email]}>"
76
+ year = data[:year] || Date.today.year
77
+ contributors[key] = [contributors[key] || 0, year].max
78
+ end
79
+ end
80
+
81
+ contributors
82
+ end
83
+
84
+ # Get YOUR latest year contribution to the file/lines.
85
+ # your_identifiers should be an array of strings that identify you (name, email fragments).
86
+ def get_your_latest_year(filepath, your_identifiers, start_line = nil, end_line = nil)
87
+ contributors = get_contributors_for_lines(filepath, start_line, end_line)
88
+
89
+ your_year = nil
90
+ contributors.each do |contributor, year|
91
+ if your_identifiers.any? { |id| contributor.include?(id) }
92
+ your_year = [your_year || 0, year].max
93
+ end
94
+ end
95
+
96
+ your_year || Date.today.year
97
+ end
98
+
99
+ # Get all contributors EXCEPT you, with their latest years.
100
+ # Returns array of { name:, email:, year: }
101
+ def get_other_contributors(filepath, your_identifiers, start_line = nil, end_line = nil)
102
+ contributors = get_contributors_for_lines(filepath, start_line, end_line)
103
+
104
+ others = []
105
+ contributors.each do |contributor, year|
106
+ next if your_identifiers.any? { |id| contributor.include?(id) }
107
+
108
+ # Parse "Name <email>" format
109
+ if contributor =~ /^(.+?)\s*<(.+)>$/
110
+ others << { name: $1.strip, email: $2.strip, year: }
111
+ end
112
+ end
113
+
114
+ others
115
+ end
116
+
117
+ private def parse_co_authors(message)
118
+ co_authors = []
119
+
120
+ message.each_line do |line|
121
+ # Match "Co-Authored-By: Name <email>" (case insensitive)
122
+ if line =~ /^Co-Authored-By:\s*(.+?)\s*<(.+?)>\s*$/i
123
+ co_authors << { name: $1.strip, email: $2.strip }
124
+ end
125
+ end
126
+
127
+ co_authors
128
+ end
129
+ end
130
+ end