Class: RubynCode::CLI::Spinner

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/cli/spinner.rb

Constant Summary collapse

THINKING_MESSAGES =
[
  'Massaging the hash...',
  'Refactoring in my head...',
  'Consulting Matz...',
  'Freezing strings...',
  'Monkey-patching reality...',
  'Yielding to the block...',
  'Enumerating possibilities...',
  'Injecting dependencies...',
  'Guard clause-ing my thoughts...',
  'Sharpening the gems...',
  'Duck typing furiously...',
  'Reducing complexity...',
  'Mapping it out...',
  'Selecting the right approach...',
  'Running the mental specs...',
  'Composing a module...',
  'Memoizing the answer...',
  'Digging through the hash...',
  'Pattern matching on this...',
  'Raising my standards...',
  'Rescuing the situation...',
  'Benchmarking my thoughts...',
  'Sending :think to self...',
  'Evaluating the proc...',
  'Opening the eigenclass...',
  'Calling .new on an idea...',
  'Plucking the good bits...',
  'Finding each solution...',
  'Requiring more context...',
  'Bundling my thoughts...'
].freeze
SUB_AGENT_MESSAGES =
[
  'Sub-agent is spelunking...',
  'Agent exploring the codebase...',
  'Reading all the things...',
  'Sub-agent doing the legwork...',
  'Agent grepping through files...',
  'Dispatching the intern...'
].freeze

Instance Method Summary collapse

Constructor Details

#initializeSpinner

Returns a new instance of Spinner.



50
51
52
# File 'lib/rubyn_code/cli/spinner.rb', line 50

def initialize
  @spinner = nil
end

Instance Method Details

#error(message = 'Failed') ⇒ Object



85
86
87
88
# File 'lib/rubyn_code/cli/spinner.rb', line 85

def error(message = 'Failed')
  @spinner&.error("(#{message})")
  @spinner = nil
end

#spinning?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/rubyn_code/cli/spinner.rb', line 95

def spinning?
  @spinner&.spinning? || false
end

#start(message = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/rubyn_code/cli/spinner.rb', line 54

def start(message = nil)
  message ||= THINKING_MESSAGES.sample
  @spinner = TTY::Spinner.new(
    "[:spinner] #{message}",
    format: :dots,
    clear: true
  )
  @spinner.auto_spin
end

#start_sub_agent(tool_count = 0) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/rubyn_code/cli/spinner.rb', line 64

def start_sub_agent(tool_count = 0)
  msg = if tool_count.positive?
          "#{SUB_AGENT_MESSAGES.sample} (#{tool_count} tools)"
        else
          SUB_AGENT_MESSAGES.sample
        end
  start(msg)
end

#stopObject



90
91
92
93
# File 'lib/rubyn_code/cli/spinner.rb', line 90

def stop
  @spinner&.stop
  @spinner = nil
end

#success(message = 'Done') ⇒ Object



80
81
82
83
# File 'lib/rubyn_code/cli/spinner.rb', line 80

def success(message = 'Done')
  @spinner&.success("(#{message})")
  @spinner = nil
end

#update(message) ⇒ Object



73
74
75
76
77
78
# File 'lib/rubyn_code/cli/spinner.rb', line 73

def update(message)
  return start(message) unless spinning?

  stop
  start(message)
end