ratatui_ruby 1.0.0 → 1.0.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.
- checksums.yaml +4 -4
- data/ext/ratatui_ruby/Cargo.lock +1 -1
- data/ext/ratatui_ruby/Cargo.toml +1 -1
- data/lib/ratatui_ruby/version.rb +1 -1
- metadata +1 -232
- data/.builds/ruby-3.2.yml +0 -54
- data/.builds/ruby-3.3.yml +0 -54
- data/.builds/ruby-3.4.yml +0 -54
- data/.builds/ruby-4.0.0.yml +0 -54
- data/.pre-commit-config.yaml +0 -16
- data/.rubocop.yml +0 -10
- data/AGENTS.md +0 -146
- data/CHANGELOG.md +0 -710
- data/README.md +0 -187
- data/README.rdoc +0 -302
- data/Rakefile +0 -11
- data/Steepfile +0 -49
- data/doc/concepts/application_architecture.md +0 -321
- data/doc/concepts/application_testing.md +0 -193
- data/doc/concepts/async.md +0 -190
- data/doc/concepts/custom_widgets.md +0 -247
- data/doc/concepts/debugging.md +0 -401
- data/doc/concepts/event_handling.md +0 -162
- data/doc/concepts/interactive_design.md +0 -146
- data/doc/contributors/auditing/parity.md +0 -239
- data/doc/contributors/design/ruby_frontend.md +0 -420
- data/doc/contributors/design/rust_backend.md +0 -422
- data/doc/contributors/design.md +0 -11
- data/doc/contributors/developing_examples.md +0 -400
- data/doc/contributors/documentation_style.md +0 -121
- data/doc/contributors/index.md +0 -21
- data/doc/contributors/todo/align/api_completeness_audit-finished.md +0 -375
- data/doc/contributors/todo/align/api_completeness_audit-unfinished.md +0 -206
- data/doc/contributors/todo/align/terminal.md +0 -647
- data/doc/contributors/todo/future_work.md +0 -169
- data/doc/contributors/upstream_requests/tab_rects.md +0 -173
- data/doc/contributors/upstream_requests/title_rects.md +0 -132
- data/doc/custom.css +0 -22
- data/doc/getting_started/quickstart.md +0 -291
- data/doc/getting_started/why.md +0 -93
- data/doc/images/app_all_events.png +0 -0
- data/doc/images/app_cli_rich_moments.gif +0 -0
- data/doc/images/app_color_picker.png +0 -0
- data/doc/images/app_debugging_showcase.gif +0 -0
- data/doc/images/app_debugging_showcase.png +0 -0
- data/doc/images/app_login_form.png +0 -0
- data/doc/images/app_stateful_interaction.png +0 -0
- data/doc/images/verify_quickstart_dsl.png +0 -0
- data/doc/images/verify_quickstart_layout.png +0 -0
- data/doc/images/verify_quickstart_lifecycle.png +0 -0
- data/doc/images/verify_readme_usage.png +0 -0
- data/doc/images/widget_barchart.png +0 -0
- data/doc/images/widget_block.png +0 -0
- data/doc/images/widget_box.png +0 -0
- data/doc/images/widget_calendar.png +0 -0
- data/doc/images/widget_canvas.png +0 -0
- data/doc/images/widget_cell.png +0 -0
- data/doc/images/widget_center.png +0 -0
- data/doc/images/widget_chart.png +0 -0
- data/doc/images/widget_gauge.png +0 -0
- data/doc/images/widget_layout_split.png +0 -0
- data/doc/images/widget_line_gauge.png +0 -0
- data/doc/images/widget_list.png +0 -0
- data/doc/images/widget_map.png +0 -0
- data/doc/images/widget_overlay.png +0 -0
- data/doc/images/widget_popup.png +0 -0
- data/doc/images/widget_ratatui_logo.png +0 -0
- data/doc/images/widget_ratatui_mascot.png +0 -0
- data/doc/images/widget_rect.png +0 -0
- data/doc/images/widget_render.png +0 -0
- data/doc/images/widget_rich_text.png +0 -0
- data/doc/images/widget_scroll_text.png +0 -0
- data/doc/images/widget_scrollbar.png +0 -0
- data/doc/images/widget_sparkline.png +0 -0
- data/doc/images/widget_style_colors.png +0 -0
- data/doc/images/widget_table.png +0 -0
- data/doc/images/widget_tabs.png +0 -0
- data/doc/images/widget_text_width.png +0 -0
- data/doc/index.md +0 -39
- data/doc/troubleshooting/async.md +0 -4
- data/doc/troubleshooting/terminal_limitations.md +0 -131
- data/doc/troubleshooting/tui_output.md +0 -197
- data/examples/app_all_events/README.md +0 -114
- data/examples/app_all_events/app.rb +0 -98
- data/examples/app_all_events/model/app_model.rb +0 -159
- data/examples/app_all_events/model/event_color_cycle.rb +0 -43
- data/examples/app_all_events/model/event_entry.rb +0 -94
- data/examples/app_all_events/model/msg.rb +0 -39
- data/examples/app_all_events/model/timestamp.rb +0 -56
- data/examples/app_all_events/update.rb +0 -75
- data/examples/app_all_events/view/app_view.rb +0 -80
- data/examples/app_all_events/view/controls_view.rb +0 -54
- data/examples/app_all_events/view/counts_view.rb +0 -61
- data/examples/app_all_events/view/live_view.rb +0 -72
- data/examples/app_all_events/view/log_view.rb +0 -57
- data/examples/app_all_events/view.rb +0 -9
- data/examples/app_cli_rich_moments/README.md +0 -81
- data/examples/app_cli_rich_moments/app.rb +0 -189
- data/examples/app_color_picker/README.md +0 -156
- data/examples/app_color_picker/app.rb +0 -76
- data/examples/app_color_picker/clipboard.rb +0 -86
- data/examples/app_color_picker/color.rb +0 -193
- data/examples/app_color_picker/controls.rb +0 -92
- data/examples/app_color_picker/copy_dialog.rb +0 -168
- data/examples/app_color_picker/export_pane.rb +0 -128
- data/examples/app_color_picker/harmony.rb +0 -58
- data/examples/app_color_picker/input.rb +0 -176
- data/examples/app_color_picker/main_container.rb +0 -180
- data/examples/app_color_picker/palette.rb +0 -111
- data/examples/app_debugging_showcase/README.md +0 -119
- data/examples/app_debugging_showcase/app.rb +0 -318
- data/examples/app_login_form/README.md +0 -58
- data/examples/app_login_form/app.rb +0 -109
- data/examples/app_stateful_interaction/README.md +0 -35
- data/examples/app_stateful_interaction/app.rb +0 -328
- data/examples/timeout_demo.rb +0 -45
- data/examples/verify_quickstart_dsl/README.md +0 -55
- data/examples/verify_quickstart_dsl/app.rb +0 -49
- data/examples/verify_quickstart_layout/README.md +0 -77
- data/examples/verify_quickstart_layout/app.rb +0 -73
- data/examples/verify_quickstart_lifecycle/README.md +0 -68
- data/examples/verify_quickstart_lifecycle/app.rb +0 -62
- data/examples/verify_readme_usage/README.md +0 -49
- data/examples/verify_readme_usage/app.rb +0 -42
- data/examples/verify_website_managed/README.md +0 -48
- data/examples/verify_website_managed/app.rb +0 -36
- data/examples/verify_website_menu/README.md +0 -60
- data/examples/verify_website_menu/app.rb +0 -84
- data/examples/verify_website_spinner/README.md +0 -44
- data/examples/verify_website_spinner/app.rb +0 -34
- data/examples/widget_barchart/README.md +0 -58
- data/examples/widget_barchart/app.rb +0 -240
- data/examples/widget_block/README.md +0 -44
- data/examples/widget_block/app.rb +0 -258
- data/examples/widget_box/README.md +0 -54
- data/examples/widget_box/app.rb +0 -255
- data/examples/widget_calendar/README.md +0 -48
- data/examples/widget_calendar/app.rb +0 -115
- data/examples/widget_canvas/README.md +0 -31
- data/examples/widget_canvas/app.rb +0 -130
- data/examples/widget_cell/README.md +0 -45
- data/examples/widget_cell/app.rb +0 -112
- data/examples/widget_center/README.md +0 -33
- data/examples/widget_center/app.rb +0 -118
- data/examples/widget_chart/README.md +0 -50
- data/examples/widget_chart/app.rb +0 -220
- data/examples/widget_gauge/README.md +0 -50
- data/examples/widget_gauge/app.rb +0 -229
- data/examples/widget_layout_split/README.md +0 -53
- data/examples/widget_layout_split/app.rb +0 -260
- data/examples/widget_line_gauge/README.md +0 -50
- data/examples/widget_line_gauge/app.rb +0 -219
- data/examples/widget_list/README.md +0 -58
- data/examples/widget_list/app.rb +0 -384
- data/examples/widget_map/README.md +0 -48
- data/examples/widget_map/app.rb +0 -95
- data/examples/widget_overlay/README.md +0 -45
- data/examples/widget_overlay/app.rb +0 -250
- data/examples/widget_popup/README.md +0 -45
- data/examples/widget_popup/app.rb +0 -106
- data/examples/widget_ratatui_logo/README.md +0 -43
- data/examples/widget_ratatui_logo/app.rb +0 -104
- data/examples/widget_ratatui_mascot/README.md +0 -43
- data/examples/widget_ratatui_mascot/app.rb +0 -95
- data/examples/widget_rect/README.md +0 -53
- data/examples/widget_rect/app.rb +0 -222
- data/examples/widget_render/README.md +0 -46
- data/examples/widget_render/app.rb +0 -186
- data/examples/widget_render/app.rbs +0 -41
- data/examples/widget_rich_text/README.md +0 -44
- data/examples/widget_rich_text/app.rb +0 -193
- data/examples/widget_scroll_text/README.md +0 -46
- data/examples/widget_scroll_text/app.rb +0 -109
- data/examples/widget_scrollbar/README.md +0 -46
- data/examples/widget_scrollbar/app.rb +0 -155
- data/examples/widget_sparkline/README.md +0 -51
- data/examples/widget_sparkline/app.rb +0 -277
- data/examples/widget_style_colors/README.md +0 -43
- data/examples/widget_style_colors/app.rb +0 -83
- data/examples/widget_table/README.md +0 -57
- data/examples/widget_table/app.rb +0 -279
- data/examples/widget_tabs/README.md +0 -50
- data/examples/widget_tabs/app.rb +0 -183
- data/examples/widget_text_width/README.md +0 -44
- data/examples/widget_text_width/app.rb +0 -117
- data/migrate_to_buffer.rb +0 -145
- data/mise.toml +0 -8
- data/tasks/autodoc/examples.rb +0 -87
- data/tasks/autodoc/member.rb +0 -58
- data/tasks/autodoc/name.rb +0 -21
- data/tasks/autodoc.rake +0 -21
- data/tasks/bump/cargo_lockfile.rb +0 -21
- data/tasks/bump/changelog.rb +0 -47
- data/tasks/bump/header.rb +0 -32
- data/tasks/bump/history.rb +0 -32
- data/tasks/bump/links.rb +0 -69
- data/tasks/bump/manifest.rb +0 -33
- data/tasks/bump/ruby_gem.rb +0 -49
- data/tasks/bump/sem_ver.rb +0 -40
- data/tasks/bump/unreleased_section.rb +0 -56
- data/tasks/bump.rake +0 -51
- data/tasks/doc.rake +0 -887
- data/tasks/example_viewer.html.erb +0 -172
- data/tasks/extension.rake +0 -14
- data/tasks/license/headers_md.rb +0 -223
- data/tasks/license/headers_rb.rb +0 -210
- data/tasks/license/license_utils.rb +0 -130
- data/tasks/license/snippets_md.rb +0 -315
- data/tasks/license/snippets_rdoc.rb +0 -150
- data/tasks/license.rake +0 -91
- data/tasks/lint.rake +0 -170
- data/tasks/rdoc_config.rb +0 -29
- data/tasks/resources/build.yml.erb +0 -60
- data/tasks/resources/index.html.erb +0 -141
- data/tasks/resources/rubies.yml +0 -7
- data/tasks/sourcehut.rake +0 -110
- data/tasks/steep.rake +0 -11
- data/tasks/terminal_preview/app_screenshot.rb +0 -45
- data/tasks/terminal_preview/crash_report.rb +0 -54
- data/tasks/terminal_preview/example_app.rb +0 -27
- data/tasks/terminal_preview/launcher_script.rb +0 -48
- data/tasks/terminal_preview/preview_collection.rb +0 -60
- data/tasks/terminal_preview/preview_timing.rb +0 -24
- data/tasks/terminal_preview/safety_confirmation.rb +0 -58
- data/tasks/terminal_preview/saved_screenshot.rb +0 -56
- data/tasks/terminal_preview/system_appearance.rb +0 -13
- data/tasks/terminal_preview/terminal_window.rb +0 -138
- data/tasks/terminal_preview/window_id.rb +0 -16
- data/tasks/terminal_preview.rake +0 -30
- data/tasks/test.rake +0 -33
- data/tasks/website/index_page.rb +0 -30
- data/tasks/website/version.rb +0 -127
- data/tasks/website/version_menu.rb +0 -68
- data/tasks/website/versioned_documentation.rb +0 -83
- data/tasks/website/website.rb +0 -53
- data/tasks/website.rake +0 -28
|
@@ -1,189 +0,0 @@
|
|
|
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
|
-
$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
|
|
9
|
-
require "ratatui_ruby"
|
|
10
|
-
|
|
11
|
-
class AppCliRichMoments
|
|
12
|
-
SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"].freeze
|
|
13
|
-
MENU_OPTIONS = [
|
|
14
|
-
"Development Environment",
|
|
15
|
-
"Staging Environment",
|
|
16
|
-
"Production Environment",
|
|
17
|
-
].freeze
|
|
18
|
-
|
|
19
|
-
def initialize
|
|
20
|
-
@selected_index = 0
|
|
21
|
-
@choice = nil
|
|
22
|
-
@tui = RatatuiRuby::TUI.new
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def run
|
|
26
|
-
phase_connecting
|
|
27
|
-
@choice = phase_menu
|
|
28
|
-
phase_editor
|
|
29
|
-
phase_saving
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private def phase_connecting
|
|
33
|
-
RatatuiRuby.run(viewport: :inline, height: 1) do
|
|
34
|
-
10.times do |i|
|
|
35
|
-
render_spinner(SPINNER_FRAMES[i % SPINNER_FRAMES.length], "Connecting to server...")
|
|
36
|
-
sleep 0.1
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Insert success message above viewport into scrollback
|
|
40
|
-
status = "✓ Connected to server"
|
|
41
|
-
@tui.insert_before(1, @tui.paragraph(text: status, style: @tui.style(fg: :green)))
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
private def phase_menu
|
|
46
|
-
RatatuiRuby.run(viewport: :inline, height: 5) do
|
|
47
|
-
loop do
|
|
48
|
-
render_menu
|
|
49
|
-
case handle_menu_input
|
|
50
|
-
when :quit, :select
|
|
51
|
-
# Position cursor after viewport for next phase
|
|
52
|
-
area = @tui.viewport_area
|
|
53
|
-
|
|
54
|
-
# # If you wanted to remove the menu from scrollback, you could do:
|
|
55
|
-
# @tui.draw { |frame| frame.render_widget(@tui.clear, frame.area) }
|
|
56
|
-
# # And move the cursor to avoid extra blank space.
|
|
57
|
-
# RatatuiRuby.cursor_position = [0, area.y]
|
|
58
|
-
|
|
59
|
-
# But instead, we'll leave it in scrollback for reference.
|
|
60
|
-
# Move the cursor to avoid overwriting it.
|
|
61
|
-
RatatuiRuby.cursor_position = [0, area.y + area.height]
|
|
62
|
-
|
|
63
|
-
return MENU_OPTIONS[@selected_index]
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
private def phase_editor
|
|
70
|
-
RatatuiRuby.run do # Fullscreen by default
|
|
71
|
-
loop do
|
|
72
|
-
render_editor
|
|
73
|
-
break if handle_editor_input == :quit
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
private def phase_saving
|
|
79
|
-
RatatuiRuby.run(viewport: :inline, height: 1) do
|
|
80
|
-
10.times do |i|
|
|
81
|
-
render_spinner(SPINNER_FRAMES[i % SPINNER_FRAMES.length], "Saving configuration...")
|
|
82
|
-
sleep 0.1
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
status = "✓ Configuration saved to #{@choice.downcase.gsub(' ', '_')}.yml"
|
|
86
|
-
@tui.insert_before(1, @tui.paragraph(text: status, style: @tui.style(fg: :green)))
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
private def render_spinner(frame, message)
|
|
91
|
-
@tui.draw do |f|
|
|
92
|
-
text = "#{frame} #{message}"
|
|
93
|
-
widget = @tui.paragraph(text:, style: @tui.style(fg: :cyan))
|
|
94
|
-
f.render_widget(widget, f.area)
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
private def render_menu
|
|
99
|
-
@tui.draw do |f|
|
|
100
|
-
lines = MENU_OPTIONS.map.with_index do |option, idx|
|
|
101
|
-
prefix = (idx == @selected_index) ? "→ " : " "
|
|
102
|
-
style = (idx == @selected_index) ? @tui.style(fg: :cyan, modifiers: [:bold]) : @tui.style(fg: :white)
|
|
103
|
-
@tui.text_line(spans: [@tui.text_span(content: "#{prefix}#{option}", style:)])
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
widget = @tui.paragraph(
|
|
107
|
-
text: lines,
|
|
108
|
-
block: @tui.block(borders: :all, title: "Select Environment")
|
|
109
|
-
)
|
|
110
|
-
f.render_widget(widget, f.area)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
private def render_editor
|
|
115
|
-
@tui.draw do |f|
|
|
116
|
-
areas = @tui.layout_split(
|
|
117
|
-
f.area,
|
|
118
|
-
direction: :vertical,
|
|
119
|
-
constraints: [
|
|
120
|
-
@tui.constraint_fill(1),
|
|
121
|
-
@tui.constraint_length(3),
|
|
122
|
-
]
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
# Main content area
|
|
126
|
-
content_text = [
|
|
127
|
-
"Editing: #{@choice}",
|
|
128
|
-
"",
|
|
129
|
-
"# Database Configuration",
|
|
130
|
-
"database:",
|
|
131
|
-
" adapter: postgresql",
|
|
132
|
-
" host: db.example.com",
|
|
133
|
-
" port: 5432",
|
|
134
|
-
"",
|
|
135
|
-
"# Cache Configuration",
|
|
136
|
-
"cache:",
|
|
137
|
-
" provider: redis",
|
|
138
|
-
" ttl: 3600",
|
|
139
|
-
].join("\n")
|
|
140
|
-
|
|
141
|
-
content = @tui.paragraph(
|
|
142
|
-
text: content_text,
|
|
143
|
-
block: @tui.block(borders: :all, title: "Configuration Editor"),
|
|
144
|
-
style: @tui.style(fg: :yellow)
|
|
145
|
-
)
|
|
146
|
-
f.render_widget(content, areas[0])
|
|
147
|
-
|
|
148
|
-
# Help panel
|
|
149
|
-
help_text = "q: Save and Exit | Ctrl+C: Cancel"
|
|
150
|
-
help = @tui.paragraph(
|
|
151
|
-
text: help_text,
|
|
152
|
-
block: @tui.block(borders: :all),
|
|
153
|
-
style: @tui.style(fg: :dark_gray),
|
|
154
|
-
alignment: :center
|
|
155
|
-
)
|
|
156
|
-
f.render_widget(help, areas[1])
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
private def handle_menu_input
|
|
161
|
-
case @tui.poll_event
|
|
162
|
-
in { type: :key, code: "q" } | { type: :key, code: "c", modifiers: ["ctrl"] }
|
|
163
|
-
:quit
|
|
164
|
-
in { type: :key, code: "enter" }
|
|
165
|
-
:select
|
|
166
|
-
in { type: :key, code: "up" }
|
|
167
|
-
@selected_index = (@selected_index - 1) % MENU_OPTIONS.length
|
|
168
|
-
nil
|
|
169
|
-
in { type: :key, code: "down" }
|
|
170
|
-
@selected_index = (@selected_index + 1) % MENU_OPTIONS.length
|
|
171
|
-
nil
|
|
172
|
-
else
|
|
173
|
-
nil
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
private def handle_editor_input
|
|
178
|
-
case @tui.poll_event
|
|
179
|
-
in { type: :key, code: "q" }
|
|
180
|
-
:quit # "and save," presumably
|
|
181
|
-
in { type: :key, code: "c", modifiers: ["ctrl"] }
|
|
182
|
-
:quit
|
|
183
|
-
else
|
|
184
|
-
nil
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
AppCliRichMoments.new.run if __FILE__ == $PROGRAM_NAME
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
-
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
-
-->
|
|
5
|
-
|
|
6
|
-
# Color Picker Example
|
|
7
|
-
|
|
8
|
-
[](app.rb)
|
|
9
|
-
|
|
10
|
-
This example demonstrates how to build a **Feature-Rich Interactive Application** using `ratatui_ruby`.
|
|
11
|
-
|
|
12
|
-
It goes beyond simple widgets to show a complete, real-world architecture for handling:
|
|
13
|
-
- **Complex State Management** (Input validation, clipboard interaction)
|
|
14
|
-
- **Mouse Interaction & Hit Testing**
|
|
15
|
-
- **Dynamic Layouts**
|
|
16
|
-
- **Modal Dialogs**
|
|
17
|
-
|
|
18
|
-
## Architecture: Component-Based
|
|
19
|
-
|
|
20
|
-
This app uses a **Strict Component-Based Architecture** where every UI element encapsulates its own **Rendering**, **State**, and **Event Handling**.
|
|
21
|
-
|
|
22
|
-
### The Component Contract
|
|
23
|
-
|
|
24
|
-
Every component implements this duck-type interface:
|
|
25
|
-
|
|
26
|
-
<!-- SPDX-SnippetBegin -->
|
|
27
|
-
<!--
|
|
28
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
29
|
-
SPDX-License-Identifier: MIT-0
|
|
30
|
-
-->
|
|
31
|
-
```ruby
|
|
32
|
-
# Renders the component into the given area
|
|
33
|
-
# Caches `area` for hit testing
|
|
34
|
-
def render(tui, frame, area)
|
|
35
|
-
@area = area
|
|
36
|
-
# ... render using frame.render_widget
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Processes events; returns a symbolic signal or nil
|
|
40
|
-
def handle_event(event) -> Symbol | nil
|
|
41
|
-
# Returns :consumed, :submitted, :copy_requested, etc.
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Optional: time-based updates
|
|
45
|
-
def tick
|
|
46
|
-
end
|
|
47
|
-
```
|
|
48
|
-
<!-- SPDX-SnippetEnd -->
|
|
49
|
-
|
|
50
|
-
### 1. The MainContainer (Orchestrator)
|
|
51
|
-
|
|
52
|
-
The `MainContainer` class (`main_container.rb`) owns all child components and orchestrates the UI:
|
|
53
|
-
|
|
54
|
-
- **Layout Phase:** Calculates `Rect`s using `tui.layout_split`.
|
|
55
|
-
- **Delegation Phase:** Calls `child.render(tui, frame, child_area)` for each component.
|
|
56
|
-
- **Event Routing (Chain of Responsibility):** Delegates events front-to-back. The modal dialog gets priority when active.
|
|
57
|
-
- **Mediator Pattern:** Interprets symbolic signals (`:submitted`, `:copy_requested`) to coordinate cross-component effects.
|
|
58
|
-
|
|
59
|
-
### 2. Self-Contained Components
|
|
60
|
-
|
|
61
|
-
Each UI element is a self-contained component:
|
|
62
|
-
|
|
63
|
-
- **`Input`**: Text entry with validation. Returns `:submitted` when Enter is pressed.
|
|
64
|
-
- **`Palette`**: Displays color harmonies. Accepts `update_color` from the container.
|
|
65
|
-
- **`ExportPane`**: Shows HEX/RGB/HSL formats. Returns `:copy_requested` when clicked.
|
|
66
|
-
- **`Controls`**: Displays keyboard shortcuts. Has a `tick` lifecycle for clipboard feedback.
|
|
67
|
-
- **`CopyDialog`**: Modal confirmation dialog. Returns `:consumed` when handling events.
|
|
68
|
-
|
|
69
|
-
### 3. The App (Minimal Runner)
|
|
70
|
-
|
|
71
|
-
The `App` class (`app.rb`) is a thin runner:
|
|
72
|
-
- Creates the `MainContainer`.
|
|
73
|
-
- Runs the main loop: `tick` → `render` → `poll` → `handle_event`.
|
|
74
|
-
- Checks for quit events.
|
|
75
|
-
|
|
76
|
-
## Key Features Showcased
|
|
77
|
-
|
|
78
|
-
### 🖱️ Encapsulated Hit Testing
|
|
79
|
-
|
|
80
|
-
Components cache their render area (`@area`) during `render`. In `handle_event`, they check `@area&.contains?(x, y)` to detect clicks. The container never calculates coordinates—hit testing is fully encapsulated.
|
|
81
|
-
|
|
82
|
-
### 🔲 Modal Dialogs via Chain of Responsibility
|
|
83
|
-
|
|
84
|
-
When `CopyDialog` is active, the `MainContainer` offers it events first. If it returns `:consumed`, event propagation stops. This creates modal behavior without explicit flags in the app.
|
|
85
|
-
|
|
86
|
-
### 📡 Symbolic Signals (Mediator Pattern)
|
|
87
|
-
|
|
88
|
-
Components return semantic symbols instead of just `:consumed`:
|
|
89
|
-
- `Input` returns `:submitted` when the user presses Enter.
|
|
90
|
-
- `ExportPane` returns `:copy_requested` when clicked.
|
|
91
|
-
|
|
92
|
-
The `MainContainer` interprets these signals to coordinate cross-component communication:
|
|
93
|
-
|
|
94
|
-
<!-- SPDX-SnippetBegin -->
|
|
95
|
-
<!--
|
|
96
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
97
|
-
SPDX-License-Identifier: MIT-0
|
|
98
|
-
-->
|
|
99
|
-
```ruby
|
|
100
|
-
result = @input.handle_event(event)
|
|
101
|
-
case result
|
|
102
|
-
when :submitted
|
|
103
|
-
@palette.update_color(@input.parsed_color)
|
|
104
|
-
return :consumed
|
|
105
|
-
end
|
|
106
|
-
```
|
|
107
|
-
<!-- SPDX-SnippetEnd -->
|
|
108
|
-
|
|
109
|
-
### ⏱️ Lifecycle Hooks (`tick`)
|
|
110
|
-
|
|
111
|
-
Components can have time-based updates. `Controls#tick` delegates to `Clipboard#tick` to decrement the feedback timer.
|
|
112
|
-
|
|
113
|
-
## Problem Solving: What You Can Learn
|
|
114
|
-
|
|
115
|
-
Read this example if you are trying to solve:
|
|
116
|
-
1. **"How do I structure a larger app?"** → Use the Component Contract and a Container for orchestration.
|
|
117
|
-
2. **"How do I handle mouse clicks?"** → Cache `@area` during render; check `contains?` in `handle_event`.
|
|
118
|
-
3. **"How do I make a popup?"** → Use Chain of Responsibility: the active modal gets events first.
|
|
119
|
-
4. **"How do I coordinate between components?"** → Use symbolic signals and the Mediator pattern.
|
|
120
|
-
5. **"How do I validate input?"** → Encapsulate validation inside the `Input` component.
|
|
121
|
-
|
|
122
|
-
## Usage
|
|
123
|
-
|
|
124
|
-
<!-- SPDX-SnippetBegin -->
|
|
125
|
-
<!--
|
|
126
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
127
|
-
SPDX-License-Identifier: MIT-0
|
|
128
|
-
-->
|
|
129
|
-
```bash
|
|
130
|
-
ruby examples/app_color_picker/app.rb
|
|
131
|
-
```
|
|
132
|
-
<!-- SPDX-SnippetEnd -->
|
|
133
|
-
|
|
134
|
-
- Type a hex code (e.g., `#FF0055`) or color name (`cyan`).
|
|
135
|
-
- Press `Enter` to generate the palette.
|
|
136
|
-
- Click on the **Export Formats** box to copy the hex code.
|
|
137
|
-
|
|
138
|
-
## Comparison: Choosing an Architecture
|
|
139
|
-
|
|
140
|
-
Complex applications require structured state habits. This Color Picker and the [App All Events](../app_all_events/README.md) example demonstrate two different approaches.
|
|
141
|
-
|
|
142
|
-
### The Tool Approach (Color Picker)
|
|
143
|
-
|
|
144
|
-
Tools require interaction. Users click buttons and drag sliders. Components need to know where they exist on screen for hit testing. The Container orchestrates cross-component effects.
|
|
145
|
-
|
|
146
|
-
This example uses a **Component-Based** pattern. Each component owns its own state, rendering, and event handling. The Container routes events and mediates communication.
|
|
147
|
-
|
|
148
|
-
Use this pattern for forms, editors, and mouse-driven tools.
|
|
149
|
-
|
|
150
|
-
### The Dashboard Approach (AppAllEvents)
|
|
151
|
-
|
|
152
|
-
Dashboards display data. They rarely require complex mouse interaction. Model-View-Update works best there. State is immutable. Logic is pure. Updates are predictable. This simplifies testing.
|
|
153
|
-
|
|
154
|
-
Use that pattern for logs, monitors, and data viewers.
|
|
155
|
-
|
|
156
|
-
[Read the source code →](app.rb)
|
|
@@ -1,76 +0,0 @@
|
|
|
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
|
-
$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
|
|
9
|
-
$LOAD_PATH.unshift File.expand_path(__dir__)
|
|
10
|
-
|
|
11
|
-
require "ratatui_ruby"
|
|
12
|
-
require_relative "main_container"
|
|
13
|
-
|
|
14
|
-
# A terminal-based color picker application.
|
|
15
|
-
#
|
|
16
|
-
# Terminal users often need to select colors for themes or UI components.
|
|
17
|
-
# Manually typing hex codes and guessing how they will look is slow and error-prone.
|
|
18
|
-
#
|
|
19
|
-
# This application solves the problem by providing an interactive interface. It parses hex strings,
|
|
20
|
-
# generates palettes, and displays them visually in the terminal.
|
|
21
|
-
#
|
|
22
|
-
# === Architecture
|
|
23
|
-
#
|
|
24
|
-
# This example uses a Component-Based pattern:
|
|
25
|
-
# - **Components**: Self-contained UI elements with `render`, `handle_event`, and optional `tick`
|
|
26
|
-
# - **Container**: Owns layout, delegates to children, routes events via Chain of Responsibility
|
|
27
|
-
# - **Mediator**: Container interprets symbolic signals (`:consumed`, `:submitted`) for cross-component effects
|
|
28
|
-
#
|
|
29
|
-
# === Examples
|
|
30
|
-
#
|
|
31
|
-
# AppColorPicker.new.run
|
|
32
|
-
#
|
|
33
|
-
class AppColorPicker
|
|
34
|
-
# Creates a new <tt>AppColorPicker</tt> instance.
|
|
35
|
-
def initialize
|
|
36
|
-
@container = nil
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Starts the terminal session and enters the main event loop.
|
|
40
|
-
#
|
|
41
|
-
# This method initializes the terminal, creates the MainContainer, and runs
|
|
42
|
-
# the event loop until the user quits.
|
|
43
|
-
#
|
|
44
|
-
# === Example
|
|
45
|
-
#
|
|
46
|
-
# app = AppColorPicker.new
|
|
47
|
-
# app.run
|
|
48
|
-
#
|
|
49
|
-
def run
|
|
50
|
-
RatatuiRuby.run do |tui|
|
|
51
|
-
@container = MainContainer.new(tui)
|
|
52
|
-
|
|
53
|
-
loop do
|
|
54
|
-
@container.tick
|
|
55
|
-
tui.draw { |frame| @container.render(tui, frame, frame.area) }
|
|
56
|
-
|
|
57
|
-
event = tui.poll_event
|
|
58
|
-
break if quit_event?(event)
|
|
59
|
-
|
|
60
|
-
@container.handle_event(event)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
private def quit_event?(event)
|
|
66
|
-
case event
|
|
67
|
-
in { type: :key, code: "q" } | { type: :key, code: "esc" } |
|
|
68
|
-
{ type: :key, code: "c", modifiers: [/ctrl/] }
|
|
69
|
-
true
|
|
70
|
-
else
|
|
71
|
-
false
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
AppColorPicker.new.run if __FILE__ == $PROGRAM_NAME
|
|
@@ -1,86 +0,0 @@
|
|
|
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
|
-
# Manages system clipboard interaction with transient feedback.
|
|
9
|
-
#
|
|
10
|
-
# Apps need to copy data to the clipboard. Users need feedback: "Did it work?"
|
|
11
|
-
# Manual clipboard handling and feedback timers scattered through app logic is
|
|
12
|
-
# messy.
|
|
13
|
-
#
|
|
14
|
-
# This object handles clipboard writes to all platforms (pbcopy, xclip, xsel).
|
|
15
|
-
# It manages a feedback message and countdown timer.
|
|
16
|
-
#
|
|
17
|
-
# Use it to provide copy-to-clipboard functionality with user feedback.
|
|
18
|
-
#
|
|
19
|
-
# === Example
|
|
20
|
-
#
|
|
21
|
-
# clipboard = Clipboard.new
|
|
22
|
-
# clipboard.copy("#FF0000")
|
|
23
|
-
# puts clipboard.message # => "Copied!"
|
|
24
|
-
#
|
|
25
|
-
# # In render loop:
|
|
26
|
-
# clipboard.tick # Decrement timer
|
|
27
|
-
# puts clipboard.message # => "" (after 60 frames)
|
|
28
|
-
class Clipboard
|
|
29
|
-
def initialize
|
|
30
|
-
@message = ""
|
|
31
|
-
@timer = 0
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Writes text to the system clipboard.
|
|
35
|
-
#
|
|
36
|
-
# Tries pbcopy (macOS), xclip (Linux), then xsel (Linux fallback). Sets the
|
|
37
|
-
# feedback message to <tt>"Copied!"</tt> and starts a 60-frame timer.
|
|
38
|
-
#
|
|
39
|
-
# [text] String to copy
|
|
40
|
-
#
|
|
41
|
-
# === Example
|
|
42
|
-
#
|
|
43
|
-
# clipboard = Clipboard.new
|
|
44
|
-
# clipboard.copy("#FF0000")
|
|
45
|
-
# clipboard.message # => "Copied!"
|
|
46
|
-
def copy(text)
|
|
47
|
-
if `which pbcopy 2>/dev/null`.strip.length > 0
|
|
48
|
-
IO.popen("pbcopy", "w") { |io| io.write(text) }
|
|
49
|
-
elsif `which xclip 2>/dev/null`.strip.length > 0
|
|
50
|
-
IO.popen("xclip -selection clipboard", "w") { |io| io.write(text) }
|
|
51
|
-
elsif `which xsel 2>/dev/null`.strip.length > 0
|
|
52
|
-
IO.popen("xsel --clipboard --input", "w") { |io| io.write(text) }
|
|
53
|
-
end
|
|
54
|
-
@message = "Copied!"
|
|
55
|
-
@timer = 60
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Decrements the feedback timer by one frame.
|
|
59
|
-
#
|
|
60
|
-
# Call this once per render cycle. The message disappears when the timer
|
|
61
|
-
# reaches zero.
|
|
62
|
-
#
|
|
63
|
-
# === Example
|
|
64
|
-
#
|
|
65
|
-
# clipboard.copy("text") # timer = 60
|
|
66
|
-
# clipboard.tick # timer = 59
|
|
67
|
-
# 60.times { clipboard.tick } # message becomes ""
|
|
68
|
-
def tick
|
|
69
|
-
@timer -= 1 if @timer > 0
|
|
70
|
-
@message = "" if @timer <= 0
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Current feedback message.
|
|
74
|
-
#
|
|
75
|
-
# Empty string when no active message. <tt>"Copied!"</tt> after a successful
|
|
76
|
-
# copy, fading after 60 frames.
|
|
77
|
-
#
|
|
78
|
-
# === Example
|
|
79
|
-
#
|
|
80
|
-
# clipboard.message # => ""
|
|
81
|
-
# clipboard.copy("x")
|
|
82
|
-
# clipboard.message # => "Copied!"
|
|
83
|
-
def message
|
|
84
|
-
@message
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,193 +0,0 @@
|
|
|
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 "chroma"
|
|
9
|
-
require "wcag_color_contrast"
|
|
10
|
-
require_relative "harmony"
|
|
11
|
-
|
|
12
|
-
# Represents a single color with format conversion and harmony generation.
|
|
13
|
-
#
|
|
14
|
-
# Colors are central to visual design. Users need to work with colors in multiple
|
|
15
|
-
# formats: hex, RGB, HSL. They also need to generate color schemes: shades, tints,
|
|
16
|
-
# and complementary colors. Managing these conversions and relationships manually
|
|
17
|
-
# is tedious and error-prone.
|
|
18
|
-
#
|
|
19
|
-
# This object wraps a Chroma color. It exposes format conversions. It generates
|
|
20
|
-
# color harmonies. It calculates contrast ratios to choose readable text colors.
|
|
21
|
-
#
|
|
22
|
-
# Use it to parse user input, transform colors, and build color palettes.
|
|
23
|
-
#
|
|
24
|
-
# === Example
|
|
25
|
-
#
|
|
26
|
-
# color = Color.parse("#FF0000")
|
|
27
|
-
# puts color.hex # => "#FF0000"
|
|
28
|
-
# puts color.rgb # => "rgb(255, 0, 0)"
|
|
29
|
-
# puts color.hsl_string # => "hsl(0, 100%, 50%)"
|
|
30
|
-
#
|
|
31
|
-
# # Generate harmonies
|
|
32
|
-
# harmonies = color.harmonies # => [main, shade, tint, complement, ...]
|
|
33
|
-
#
|
|
34
|
-
# # Transform colors
|
|
35
|
-
# lighter = color.tint(5)
|
|
36
|
-
# darker = color.shade(3)
|
|
37
|
-
# rotated = color.spin(180)
|
|
38
|
-
class Color
|
|
39
|
-
def initialize(chroma_color)
|
|
40
|
-
@chroma = chroma_color
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Parses a color string and returns a Color, or nil if the string is invalid.
|
|
44
|
-
#
|
|
45
|
-
# Accepts hex, RGB, HSL, and named colors. Trims whitespace and handles
|
|
46
|
-
# empty strings gracefully.
|
|
47
|
-
#
|
|
48
|
-
# [input_str] String in any format Chroma supports (e.g., <tt>"#FF0000"</tt>, <tt>"red"</tt>, <tt>"rgb(255,0,0)"</tt>)
|
|
49
|
-
#
|
|
50
|
-
# === Example
|
|
51
|
-
#
|
|
52
|
-
# Color.parse("#FF0000") # => Color
|
|
53
|
-
# Color.parse("red") # => Color
|
|
54
|
-
# Color.parse("invalid") # => nil
|
|
55
|
-
# Color.parse("") # => nil
|
|
56
|
-
def self.parse(input_str)
|
|
57
|
-
input_str = input_str.to_s.strip
|
|
58
|
-
return nil if input_str.empty?
|
|
59
|
-
|
|
60
|
-
new(Chroma.paint(input_str.dup))
|
|
61
|
-
rescue
|
|
62
|
-
nil
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Hex color code (uppercase).
|
|
66
|
-
#
|
|
67
|
-
# === Example
|
|
68
|
-
#
|
|
69
|
-
# color = Color.parse("red")
|
|
70
|
-
# color.hex # => "#FF0000"
|
|
71
|
-
def hex
|
|
72
|
-
@chroma.to_hex.upcase
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# RGB color code.
|
|
76
|
-
#
|
|
77
|
-
# === Example
|
|
78
|
-
#
|
|
79
|
-
# color = Color.parse("red")
|
|
80
|
-
# color.rgb # => "rgb(255, 0, 0)"
|
|
81
|
-
def rgb
|
|
82
|
-
@chroma.to_rgb
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# HSL color string with percentage formatting.
|
|
86
|
-
#
|
|
87
|
-
# === Example
|
|
88
|
-
#
|
|
89
|
-
# color = Color.parse("red")
|
|
90
|
-
# color.hsl_string # => "hsl(0, 100%, 50%)"
|
|
91
|
-
def hsl_string
|
|
92
|
-
hsl_obj = @chroma.hsl
|
|
93
|
-
h = hsl_obj.h
|
|
94
|
-
s = hsl_obj.s
|
|
95
|
-
l = hsl_obj.l
|
|
96
|
-
format("hsl(%.0f, %.1f%%, %.1f%%)", h, s * 100, l * 100)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# Darkens the color. Returns a new Color.
|
|
100
|
-
#
|
|
101
|
-
# [amount] Integer amount to darken (default: 3)
|
|
102
|
-
#
|
|
103
|
-
# === Example
|
|
104
|
-
#
|
|
105
|
-
# color = Color.parse("red")
|
|
106
|
-
# color.shade(5).hex # => darker red
|
|
107
|
-
def shade(amount = 3)
|
|
108
|
-
Color.new(@chroma.darken(amount))
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# Lightens the color. Returns a new Color.
|
|
112
|
-
#
|
|
113
|
-
# [amount] Integer amount to lighten (default: 3)
|
|
114
|
-
#
|
|
115
|
-
# === Example
|
|
116
|
-
#
|
|
117
|
-
# color = Color.parse("red")
|
|
118
|
-
# color.tint(5).hex # => lighter red
|
|
119
|
-
def tint(amount = 3)
|
|
120
|
-
Color.new(@chroma.lighten(amount))
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# Rotates the hue. Returns a new Color.
|
|
124
|
-
#
|
|
125
|
-
# [degrees] Integer degrees to rotate (0-360)
|
|
126
|
-
#
|
|
127
|
-
# === Example
|
|
128
|
-
#
|
|
129
|
-
# color = Color.parse("red")
|
|
130
|
-
# color.spin(180).hex # => cyan
|
|
131
|
-
def spin(degrees)
|
|
132
|
-
Color.new(@chroma.spin(degrees))
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# Determines optimal text color (:white or :black) for maximum contrast.
|
|
136
|
-
#
|
|
137
|
-
# Uses WCAG contrast ratio calculation. Returns <tt>:white</tt> if white has
|
|
138
|
-
# higher contrast; <tt>:black</tt> otherwise.
|
|
139
|
-
#
|
|
140
|
-
# === Example
|
|
141
|
-
#
|
|
142
|
-
# Color.parse("yellow").contrasting_text_color # => :black
|
|
143
|
-
# Color.parse("navy").contrasting_text_color # => :white
|
|
144
|
-
def contrasting_text_color
|
|
145
|
-
white_contrast = WCAGColorContrast.ratio(hex.sub(/^#/, ""), "ffffff")
|
|
146
|
-
black_contrast = WCAGColorContrast.ratio(hex.sub(/^#/, ""), "000000")
|
|
147
|
-
(white_contrast > black_contrast) ? :white : :black
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
# Background color for rendering this color as a swatch.
|
|
151
|
-
#
|
|
152
|
-
# Returns <tt>"#000000"</tt> if text should be white; <tt>"#ffffff"</tt> if black.
|
|
153
|
-
# Used to frame color swatches with contrasting borders.
|
|
154
|
-
#
|
|
155
|
-
# === Example
|
|
156
|
-
#
|
|
157
|
-
# Color.parse("yellow").frame_color # => "#000000"
|
|
158
|
-
def frame_color
|
|
159
|
-
(contrasting_text_color == :white) ? "#000000" : "#ffffff"
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# Seven-color harmony: main, shade, tint, complement, split 1, split 2, split-complement.
|
|
163
|
-
#
|
|
164
|
-
# Generates a complete color scheme for UI design. Each harmony is a Harmony
|
|
165
|
-
# value object with label, hex, and styling information.
|
|
166
|
-
#
|
|
167
|
-
# === Example
|
|
168
|
-
#
|
|
169
|
-
# color = Color.parse("red")
|
|
170
|
-
# harmonies = color.harmonies
|
|
171
|
-
# harmonies.first.label # => "Main"
|
|
172
|
-
# harmonies.size # => 7
|
|
173
|
-
def harmonies
|
|
174
|
-
[
|
|
175
|
-
harmony_with_label("Main"),
|
|
176
|
-
shade.harmony_with_label("Shade"),
|
|
177
|
-
tint.harmony_with_label("Tint"),
|
|
178
|
-
spin(180).harmony_with_label("Comp"),
|
|
179
|
-
spin(150).harmony_with_label("Split 1"),
|
|
180
|
-
spin(210).harmony_with_label("Split 2"),
|
|
181
|
-
spin(30).harmony_with_label("S.Comp"),
|
|
182
|
-
]
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def harmony_with_label(label)
|
|
186
|
-
Harmony.new(
|
|
187
|
-
label:,
|
|
188
|
-
hex:,
|
|
189
|
-
text_color: contrasting_text_color,
|
|
190
|
-
frame_color:,
|
|
191
|
-
)
|
|
192
|
-
end
|
|
193
|
-
end
|