Class: TTY::PromptX
- Inherits:
-
Prompt
- Object
- Prompt
- TTY::PromptX
- Defined in:
- lib/monadic_chat/helper.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(active_color:, prefix:, history: true) ⇒ PromptX
constructor
A new instance of PromptX.
- #readline(text = "") ⇒ Object
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
#prefix ⇒ Object (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 |