Class: Tuile::Component::LogTextView
- Defined in:
- lib/tuile/component/log_text_view.rb,
sig/tuile.rbs
Overview
A TextView purpose-built for log output: auto-scroll is on, the scrollbar is visible, and lines arrive via #log — from any thread. Point a logger at a IO to route its lines here:
view = Tuile::Component::LogTextView.new
logger = Logger.new(Tuile::Component::LogTextView::IO.new(view))
logger.info("started") # appears in the view, from any thread
Any logger that writes formatted lines to an IO works the same way —
for example TTY::Logger configured with the :console handler and
output: LogTextView::IO.new(view).
Add it to a layout as-is for a frameless log pane, or use LogWindow for the framed assembly. A TextView rather than a List: long lines (stacktraces, wide log records) word-wrap rather than ellipsize — a truncated log line hides the very detail you opened the log to read.
Defined Under Namespace
Classes: IO
Instance Attribute Summary
Attributes inherited from TextView
#auto_scroll, #scroll_top_row, #scrollbar_visibility
Instance Method Summary collapse
-
#initialize ⇒ LogTextView
constructor
A new instance of LogTextView.
-
#log(string) ⇒ void
Appends the given line to the log.
Methods inherited from TextView
#<<, #add_line, #append, #append_to_region, #at_bottom?, #build_text, #clear, #create_region, #empty?, #focusable?, #following?, #half_page_rows, #handle_key, #handle_mouse, #insert, #move_scroll_top_row_by, #move_scroll_top_row_to, #normalize_replace_range, #on_width_changed, #pad_to, #paintable_row, #pop_line, #push_line, #region_start_index, #remove_last_n_from_region, #remove_last_n_lines, #remove_region, #repaint, #replace, #replace_in_region, #rewrap, #row_offset_at, #scroll_half_page_down, #scroll_half_page_up, #scroll_top_row_max, #scrollbar_visible?, #set_region_text, #splice_lines, #tab_stop?, #text, #text=, #text_for_region, #update_region_counts, #update_scroll_top_row_if_auto_scroll, #viewport_rows, #wrap_line, #wrap_width
Constructor Details
#initialize ⇒ LogTextView
Returns a new instance of LogTextView.
22 23 24 25 26 |
# File 'lib/tuile/component/log_text_view.rb', line 22 def initialize super self.auto_scroll = true self. = :visible end |
Instance Method Details
#log(string) ⇒ void
This method returns an undefined value.
Appends the given line to the log. Safe to call from any thread —
the one exception to the UI-thread confinement every component
carries: the append is marshalled through event_queue.submit, so
it lands once a loop drains the queue (deferred before the first
loop; silently dropped after the loop has returned).
@param string — the line (or multiple lines) to log; nil is a no-op.
36 37 38 39 40 |
# File 'lib/tuile/component/log_text_view.rb', line 36 def log(string) return if string.nil? screen.event_queue.submit { add_line(string) } end |