class BotConsole::LogBuffer
Constants
- DEFAULT_CAPACITY
Public Class Methods
Source
# File lib/bot_console/log_buffer.rb, line 15 def initialize(capacity: DEFAULT_CAPACITY, log_path: nil) @capacity = capacity @mutex = Mutex.new @lines = [] @scroll_offset = 0 @log_file = log_path ? LogFile.new(log_path) : nil @full_lines_cache = nil end
Public Instance Methods
Source
# File lib/bot_console/log_buffer.rb, line 24 def append(line) condensed = LogLine.condense(line) return if condensed.nil? || condensed.empty? @mutex.synchronize do @lines << condensed @lines.shift while @lines.length > @capacity @log_file&.append(condensed) invalidate_file_cache! @scroll_offset = 0 if @scroll_offset.zero? end end
Source
# File lib/bot_console/log_buffer.rb, line 89 def scroll_bottom @mutex.synchronize { @scroll_offset = 0 } end
Source
# File lib/bot_console/log_buffer.rb, line 73 def scroll_by(delta, height) @mutex.synchronize do all = backing_lines_locked max_offset = [all.length - height, 0].max @scroll_offset = [[@scroll_offset + delta, 0].max, max_offset].min end end
Source
# File lib/bot_console/log_buffer.rb, line 58 def scroll_state(height) @mutex.synchronize do total = total_line_count_locked max_offset = [total - height, 0].max at_tail = @scroll_offset <= 0 { total: total, offset: @scroll_offset, max_offset: max_offset, at_tail: at_tail, archives: @log_file&.archive_count.to_i } end end
Source
# File lib/bot_console/log_buffer.rb, line 81 def scroll_top(height) @mutex.synchronize do all = backing_lines_locked max_offset = [all.length - height, 0].max @scroll_offset = max_offset end end
Source
# File lib/bot_console/log_buffer.rb, line 54 def scrolled_up? @mutex.synchronize { @scroll_offset.positive? } end
Source
# File lib/bot_console/log_buffer.rb, line 41 def visible_lines(height) all = backing_lines return [] if height <= 0 @mutex.synchronize do max_offset = [all.length - height, 0].max @scroll_offset = [[@scroll_offset, 0].max, max_offset].min start = all.length - height - @scroll_offset start = 0 if start.negative? all[start, height] || [] end end