Class: Fatty::CallbackEnvironment

Inherits:
Object
  • Object
show all
Includes:
AlertApi, ChooseApi, EnvironmentApi, KeytestApi, MenuApi, OutputApi, ProgressApi, PromptApi, StatusApi
Defined in:
lib/fatty/callback_environment.rb

Constant Summary collapse

INTERRUPT_POLL_INTERVAL =
1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EnvironmentApi

#environment

Methods included from KeytestApi

#keytest

Methods included from AlertApi

#alert

Methods included from StatusApi

#error, #good, #info, #oops, #status, #warn

Methods included from PromptApi

#prompt

Methods included from ChooseApi

#choose, #choose_multi, #confirm

Methods included from ProgressApi

#add_progress

Methods included from MenuApi

#menu

Methods included from OutputApi

#append, #append_now, #markdown

Constructor Details

#initialize(terminal:, output_id:, label: nil) ⇒ CallbackEnvironment

Returns a new instance of CallbackEnvironment.



35
36
37
38
39
40
41
# File 'lib/fatty/callback_environment.rb', line 35

def initialize(terminal:, output_id:, label: nil)
  @terminal = terminal
  @output_id = output_id
  @label = label
  @commands = []
  @last_interrupt_check_at = nil
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



33
34
35
# File 'lib/fatty/callback_environment.rb', line 33

def commands
  @commands
end

#labelObject (readonly)

Returns the value of attribute label.



33
34
35
# File 'lib/fatty/callback_environment.rb', line 33

def label
  @label
end

#payloadObject (readonly)

Returns the value of attribute payload.



33
34
35
# File 'lib/fatty/callback_environment.rb', line 33

def payload
  @payload
end

#progressObject (readonly)

Returns the value of attribute progress.



33
34
35
# File 'lib/fatty/callback_environment.rb', line 33

def progress
  @progress
end

#terminalObject (readonly)

Returns the value of attribute terminal.



33
34
35
# File 'lib/fatty/callback_environment.rb', line 33

def terminal
  @terminal
end

Instance Method Details

#check_interrupt!Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/fatty/callback_environment.rb', line 48

def check_interrupt!
  now = monotonic_time

  if interrupt_check_due?(now)
    @last_interrupt_check_at = now
    raise Fatty::Interrupt if terminal.interrupt_pending?
  end

  nil
end

#queue(command) ⇒ Object



43
44
45
46
# File 'lib/fatty/callback_environment.rb', line 43

def queue(command)
  @commands << command
  command
end