Class: Clacky::RichUIController::FormDialog
- Inherits:
-
Object
- Object
- Clacky::RichUIController::FormDialog
- 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(title:, fields:, width: 92) ⇒ FormDialog
constructor
A new instance of FormDialog.
- #key(event_name, priority = 0, &block) ⇒ Object
- #notify_listeners(event_data) ⇒ Object
- #render_to_buffer ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(title:, fields:, width: 92) ⇒ FormDialog
Returns a new instance of FormDialog.
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 |
# File 'lib/clacky/rich_ui_controller.rb', line 1431 def initialize(title:, fields:, width: 92) @title = title @fields = fields @field_index = 0 @editors = fields.map do |field| RubyRich::LineEditor.new.tap { |editor| editor.value = field[:default].to_s } end @width = width @height = [fields.length * 3 + 8, 16].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: :form_dialog, width: @width, height: @height) @layout.update_content(@panel) @layout.calculate_dimensions(@width, @height) wire_default_keys end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
1429 1430 1431 |
# File 'lib/clacky/rich_ui_controller.rb', line 1429 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
1429 1430 1431 |
# File 'lib/clacky/rich_ui_controller.rb', line 1429 def width @width end |
Instance Method Details
#finish(value) ⇒ Object
1452 1453 1454 1455 1456 1457 1458 1459 |
# File 'lib/clacky/rich_ui_controller.rb', line 1452 def finish(value) @mutex.synchronize do @result = value @finished = true @condition.signal end true end |
#key(event_name, priority = 0, &block) ⇒ Object
1466 1467 1468 1469 1470 |
# File 'lib/clacky/rich_ui_controller.rb', line 1466 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 |
#notify_listeners(event_data) ⇒ Object
1472 1473 1474 1475 |
# File 'lib/clacky/rich_ui_controller.rb', line 1472 def notify_listeners(event_data) listeners = Array(@event_listeners[event_data[:name]]) listeners.each { |listener| listener[:block].call(event_data, nil) } end |
#render_to_buffer ⇒ Object
1477 1478 1479 1480 1481 |
# File 'lib/clacky/rich_ui_controller.rb', line 1477 def render_to_buffer @panel.content = render_content @layout.calculate_dimensions(@width, @height) @layout.render_to_buffer end |
#wait ⇒ Object
1461 1462 1463 1464 |
# File 'lib/clacky/rich_ui_controller.rb', line 1461 def wait @mutex.synchronize { @condition.wait(@mutex) until @finished } @result end |