Class: Kward::PromptInterface::EditorRunnerState
- Inherits:
-
Object
- Object
- Kward::PromptInterface::EditorRunnerState
- Defined in:
- lib/kward/prompt_interface/editor/runner_state.rb
Instance Attribute Summary collapse
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#source_digest ⇒ Object
readonly
Returns the value of attribute source_digest.
Instance Method Summary collapse
- #cancel ⇒ Object
- #cancel_requested? ⇒ Boolean
- #complete(result) ⇒ Object
- #error ⇒ Object
- #fail(error) ⇒ Object
-
#initialize(language:, source:) ⇒ EditorRunnerState
constructor
A new instance of EditorRunnerState.
- #output_text ⇒ Object
- #result ⇒ Object
- #running? ⇒ Boolean
- #scroll_by(delta, maximum:) ⇒ Object
- #scroll_row ⇒ Object
- #set_scroll_row(row, maximum:) ⇒ Object
Constructor Details
#initialize(language:, source:) ⇒ EditorRunnerState
Returns a new instance of EditorRunnerState.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 10 def initialize(language:, source:) @language = language.to_sym @source_digest = Digest::SHA256.hexdigest(source.to_s) @mutex = Mutex.new @running = true @cancel_requested = false @result = nil @error = nil @scroll_row = 0 end |
Instance Attribute Details
#language ⇒ Object (readonly)
Returns the value of attribute language.
8 9 10 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 8 def language @language end |
#source_digest ⇒ Object (readonly)
Returns the value of attribute source_digest.
8 9 10 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 8 def source_digest @source_digest end |
Instance Method Details
#cancel ⇒ Object
29 30 31 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 29 def cancel @mutex.synchronize { @cancel_requested = true } end |
#cancel_requested? ⇒ Boolean
25 26 27 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 25 def cancel_requested? @mutex.synchronize { @cancel_requested } end |
#complete(result) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 33 def complete(result) @mutex.synchronize do @result = result @running = false end end |
#error ⇒ Object
51 52 53 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 51 def error @mutex.synchronize { @error } end |
#fail(error) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 40 def fail(error) @mutex.synchronize do @error = error @running = false end end |
#output_text ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 55 def output_text @mutex.synchronize do return @error..to_s if @error @result&.output.to_s end end |
#result ⇒ Object
47 48 49 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 47 def result @mutex.synchronize { @result } end |
#running? ⇒ Boolean
21 22 23 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 21 def running? @mutex.synchronize { @running } end |
#scroll_by(delta, maximum:) ⇒ Object
73 74 75 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 73 def scroll_by(delta, maximum:) set_scroll_row(scroll_row + delta.to_i, maximum: maximum) end |
#scroll_row ⇒ Object
63 64 65 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 63 def scroll_row @mutex.synchronize { @scroll_row } end |
#set_scroll_row(row, maximum:) ⇒ Object
67 68 69 70 71 |
# File 'lib/kward/prompt_interface/editor/runner_state.rb', line 67 def set_scroll_row(row, maximum:) @mutex.synchronize do @scroll_row = [[row.to_i, 0].max, maximum.to_i].min end end |