Class: Tuile::Component::LogWindow

Inherits:
Window
  • Object
show all
Defined in:
lib/tuile/component/log_window.rb,
sig/tuile.rbs

Overview

Shows a log. Construct your logger pointed at a IO to route log lines into this window:

log_window = Tuile::Component::LogWindow.new
logger = Logger.new(Tuile::Component::LogWindow::IO.new(log_window))

Any logger that writes formatted lines to an IO works the same way — for example TTY::Logger configured with the :console handler and output: LogWindow::IO.new(window).

Defined Under Namespace

Classes: IO

Instance Attribute Summary

Attributes inherited from Window

#caption, #footer, #footer_text

Attributes included from HasContent

#content

Instance Method Summary collapse

Methods inherited from Window

#bottom_border, #children, #focusable?, #frame_caption, #handle_mouse, #key_shortcut=, #layout, #layout_footer, #on_focus, #rect=, #repaint, #repaint_border, #scrollbar=

Methods included from HasContent

#children, #handle_mouse, #on_focus, #rect=

Constructor Details

#initialize(caption = "Log") ⇒ LogWindow

@param caption

Parameters:

  • caption (String) (defaults to: "Log")


16
17
18
19
20
21
22
23
24
25
# File 'lib/tuile/component/log_window.rb', line 16

def initialize(caption = "Log")
  super
  view = Component::TextView.new
  # Word-wrap long lines (stacktraces, wide log records) rather than
  # ellipsizing them as a {List} would — a truncated log line hides the
  # very detail you opened the log to read.
  view.auto_scroll = true
  self.content = view
  self.scrollbar = true
end

Instance Method Details

#log(string) ⇒ void

This method returns an undefined value.

Appends given line to the log. Can be called from any thread. Does nothing if nil is passed in.

@param string — the line (or multiple lines) to log.

Parameters:

  • string (String, nil)


30
31
32
33
34
35
36
# File 'lib/tuile/component/log_window.rb', line 30

def log(string)
  return if string.nil?

  screen.event_queue.submit do
    content.add_line(string)
  end
end