Class: TTY::PromptX

Inherits:
Prompt
  • Object
show all
Defined in:
lib/monadic_chat/helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active_color:, prefix:, history: true) ⇒ PromptX

Returns a new instance of PromptX.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/monadic_chat/helper.rb', line 24

def initialize(active_color:, prefix:, history: true)
  @interrupt = lambda do
    print TTY::Cursor.clear_screen_down
    print "\e[2J\e[f"
    res = TTY::Prompt.new.yes?("Quit the app?")
    exit if res
  end

  super(active_color: active_color, prefix: prefix, interrupt: @interrupt)
  @history = history
  @prefix = prefix
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



22
23
24
# File 'lib/monadic_chat/helper.rb', line 22

def prefix
  @prefix
end

Instance Method Details

#readline(text = "") ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/monadic_chat/helper.rb', line 37

def readline(text = "")
  puts @prefix
  begin
    Readline.readline(text, @history)
  rescue Interrupt
    @interrupt.call
  end
end