Class: RubynCode::CLI::Spinner
- Inherits:
-
Object
- Object
- RubynCode::CLI::Spinner
- 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
- #error(message = 'Failed') ⇒ Object
-
#initialize ⇒ Spinner
constructor
A new instance of Spinner.
- #spinning? ⇒ Boolean
- #start(message = nil) ⇒ Object
- #start_sub_agent(tool_count = 0) ⇒ Object
- #stop ⇒ Object
- #success(message = 'Done') ⇒ Object
- #update(message) ⇒ Object
Constructor Details
#initialize ⇒ Spinner
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( = 'Failed') @spinner&.error("(#{})") @spinner = nil end |
#spinning? ⇒ 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( = nil) ||= THINKING_MESSAGES.sample @spinner = TTY::Spinner.new( "[:spinner] #{}", 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 |
#stop ⇒ Object
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( = 'Done') @spinner&.success("(#{})") @spinner = nil end |
#update(message) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/rubyn_code/cli/spinner.rb', line 73 def update() return start() unless spinning? stop start() end |