Class: Tuile::Component::LogWindow

Inherits:
Window show all
Defined in:
lib/tuile/component/log_window.rb

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_sizing

Attributes included from HasContent

#content

Attributes inherited from Tuile::Component

#content_size, #key_shortcut, #on_theme_changed, #parent, #rect

Instance Method Summary collapse

Methods inherited from Window

#children, #content=, #focusable?, #handle_mouse, #key_shortcut=, #on_child_content_size_changed, #rect=, #repaint, #scrollbar=

Methods included from HasContent

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

Methods inherited from Tuile::Component

#active=, #active?, #attached?, #children, #cursor_position, #depth, #find_shortcut_component, #focus, #focusable?, #handle_key, #handle_mouse, #keyboard_hint, #on_child_content_size_changed, #on_child_removed, #on_focus, #on_tree, #repaint, #root, #screen, #tab_stop?

Constructor Details

#initialize(caption = "Log") ⇒ LogWindow

Returns a new instance of LogWindow.

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.

Parameters:

  • string (String, nil)

    the line (or multiple lines) to log.



44
45
46
47
48
49
50
# File 'lib/tuile/component/log_window.rb', line 44

def log(string)
  return if string.nil?

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

Let a busy log grow past the popup’s base 12-row cap (up to the 4/5-of-screen ceiling Popup#update_rect applies) so the diagnostic stream stays scrollable in a tall window. Advice consulted by Popup#max_height when this window is a popup’s content.

Returns:

  • (Integer)


39
# File 'lib/tuile/component/log_window.rb', line 39

def popup_max_height = screen.size.height

Keep the log pane at least half the screen tall even when only a few lines have been logged: a Popup sizes to its content, which would collapse a near-empty log to two or three rows. Advice consulted by Popup#min_height when this window is a popup’s content.

Returns:

  • (Integer)


32
# File 'lib/tuile/component/log_window.rb', line 32

def popup_min_height = screen.size.height / 2