Class: Brakeman::Logger::Console
- Inherits:
-
Base
- Object
- Base
- Brakeman::Logger::Console
show all
- Defined in:
- lib/brakeman/logger.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#color, #color?, #debug, #log, #show_timing?, #single_context
Constructor Details
#initialize(options) ⇒ Console
Returns a new instance of Console.
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/brakeman/logger.rb', line 156
def initialize(options, *)
super
load_highline(options[:output_color])
require 'reline'
require 'reline/io/ansi'
@prefix = ''
@post_fix_pos = 0
@reline = Reline::ANSI.new
@report_progress = options[:report_progress]
@spinner = ["⣀", "⣄", "⣤", "⣦", "⣶", "⣷", "⣿"]
@percenter = ["⣀", "⣤", "⣶", "⣿"]
@spindex = 0
@last_spin = Time.now
@reline.hide_cursor
end
|
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
154
155
156
|
# File 'lib/brakeman/logger.rb', line 154
def prefix
@prefix
end
|
Instance Method Details
#alert(message) ⇒ Object
180
181
182
183
184
|
# File 'lib/brakeman/logger.rb', line 180
def alert message
clear_line
log color(message, :red)
rewrite_prefix
end
|
#announce(message) ⇒ Object
174
175
176
177
178
|
# File 'lib/brakeman/logger.rb', line 174
def announce message
clear_line
log color(message, :bold, :green)
rewrite_prefix
end
|
#cleanup(newline = true) ⇒ Object
258
259
260
261
|
# File 'lib/brakeman/logger.rb', line 258
def cleanup(newline = true)
@reline.show_cursor
log('') if newline
end
|
#clear_line ⇒ Object
245
246
247
248
|
# File 'lib/brakeman/logger.rb', line 245
def clear_line
@reline.move_cursor_column(0)
@reline.erase_after_cursor
end
|
#clear_prefix ⇒ Object
239
240
241
242
243
|
# File 'lib/brakeman/logger.rb', line 239
def clear_prefix
@prefix = ''
@post_fix_pos = 0
clear_line
end
|
#context(description) ⇒ Object
186
187
188
189
190
191
192
|
# File 'lib/brakeman/logger.rb', line 186
def context(description, &)
write_prefix description
time_step(description, &)
ensure
clear_prefix
end
|
#rewrite_prefix ⇒ Object
If an alert was written, redo prefix on next line
223
224
225
226
|
# File 'lib/brakeman/logger.rb', line 223
def rewrite_prefix
log(@prefix, newline: false)
@reline.erase_after_cursor
end
|
#set_prefix(message) ⇒ Object
234
235
236
237
|
# File 'lib/brakeman/logger.rb', line 234
def set_prefix message
@prefix = "#{color('»', :bold, :cyan)} #{color(message, :green)}"
@post_fix_pos = HighLine::Wrapper.actual_length(@prefix) + 1
end
|
#spin ⇒ Object
250
251
252
253
254
255
256
|
# File 'lib/brakeman/logger.rb', line 250
def spin
return unless (Time.now - @last_spin) > 0.2
write_after color(@spinner[@spindex], :bold, :red)
@spindex = (@spindex + 1) % @spinner.length
@last_spin = Time.now
end
|
#time_step(description) ⇒ Object
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/brakeman/logger.rb', line 194
def time_step(description, &)
if show_timing?
start_t = Time.now
yield
duration = Time.now - start_t
write_after color(('%0.2fs' % duration), :gray)
log ''
else
yield
end
end
|
#update_progress(current, total, type = 'files') ⇒ Object
207
208
209
210
211
212
213
214
215
|
# File 'lib/brakeman/logger.rb', line 207
def update_progress current, total, type = 'files'
percent = ((current / total.to_f) * 100).to_i
tenths = [(percent / 10), 0].max
lead = color(@percenter[percent % 10 / 3], :bold, :red)
done_blocks = color("⣿" * tenths, :red)
remaining = color("⣀" * (9 - tenths), :gray)
write_after "#{done_blocks}#{lead}#{remaining}"
end
|
#write_after(message) ⇒ Object
228
229
230
231
232
|
# File 'lib/brakeman/logger.rb', line 228
def write_after message
@reline.move_cursor_column(@post_fix_pos)
log(message, newline: false)
@reline.erase_after_cursor
end
|
#write_prefix(pref) ⇒ Object
217
218
219
220
|
# File 'lib/brakeman/logger.rb', line 217
def write_prefix pref
set_prefix pref
rewrite_prefix
end
|