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.
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 |
# File 'lib/clacky/rich_ui_controller.rb', line 1328 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.
1326 1327 1328 |
# File 'lib/clacky/rich_ui_controller.rb', line 1326 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
1326 1327 1328 |
# File 'lib/clacky/rich_ui_controller.rb', line 1326 def width @width end |
Instance Method Details
#finish(value) ⇒ Object
1356 1357 1358 1359 1360 1361 1362 1363 |
# File 'lib/clacky/rich_ui_controller.rb', line 1356 def finish(value) @mutex.synchronize do @result = value @finished = true @condition.signal end true end |
#key(event_name, priority = 0, &block) ⇒ Object
1370 1371 1372 1373 1374 |
# File 'lib/clacky/rich_ui_controller.rb', line 1370 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
1352 1353 1354 |
# File 'lib/clacky/rich_ui_controller.rb', line 1352 def move_down move(1) end |
#move_up ⇒ Object
1348 1349 1350 |
# File 'lib/clacky/rich_ui_controller.rb', line 1348 def move_up move(-1) end |
#notify_listeners(event_data) ⇒ Object
1376 1377 1378 |
# File 'lib/clacky/rich_ui_controller.rb', line 1376 def notify_listeners(event_data) Array(@event_listeners[event_data[:name]]).each { |listener| listener[:block].call(event_data, nil) } end |
#render_to_buffer ⇒ Object
1380 1381 1382 1383 1384 |
# File 'lib/clacky/rich_ui_controller.rb', line 1380 def render_to_buffer @panel.content = render_content @layout.calculate_dimensions(@width, @height) @layout.render_to_buffer end |
#selected_choice ⇒ Object
1344 1345 1346 |
# File 'lib/clacky/rich_ui_controller.rb', line 1344 def selected_choice @choices[@selected_index] end |
#wait ⇒ Object
1365 1366 1367 1368 |
# File 'lib/clacky/rich_ui_controller.rb', line 1365 def wait @mutex.synchronize { @condition.wait(@mutex) until @finished } @result end |