Class: Clacky::RichUIController::ConfigMenuDialog
- Inherits:
-
Object
- Object
- Clacky::RichUIController::ConfigMenuDialog
- Defined in:
- lib/clacky/rich_ui_controller.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #finish(value) ⇒ Object
-
#initialize(choices:, selected_index: 0, title: "Model Configuration", width: 86) ⇒ ConfigMenuDialog
constructor
A new instance of ConfigMenuDialog.
- #key(event_name, priority = 0, &block) ⇒ Object
- #move_down ⇒ Object
- #move_up ⇒ Object
- #notify_listeners(event_data) ⇒ Object
- #render_to_buffer ⇒ Object
- #selected_choice ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(choices:, selected_index: 0, title: "Model Configuration", width: 86) ⇒ ConfigMenuDialog
Returns a new instance of ConfigMenuDialog.
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/clacky/rich_ui_controller.rb', line 1330 def initialize(choices:, selected_index: 0, title: "Model Configuration", width: 86) @choices = choices @selected_index = selected_index @width = width @height = [choices.length + 7, 12].max @event_listeners = {} @mutex = Mutex.new @condition = ConditionVariable.new @finished = false @result = nil @panel = RubyRich::Panel.new("", title: title, border_style: :cyan, title_align: :center) @layout = RubyRich::Layout.new(name: :config_dialog, width: @width, height: @height) @layout.update_content(@panel) @layout.calculate_dimensions(@width, @height) end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
1328 1329 1330 |
# File 'lib/clacky/rich_ui_controller.rb', line 1328 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
1328 1329 1330 |
# File 'lib/clacky/rich_ui_controller.rb', line 1328 def width @width end |
Instance Method Details
#finish(value) ⇒ Object
1358 1359 1360 1361 1362 1363 1364 1365 |
# File 'lib/clacky/rich_ui_controller.rb', line 1358 def finish(value) @mutex.synchronize do @result = value @finished = true @condition.signal end true end |
#key(event_name, priority = 0, &block) ⇒ Object
1372 1373 1374 1375 1376 |
# File 'lib/clacky/rich_ui_controller.rb', line 1372 def key(event_name, priority = 0, &block) @event_listeners[event_name] ||= [] @event_listeners[event_name] << { priority: priority, block: block } @event_listeners[event_name].sort_by! { |listener| -listener[:priority] } end |
#move_down ⇒ Object
1354 1355 1356 |
# File 'lib/clacky/rich_ui_controller.rb', line 1354 def move_down move(1) end |
#move_up ⇒ Object
1350 1351 1352 |
# File 'lib/clacky/rich_ui_controller.rb', line 1350 def move_up move(-1) end |
#notify_listeners(event_data) ⇒ Object
1378 1379 1380 |
# File 'lib/clacky/rich_ui_controller.rb', line 1378 def notify_listeners(event_data) Array(@event_listeners[event_data[:name]]).each { |listener| listener[:block].call(event_data, nil) } end |
#render_to_buffer ⇒ Object
1382 1383 1384 1385 1386 |
# File 'lib/clacky/rich_ui_controller.rb', line 1382 def render_to_buffer @panel.content = render_content @layout.calculate_dimensions(@width, @height) @layout.render_to_buffer end |
#selected_choice ⇒ Object
1346 1347 1348 |
# File 'lib/clacky/rich_ui_controller.rb', line 1346 def selected_choice @choices[@selected_index] end |
#wait ⇒ Object
1367 1368 1369 1370 |
# File 'lib/clacky/rich_ui_controller.rb', line 1367 def wait @mutex.synchronize { @condition.wait(@mutex) until @finished } @result end |