ratatui_ruby 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/.builds/ruby-3.2.yml +1 -1
- data/.builds/ruby-3.3.yml +1 -1
- data/.builds/ruby-3.4.yml +1 -1
- data/.builds/ruby-4.0.0.yml +1 -1
- data/AGENTS.md +3 -2
- data/CHANGELOG.md +33 -7
- data/Steepfile +1 -0
- data/doc/concepts/application_testing.md +5 -5
- data/doc/concepts/event_handling.md +1 -1
- data/doc/contributors/design/ruby_frontend.md +40 -12
- data/doc/contributors/design/rust_backend.md +13 -1
- data/doc/contributors/releasing.md +215 -0
- data/doc/contributors/todo/align/api_completeness_audit-finished.md +6 -0
- data/doc/contributors/todo/align/api_completeness_audit-unfinished.md +1 -7
- data/doc/contributors/todo/align/term.md +351 -0
- data/doc/contributors/upstream_requests/paragraph_span_rects.md +259 -0
- data/doc/getting_started/quickstart.md +1 -1
- data/doc/getting_started/why.md +3 -3
- data/doc/images/app_external_editor.gif +0 -0
- data/doc/index.md +1 -6
- data/examples/app_external_editor/README.md +62 -0
- data/examples/app_external_editor/app.rb +344 -0
- data/examples/widget_list/app.rb +2 -4
- data/examples/widget_table/app.rb +8 -2
- data/ext/ratatui_ruby/Cargo.lock +1 -1
- data/ext/ratatui_ruby/Cargo.toml +1 -1
- data/ext/ratatui_ruby/src/events.rs +171 -203
- data/ext/ratatui_ruby/src/lib.rs +36 -0
- data/ext/ratatui_ruby/src/lib_header.rs +11 -0
- data/ext/ratatui_ruby/src/terminal/capabilities.rs +46 -0
- data/ext/ratatui_ruby/src/terminal/init.rs +92 -0
- data/ext/ratatui_ruby/src/terminal/mod.rs +12 -3
- data/ext/ratatui_ruby/src/terminal/queries.rs +15 -0
- data/ext/ratatui_ruby/src/terminal/query.rs +64 -2
- data/lib/ratatui_ruby/backend/window_size.rb +50 -0
- data/lib/ratatui_ruby/backend.rb +59 -0
- data/lib/ratatui_ruby/event/key/navigation.rb +10 -1
- data/lib/ratatui_ruby/event/key.rb +84 -0
- data/lib/ratatui_ruby/event/mouse.rb +95 -3
- data/lib/ratatui_ruby/event/resize.rb +45 -3
- data/lib/ratatui_ruby/layout/alignment.rb +91 -0
- data/lib/ratatui_ruby/layout/layout.rb +1 -2
- data/lib/ratatui_ruby/layout/size.rb +10 -3
- data/lib/ratatui_ruby/layout.rb +4 -0
- data/lib/ratatui_ruby/terminal/capabilities.rb +316 -0
- data/lib/ratatui_ruby/terminal/viewport.rb +1 -1
- data/lib/ratatui_ruby/terminal.rb +66 -0
- data/lib/ratatui_ruby/test_helper/global_state.rb +111 -0
- data/lib/ratatui_ruby/test_helper.rb +3 -0
- data/lib/ratatui_ruby/version.rb +1 -1
- data/lib/ratatui_ruby/widgets/table.rb +2 -2
- data/lib/ratatui_ruby.rb +25 -4
- data/sig/examples/app_external_editor/app.rbs +12 -0
- data/sig/generated/event_key_predicates.rbs +1348 -0
- data/sig/ratatui_ruby/backend/window_size.rbs +17 -0
- data/sig/ratatui_ruby/backend.rbs +12 -0
- data/sig/ratatui_ruby/event.rbs +7 -0
- data/sig/ratatui_ruby/layout/alignment.rbs +26 -0
- data/sig/ratatui_ruby/ratatui_ruby.rbs +2 -0
- data/sig/ratatui_ruby/terminal/capabilities.rbs +38 -0
- data/sig/ratatui_ruby/terminal/viewport.rbs +15 -1
- data/tasks/bump/bump_workflow.rb +49 -0
- data/tasks/bump/changelog.rb +57 -0
- data/tasks/bump/patch_release.rb +19 -0
- data/tasks/bump/release_branch.rb +17 -0
- data/tasks/bump/release_from_trunk.rb +49 -0
- data/tasks/bump/repository.rb +54 -0
- data/tasks/bump/ruby_gem.rb +6 -26
- data/tasks/bump/sem_ver.rb +4 -0
- data/tasks/bump/unreleased_section.rb +17 -0
- data/tasks/bump.rake +21 -11
- data/tasks/doc/documentation.rb +59 -0
- data/tasks/doc/link/file_url.rb +30 -0
- data/tasks/doc/link/relative_path.rb +61 -0
- data/tasks/doc/link/web_url.rb +55 -0
- data/tasks/doc/link.rb +52 -0
- data/tasks/doc/link_audit.rb +116 -0
- data/tasks/doc/problem.rb +40 -0
- data/tasks/doc/source_file.rb +93 -0
- data/tasks/doc.rake +18 -0
- data/tasks/rbs_predicates/predicate_catalog.rb +52 -0
- data/tasks/rbs_predicates/predicate_tests.rb +124 -0
- data/tasks/rbs_predicates/rbs_signature.rb +63 -0
- data/tasks/rbs_predicates.rake +31 -0
- data/tasks/test.rake +3 -0
- data/tasks/website/version.rb +23 -28
- metadata +38 -1
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
require "pathname"
|
|
9
|
+
|
|
10
|
+
require_relative "../problem"
|
|
11
|
+
|
|
12
|
+
# A relative path to a local file.
|
|
13
|
+
#
|
|
14
|
+
# Documentation references sibling files: images, other docs, source code.
|
|
15
|
+
# Files get renamed. Directories restructure. These paths silently break.
|
|
16
|
+
#
|
|
17
|
+
# RelativePath resolves the path against the project root and checks if the
|
|
18
|
+
# target exists. It also handles RDoc's HTML naming convention (converting
|
|
19
|
+
# <tt>foo_rb.html</tt> back to <tt>foo.rb</tt> for validation).
|
|
20
|
+
#
|
|
21
|
+
# === Example
|
|
22
|
+
#
|
|
23
|
+
# link = RelativePath.new("../images/diagram.png", 20, source_file)
|
|
24
|
+
# link.problem(root) # => nil (file exists) or Problem (missing)
|
|
25
|
+
#
|
|
26
|
+
class RelativePath < Link
|
|
27
|
+
# Returns a Problem if the target file does not exist. Returns <tt>nil</tt>
|
|
28
|
+
# if the path resolves to an existing file or directory.
|
|
29
|
+
#
|
|
30
|
+
# [root] Project root directory for resolving absolute paths.
|
|
31
|
+
def problem(root)
|
|
32
|
+
root = Pathname.new(root)
|
|
33
|
+
resolved = resolve(root)
|
|
34
|
+
return nil unless resolved
|
|
35
|
+
|
|
36
|
+
Problem.new(self, "File not found: #{resolved.relative_path_from(root)}") unless exists?(resolved)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private def exists?(resolved) # :nodoc:
|
|
40
|
+
return true if resolved.exist?
|
|
41
|
+
|
|
42
|
+
# RDoc generates foo_rb.html from foo.rb
|
|
43
|
+
if raw.end_with?("_rb.html")
|
|
44
|
+
source = Pathname.new(resolved.to_s.sub(/_rb\.html$/, ".rb"))
|
|
45
|
+
return true if source.exist?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
resolved.directory? if raw.end_with?("/")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private def resolve(root) # :nodoc:
|
|
52
|
+
path = raw.split("#").first&.split("?")&.first
|
|
53
|
+
return nil if path.nil? || path.empty? || path.length < 4
|
|
54
|
+
|
|
55
|
+
if path.start_with?("/")
|
|
56
|
+
root.join(path.delete_prefix("/"))
|
|
57
|
+
else
|
|
58
|
+
source_file.path.dirname.join(path)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
require "net/http"
|
|
9
|
+
require "uri"
|
|
10
|
+
|
|
11
|
+
require_relative "../problem"
|
|
12
|
+
|
|
13
|
+
# An HTTP or HTTPS URL in documentation.
|
|
14
|
+
#
|
|
15
|
+
# External links rot. Servers go offline. Pages move. A link that worked last
|
|
16
|
+
# year may 404 today. Manual verification is slow and error-prone.
|
|
17
|
+
#
|
|
18
|
+
# WebUrl checks reachability by making a HEAD request. It returns a Problem if
|
|
19
|
+
# the server responds with an error or is unreachable.
|
|
20
|
+
#
|
|
21
|
+
# === Example
|
|
22
|
+
#
|
|
23
|
+
# link = WebUrl.new("https://example.com", 15, source_file)
|
|
24
|
+
# link.web? # => true
|
|
25
|
+
# link.problem(root) # => nil (site is up) or Problem (site is down)
|
|
26
|
+
#
|
|
27
|
+
class WebUrl < Link
|
|
28
|
+
# Whether this link points to a web URL. Always <tt>true</tt> for WebUrl.
|
|
29
|
+
def web?
|
|
30
|
+
true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns a Problem if the URL is unreachable. Returns <tt>nil</tt> if the
|
|
34
|
+
# server responds with a 2xx or 3xx status.
|
|
35
|
+
#
|
|
36
|
+
# [_root] Unused. Present for interface compatibility.
|
|
37
|
+
def problem(_root)
|
|
38
|
+
Problem.new(self, "URL returned error or is unreachable") unless reachable?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private def reachable? # :nodoc:
|
|
42
|
+
uri = URI.parse(raw)
|
|
43
|
+
return false unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
|
|
44
|
+
|
|
45
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
46
|
+
http.use_ssl = uri.scheme == "https"
|
|
47
|
+
http.open_timeout = 5
|
|
48
|
+
http.read_timeout = 5
|
|
49
|
+
|
|
50
|
+
response = http.request_head(uri.request_uri)
|
|
51
|
+
response.code.to_i < 400
|
|
52
|
+
rescue
|
|
53
|
+
false
|
|
54
|
+
end
|
|
55
|
+
end
|
data/tasks/doc/link.rb
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
# Base class for links found in documentation.
|
|
9
|
+
#
|
|
10
|
+
# Documentation contains links: URLs, file paths, images. These links break.
|
|
11
|
+
# Pages move. Files get renamed. Servers go offline. Manual checking is tedious.
|
|
12
|
+
#
|
|
13
|
+
# Link is the base type. It holds the raw text, line number, and source file.
|
|
14
|
+
# Subclasses (FileUrl, WebUrl, RelativePath) implement <tt>problem</tt> to
|
|
15
|
+
# detect specific breakage.
|
|
16
|
+
#
|
|
17
|
+
# Use <tt>Link.build</tt> to create the correct subclass based on the raw text.
|
|
18
|
+
#
|
|
19
|
+
# === Example
|
|
20
|
+
#
|
|
21
|
+
# link = Link.build("https://example.com", 42, source_file)
|
|
22
|
+
# link.web? # => true
|
|
23
|
+
# link.problem(root) # => nil or Problem
|
|
24
|
+
#
|
|
25
|
+
class Link < Data.define(:raw, :line, :source_file)
|
|
26
|
+
# Creates the appropriate Link subclass based on the raw text.
|
|
27
|
+
#
|
|
28
|
+
# [raw] The raw link text extracted from the file.
|
|
29
|
+
# [line] Line number where the link appears.
|
|
30
|
+
# [source_file] The SourceFile containing this link.
|
|
31
|
+
def self.build(raw, line, source_file)
|
|
32
|
+
if raw.start_with?("file://")
|
|
33
|
+
FileUrl.new(raw, line, source_file)
|
|
34
|
+
elsif raw.start_with?("https://", "http://")
|
|
35
|
+
WebUrl.new(raw, line, source_file)
|
|
36
|
+
else
|
|
37
|
+
RelativePath.new(raw, line, source_file)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Whether this link points to a web URL.
|
|
42
|
+
#
|
|
43
|
+
# WebUrl overrides this to return <tt>true</tt>. Other link types return
|
|
44
|
+
# <tt>false</tt>. The audit uses this to decide whether to skip verification.
|
|
45
|
+
def web?
|
|
46
|
+
false
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
require_relative "link/file_url"
|
|
51
|
+
require_relative "link/web_url"
|
|
52
|
+
require_relative "link/relative_path"
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
require_relative "documentation"
|
|
9
|
+
|
|
10
|
+
# Results of auditing documentation for broken links.
|
|
11
|
+
#
|
|
12
|
+
# Documentation breaks silently. Links rot. Files move. Paths change. Manual
|
|
13
|
+
# checking is tedious and error-prone. Automated checking catches problems
|
|
14
|
+
# before users do.
|
|
15
|
+
#
|
|
16
|
+
# LinkAudit scans all documentation, checks each link, and collects problems.
|
|
17
|
+
# It separates web URLs (slow to verify) from local paths (fast to check).
|
|
18
|
+
# The results render as a human-readable report via <tt>to_s</tt>.
|
|
19
|
+
#
|
|
20
|
+
# === Example
|
|
21
|
+
#
|
|
22
|
+
# audit = LinkAudit.new("/project/root", verify_web: false)
|
|
23
|
+
# puts audit # prints the full report
|
|
24
|
+
# exit 1 unless audit.success?
|
|
25
|
+
#
|
|
26
|
+
class LinkAudit
|
|
27
|
+
# Problems found during the audit.
|
|
28
|
+
attr_reader :problems
|
|
29
|
+
|
|
30
|
+
# Web URLs that were not verified (when <tt>verify_web: false</tt>).
|
|
31
|
+
attr_reader :unverified
|
|
32
|
+
|
|
33
|
+
# Creates a new LinkAudit and runs the scan immediately.
|
|
34
|
+
#
|
|
35
|
+
# [root] Project root directory to scan.
|
|
36
|
+
# [verify_web] Whether to make HTTP requests to verify web URLs.
|
|
37
|
+
def initialize(root, verify_web: false)
|
|
38
|
+
@root = root
|
|
39
|
+
@docs = Documentation.new(root)
|
|
40
|
+
@verify_web = verify_web
|
|
41
|
+
@problems = []
|
|
42
|
+
@unverified = []
|
|
43
|
+
@checked = 0
|
|
44
|
+
@web_checked = 0
|
|
45
|
+
scan
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Whether the audit passed with no problems.
|
|
49
|
+
def success?
|
|
50
|
+
@problems.empty?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Returns the audit report as a String.
|
|
54
|
+
def to_s
|
|
55
|
+
lines = []
|
|
56
|
+
lines << ""
|
|
57
|
+
lines << "Scanning for broken links in #{@root}..."
|
|
58
|
+
lines << ""
|
|
59
|
+
|
|
60
|
+
if @verify_web
|
|
61
|
+
lines << "Checked #{@checked} links in #{@docs.count} files (#{@web_checked} web URLs probed)."
|
|
62
|
+
else
|
|
63
|
+
lines << "Checked #{@checked} links in #{@docs.count} files (URL verification skipped)."
|
|
64
|
+
end
|
|
65
|
+
lines << ""
|
|
66
|
+
|
|
67
|
+
unless @unverified.empty?
|
|
68
|
+
lines << "📋 Unverified HTTP/HTTPS URLs (#{@unverified.size}):"
|
|
69
|
+
lines << ""
|
|
70
|
+
@unverified.uniq(&:raw).each { |link| lines << " #{link.raw}" }
|
|
71
|
+
lines << ""
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
if @problems.empty?
|
|
75
|
+
lines << "✅ No broken links found!"
|
|
76
|
+
else
|
|
77
|
+
lines << "❌ Found #{@problems.size} broken link(s):"
|
|
78
|
+
lines << ""
|
|
79
|
+
|
|
80
|
+
@problems.group_by(&:file).each do |path, problems|
|
|
81
|
+
lines << "#{path}:"
|
|
82
|
+
problems.each do |problem|
|
|
83
|
+
lines << " L#{problem.line || '?'}: #{problem.raw}"
|
|
84
|
+
lines << " → #{problem.reason}"
|
|
85
|
+
end
|
|
86
|
+
lines << ""
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
lines.join("\n")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private def scan # :nodoc:
|
|
94
|
+
@docs.each do |file|
|
|
95
|
+
file.links.each do |link|
|
|
96
|
+
@checked += 1
|
|
97
|
+
check(link)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
private def check(link) # :nodoc:
|
|
103
|
+
if link.web?
|
|
104
|
+
if @verify_web
|
|
105
|
+
@web_checked += 1
|
|
106
|
+
problem = link.problem(@root)
|
|
107
|
+
@problems << problem if problem
|
|
108
|
+
else
|
|
109
|
+
@unverified << link
|
|
110
|
+
end
|
|
111
|
+
else
|
|
112
|
+
problem = link.problem(@root)
|
|
113
|
+
@problems << problem if problem
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
# Represents a broken link.
|
|
9
|
+
#
|
|
10
|
+
# Link checking produces results. Some links are fine. Some are broken. You
|
|
11
|
+
# need to report the broken ones with context: where they were found and why
|
|
12
|
+
# they failed.
|
|
13
|
+
#
|
|
14
|
+
# Problem holds the link and the reason it failed. It delegates to the link
|
|
15
|
+
# for file, line, and raw text. Use it to build human-readable error reports.
|
|
16
|
+
#
|
|
17
|
+
# === Example
|
|
18
|
+
#
|
|
19
|
+
# problem = Problem.new(link, "File not found: missing.md")
|
|
20
|
+
# problem.file # => "doc/guide.md"
|
|
21
|
+
# problem.line # => 42
|
|
22
|
+
# problem.raw # => "missing.md"
|
|
23
|
+
# problem.reason # => "File not found: missing.md"
|
|
24
|
+
#
|
|
25
|
+
class Problem < Data.define(:link, :reason)
|
|
26
|
+
# Relative path to the file containing the broken link.
|
|
27
|
+
def file
|
|
28
|
+
link.source_file.relative_path
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Line number where the broken link appears.
|
|
32
|
+
def line
|
|
33
|
+
link.line
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The raw link text that failed validation.
|
|
37
|
+
def raw
|
|
38
|
+
link.raw
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
require "pathname"
|
|
9
|
+
require_relative "link"
|
|
10
|
+
|
|
11
|
+
# A file that may contain links.
|
|
12
|
+
#
|
|
13
|
+
# Documentation lives in many files: Ruby source with RDoc comments, Markdown
|
|
14
|
+
# guides, RDoc text files. Each file may reference images, other docs, or
|
|
15
|
+
# external URLs. Extracting these links by hand is tedious.
|
|
16
|
+
#
|
|
17
|
+
# SourceFile scans its content with regex patterns. It creates the appropriate
|
|
18
|
+
# Link subclass for each match. It tracks line numbers for error reporting.
|
|
19
|
+
#
|
|
20
|
+
# === Example
|
|
21
|
+
#
|
|
22
|
+
# file = SourceFile.new("/path/to/guide.md", "/project/root")
|
|
23
|
+
# file.links.each do |link|
|
|
24
|
+
# puts "#{link.raw} at line #{link.line}"
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
class SourceFile
|
|
28
|
+
# Regex patterns for extracting links from documentation.
|
|
29
|
+
PATTERNS = {
|
|
30
|
+
rdoc_image_link: /\{rdoc-image:([^}]+)\}\[link:([^\]]+)\]/,
|
|
31
|
+
rdoc_link: /\{[^}]*\}\[link:([^\]]+)\]/,
|
|
32
|
+
rdoc_image: /\{rdoc-image:([^}]+)\}/,
|
|
33
|
+
markdown_link: /\[(?:[^\]]*)\]\((?!mailto:|#)([^)\s]+)\)/,
|
|
34
|
+
markdown_image: /!\[[^\]]*\]\(([^)\s]+)\)/,
|
|
35
|
+
html_src: /src=["']([^"']+)["']/,
|
|
36
|
+
html_href: /href=["'](?!mailto:|#)([^"']+)["']/,
|
|
37
|
+
}.freeze
|
|
38
|
+
|
|
39
|
+
# The Pathname to this file.
|
|
40
|
+
attr_reader :path
|
|
41
|
+
|
|
42
|
+
# Creates a new SourceFile.
|
|
43
|
+
#
|
|
44
|
+
# [path] Path to the file (String or Pathname).
|
|
45
|
+
# [root] Project root directory for computing relative paths.
|
|
46
|
+
def initialize(path, root)
|
|
47
|
+
@path = Pathname.new(path)
|
|
48
|
+
@root = Pathname.new(root)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Extracts all links from the file content. Returns an Array of Link objects.
|
|
52
|
+
def links
|
|
53
|
+
found = []
|
|
54
|
+
|
|
55
|
+
PATTERNS.each_value do |pattern|
|
|
56
|
+
content.scan(pattern) do |matches|
|
|
57
|
+
matches = [matches] unless matches.is_a?(Array)
|
|
58
|
+
matches.each do |match|
|
|
59
|
+
next if match.nil? || match.empty?
|
|
60
|
+
next unless looks_like_link?(match)
|
|
61
|
+
found << Link.build(match, line_for(match), self)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
found
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# The file path relative to the project root.
|
|
70
|
+
def relative_path
|
|
71
|
+
@path.relative_path_from(@root).to_s
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private def content # :nodoc:
|
|
75
|
+
@content ||= @path.read(mode: "rb").force_encoding("UTF-8").scrub("")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private def line_for(link_text) # :nodoc:
|
|
79
|
+
line_num = 1
|
|
80
|
+
content.each_line do |line|
|
|
81
|
+
return line_num if line.include?(link_text)
|
|
82
|
+
line_num += 1
|
|
83
|
+
end
|
|
84
|
+
nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private def looks_like_link?(text) # :nodoc:
|
|
88
|
+
# Skip regex patterns and other false positives
|
|
89
|
+
return false if text.match?(/[\[\]^*+?]/) # Contains regex special chars
|
|
90
|
+
return false if text.length < 4
|
|
91
|
+
true
|
|
92
|
+
end
|
|
93
|
+
end
|
data/tasks/doc.rake
CHANGED
|
@@ -885,3 +885,21 @@ def build_guides_nav(parent_ul, tree, doc, prefix, current_file_rel, current_tre
|
|
|
885
885
|
parent_ul.add_child(li)
|
|
886
886
|
end
|
|
887
887
|
end
|
|
888
|
+
|
|
889
|
+
namespace :doc do
|
|
890
|
+
desc "Check for broken links in RDoc and Markdown files"
|
|
891
|
+
task :check_links do
|
|
892
|
+
require_relative "doc/link_audit"
|
|
893
|
+
|
|
894
|
+
root = File.expand_path("..", __dir__)
|
|
895
|
+
|
|
896
|
+
print "Verify HTTP/HTTPS URLs (slow)? [Y/n] "
|
|
897
|
+
$stdout.flush
|
|
898
|
+
verify_web = $stdin.gets&.strip&.downcase != "n"
|
|
899
|
+
|
|
900
|
+
audit = LinkAudit.new(root, verify_web:)
|
|
901
|
+
puts audit
|
|
902
|
+
|
|
903
|
+
exit 1 unless audit.success?
|
|
904
|
+
end
|
|
905
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
require "ratatui_ruby"
|
|
9
|
+
|
|
10
|
+
# Catalog of all key predicates sourced from Rust + Ruby generation.
|
|
11
|
+
class PredicateCatalog < Data.define(:base_keys, :media_keys, :modifier_keys, :keyboard_modifiers)
|
|
12
|
+
# ASCII printable characters that can be RBS method names (with backtick escaping)
|
|
13
|
+
# Excludes: space (0x20), backtick (`), and characters that break RBS parser (:, etc.)
|
|
14
|
+
RBS_INCOMPATIBLE = %w[` :].freeze
|
|
15
|
+
CHARACTERS = (0x21..0x7E).map(&:chr).reject { |c| RBS_INCOMPATIBLE.include?(c) }.freeze
|
|
16
|
+
# Function keys F1-F24 (conventional terminal range)
|
|
17
|
+
FUNCTION_KEYS = (1..24).map { |n| "f#{n}" }.freeze
|
|
18
|
+
|
|
19
|
+
def self.new
|
|
20
|
+
data = RatatuiRuby._all_key_codes
|
|
21
|
+
super(
|
|
22
|
+
base_keys: data[:base_keys],
|
|
23
|
+
media_keys: data[:media_keys],
|
|
24
|
+
modifier_keys: data[:modifier_keys],
|
|
25
|
+
keyboard_modifiers: data[:keyboard_modifiers]
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def characters = CHARACTERS
|
|
30
|
+
def function_keys = FUNCTION_KEYS
|
|
31
|
+
|
|
32
|
+
def all_base_codes
|
|
33
|
+
base_keys + media_keys + modifier_keys + characters + function_keys
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def modifier_combinations
|
|
37
|
+
mods = keyboard_modifiers.sort # Modifiers are stored sorted alphabetically
|
|
38
|
+
one = mods.map { |m| [m] }
|
|
39
|
+
two = mods.combination(2).map(&:sort)
|
|
40
|
+
three = mods.combination(3).map(&:sort)
|
|
41
|
+
one + two + three
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def all_predicates
|
|
45
|
+
simple = all_base_codes
|
|
46
|
+
combined = modifier_combinations.flat_map do |combo|
|
|
47
|
+
prefix = combo.join("_")
|
|
48
|
+
all_base_codes.map { |key| "#{prefix}_#{key}" }
|
|
49
|
+
end
|
|
50
|
+
simple + combined
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
require "fileutils"
|
|
9
|
+
|
|
10
|
+
# The generated Minitest file for Event::Key predicates.
|
|
11
|
+
# The tests know how to persist themselves to disk.
|
|
12
|
+
class PredicateTests < Data.define(:catalog, :output_path)
|
|
13
|
+
DEFAULT_OUTPUT = File.expand_path("../../test/generated/event_key_predicates_test.rb", __dir__)
|
|
14
|
+
|
|
15
|
+
def initialize(catalog:, output_path: DEFAULT_OUTPUT)
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def persist!
|
|
20
|
+
FileUtils.mkdir_p(File.dirname(output_path))
|
|
21
|
+
File.write(output_path, to_ruby)
|
|
22
|
+
puts "Generated #{test_methods.size} tests to #{output_path}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_ruby
|
|
26
|
+
<<~RUBY
|
|
27
|
+
# frozen_string_literal: true
|
|
28
|
+
|
|
29
|
+
#--
|
|
30
|
+
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
31
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
32
|
+
#++
|
|
33
|
+
|
|
34
|
+
# \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
35
|
+
# \u2551 \u26a0\ufe0f DO NOT EDIT THIS FILE \u26a0\ufe0f \u2551
|
|
36
|
+
# \u2551 \u2551
|
|
37
|
+
# \u2551 This file is auto-generated by: rake rbs:tests \u2551
|
|
38
|
+
# \u2551 Any manual changes will be overwritten on next generation. \u2551
|
|
39
|
+
# \u2551 \u2551
|
|
40
|
+
# \u2551 To modify tests, edit: tasks/rbs_predicates/predicate_tests.rb \u2551
|
|
41
|
+
# \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255d
|
|
42
|
+
|
|
43
|
+
require "test_helper"
|
|
44
|
+
|
|
45
|
+
class GeneratedEventKeyPredicatesTest < Minitest::Test
|
|
46
|
+
include RatatuiRuby::TestHelper
|
|
47
|
+
|
|
48
|
+
#{test_methods.map { |t| t.to_s.gsub(/^/, ' ') }.join("\n\n")}
|
|
49
|
+
end
|
|
50
|
+
RUBY
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private def test_methods
|
|
54
|
+
simple_tests + combo_tests
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private def simple_tests
|
|
58
|
+
catalog.all_base_codes.map { |code| SimplePredicateTest.new(code) }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private def combo_tests
|
|
62
|
+
sampled_combos.map { |combo| ModifierComboTest.new(combo) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private def sampled_combos
|
|
66
|
+
sample_keys = %w[a enter up f1]
|
|
67
|
+
catalog.modifier_combinations.product(sample_keys).map { |mods, key| mods + [key] }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# A single predicate test that knows how to render itself.
|
|
71
|
+
class SimplePredicateTest < Data.define(:code)
|
|
72
|
+
VALID_IDENTIFIER = /\A[a-z_][a-z0-9_]*\?\z/i
|
|
73
|
+
|
|
74
|
+
def to_s
|
|
75
|
+
<<~RUBY.chomp
|
|
76
|
+
def test_#{method_name}_predicate
|
|
77
|
+
RatatuiRuby.inject_test_event("key", { code: #{code.inspect} })
|
|
78
|
+
event = RatatuiRuby.poll_event
|
|
79
|
+
#{assertion}
|
|
80
|
+
end
|
|
81
|
+
RUBY
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private def predicate = "#{code}?"
|
|
85
|
+
private def method_name = code.gsub(/[^a-z0-9_]/i) { |c| "_#{c.ord}_" }
|
|
86
|
+
|
|
87
|
+
private def assertion
|
|
88
|
+
if predicate.match?(VALID_IDENTIFIER)
|
|
89
|
+
"assert event.#{predicate}"
|
|
90
|
+
else
|
|
91
|
+
"assert event.public_send(#{predicate.inspect})"
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# A modifier + key combo test that knows how to render itself.
|
|
97
|
+
class ModifierComboTest < Data.define(:combo)
|
|
98
|
+
VALID_IDENTIFIER = /\A[a-z_][a-z0-9_]*\?\z/i
|
|
99
|
+
|
|
100
|
+
def to_s
|
|
101
|
+
<<~RUBY.chomp
|
|
102
|
+
def test_#{method_name}_predicate
|
|
103
|
+
RatatuiRuby.inject_test_event("key", { code: #{key.inspect}, modifiers: [#{mods_array}] })
|
|
104
|
+
event = RatatuiRuby.poll_event
|
|
105
|
+
#{assertion}
|
|
106
|
+
end
|
|
107
|
+
RUBY
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private def key = combo.last
|
|
111
|
+
private def mods = combo[0...-1]
|
|
112
|
+
private def mods_array = mods.map(&:inspect).join(", ")
|
|
113
|
+
private def predicate = "#{combo.join('_')}?"
|
|
114
|
+
private def method_name = combo.join("_").gsub(/[^a-z0-9_]/i) { |c| "_#{c.ord}_" }
|
|
115
|
+
|
|
116
|
+
private def assertion
|
|
117
|
+
if predicate.match?(VALID_IDENTIFIER)
|
|
118
|
+
"assert event.#{predicate}"
|
|
119
|
+
else
|
|
120
|
+
"assert event.public_send(#{predicate.inspect})"
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
# RBS signature file for Event::Key predicates.
|
|
9
|
+
class RbsSignature < Data.define(:catalog, :output_path)
|
|
10
|
+
DEFAULT_OUTPUT = File.expand_path("../../sig/generated/event_key_predicates.rbs", __dir__)
|
|
11
|
+
|
|
12
|
+
def initialize(catalog:, output_path: DEFAULT_OUTPUT)
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def write
|
|
17
|
+
FileUtils.mkdir_p(File.dirname(output_path))
|
|
18
|
+
File.write(output_path, content)
|
|
19
|
+
puts "Generated #{catalog.all_predicates.size} predicates to #{output_path}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def content
|
|
23
|
+
<<~RBS
|
|
24
|
+
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
25
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
26
|
+
#
|
|
27
|
+
# ╔═══════════════════════════════════════════════════════════════════╗
|
|
28
|
+
# ║ ⚠️ DO NOT EDIT THIS FILE ⚠️ ║
|
|
29
|
+
# ║ ║
|
|
30
|
+
# ║ This file is auto-generated by: rake rbs:predicates ║
|
|
31
|
+
# ║ Any manual changes will be overwritten on next generation. ║
|
|
32
|
+
# ║ ║
|
|
33
|
+
# ║ To modify predicates, edit the source in: ║
|
|
34
|
+
# ║ - ext/ratatui_ruby/src/events.rs (key mappings) ║
|
|
35
|
+
# ║ - tasks/rbs_predicates/predicate_catalog.rb ║
|
|
36
|
+
# ╚═══════════════════════════════════════════════════════════════════╝
|
|
37
|
+
|
|
38
|
+
module RatatuiRuby
|
|
39
|
+
class Event
|
|
40
|
+
class Key < Event
|
|
41
|
+
#{predicate_declarations.map { |d| " #{d}" }.join("\n")}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
RBS
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private def predicate_declarations
|
|
49
|
+
catalog.all_predicates.map { |name| rbs_method_def(name) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Valid Ruby method identifier: starts with letter/underscore, followed by word chars, optional ?
|
|
53
|
+
VALID_PREDICATE_PATTERN = /\A[a-z_][a-z0-9_]*\?\z/i
|
|
54
|
+
|
|
55
|
+
def rbs_method_def(name)
|
|
56
|
+
method_name = "#{name}?"
|
|
57
|
+
if method_name.match?(VALID_PREDICATE_PATTERN)
|
|
58
|
+
"def #{method_name}: () -> bool"
|
|
59
|
+
else
|
|
60
|
+
"def `#{method_name}`: () -> bool"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|