Class: RubyRich::Dialog

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/dialog.rb

Direct Known Subclasses

ConfirmDialog, InputDialog

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: "", content: "", buttons: ["OK"]) ⇒ Dialog

Returns a new instance of Dialog.



5
6
7
8
9
10
11
# File 'lib/ruby_rich/dialog.rb', line 5

def initialize(title: "", content: "", buttons: ["OK"])
  @title = title
  @content = content
  @buttons = buttons
  @selected_index = 0
  @result = nil
end

Instance Attribute Details

#buttonsObject

Returns the value of attribute buttons.



3
4
5
# File 'lib/ruby_rich/dialog.rb', line 3

def buttons
  @buttons
end

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/ruby_rich/dialog.rb', line 3

def content
  @content
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/ruby_rich/dialog.rb', line 3

def title
  @title
end

Instance Method Details

#showObject

主显示方法



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_rich/dialog.rb', line 14

def show
  Console.raw do
    loop do
      Console.clear
      render
      handle_input(Console.get_key)
      break if @result
    end
  end
  @result
end