Class: Reviewer::Output::Printer

Inherits:
Object
  • Object
show all
Includes:
AnsiStyles
Defined in:
lib/reviewer/output/printer.rb

Overview

Wrapper to encapsulate some lower-level details of printing to $stdout. Handles ANSI styling via the pre-computed AnsiStyles::STYLES constant.

Constant Summary

Constants included from AnsiStyles

AnsiStyles::COLORS, AnsiStyles::ESC, AnsiStyles::RESET, AnsiStyles::STYLES, AnsiStyles::STYLE_DEFS, AnsiStyles::WEIGHTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = $stdout) ⇒ Printer

Creates a printer for styled console output

Parameters:

  • stream (IO) (defaults to: $stdout)

    the output stream to write to



54
55
56
57
# File 'lib/reviewer/output/printer.rb', line 54

def initialize(stream = $stdout)
  @stream = stream
  @stream.sync = true if @stream.respond_to?(:sync=)
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



48
49
50
# File 'lib/reviewer/output/printer.rb', line 48

def stream
  @stream
end

Instance Method Details

This method returns an undefined value.

Prints styled content without a newline

Parameters:

  • style (Symbol)

    the style key for color and weight

  • content (String)

    the text to print



64
65
66
# File 'lib/reviewer/output/printer.rb', line 64

def print(style, content)
  text(style, content)
end

#puts(style, content) ⇒ void

This method returns an undefined value.

Prints styled content followed by a newline

Parameters:

  • style (Symbol)

    the style key for color and weight

  • content (String)

    the text to print



73
74
75
76
# File 'lib/reviewer/output/printer.rb', line 73

def puts(style, content)
  text(style, content)
  stream.puts
end

#tty?Boolean Also known as: style_enabled?

Whether the output stream is a TTY (interactive terminal)

Returns:

  • (Boolean)

    true if the stream supports ANSI styling



91
# File 'lib/reviewer/output/printer.rb', line 91

def tty? = stream.tty?

#write_raw(content) ⇒ void

This method returns an undefined value.

Writes content directly to the stream without styling. Skips if content is nil or blank.

Parameters:

  • content (String, nil)

    the raw text to write



83
84
85
86
87
# File 'lib/reviewer/output/printer.rb', line 83

def write_raw(content)
  return if content.to_s.strip.empty?

  stream << content
end