Class: Ruby::Pomodoro::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/pomodoro/printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream: $stdout, cursor: TTY::Cursor, palette: Pastel.new) ⇒ Printer

Returns a new instance of Printer.



4
5
6
7
8
# File 'lib/ruby/pomodoro/printer.rb', line 4

def initialize(stream: $stdout, cursor: TTY::Cursor, palette: Pastel.new)
  @stream = stream
  @cursor = cursor
  @palette = palette
end

Instance Method Details

#clear_terminalObject



15
16
17
18
# File 'lib/ruby/pomodoro/printer.rb', line 15

def clear_terminal
  stream.print(cursor.up(100))
  stream.print(cursor.clear_screen_down)
end


20
21
22
23
24
25
26
27
# File 'lib/ruby/pomodoro/printer.rb', line 20

def print(text, color: nil)
  if color
    stream.print(palette.send(color, text))
  else
    stream.print(text)
  end
  stream.flush
end


29
30
31
32
# File 'lib/ruby/pomodoro/printer.rb', line 29

def print_line(text, color: nil)
  cursor.clear_line
  print(text, color: color)
end


10
11
12
13
# File 'lib/ruby/pomodoro/printer.rb', line 10

def print_template(template_name, cmd_binding)
  @__cmd_binding = cmd_binding
  stream.print(render(template_name))
end

#render(file_name) ⇒ Object



35
36
37
# File 'lib/ruby/pomodoro/printer.rb', line 35

def render(file_name)
  ERB.new(read_file(file_name)).result(@__cmd_binding)
end