Class: Ruby::Pomodoro::Printer
- Inherits:
-
Object
- Object
- Ruby::Pomodoro::Printer
- Defined in:
- lib/ruby/pomodoro/printer.rb
Instance Method Summary collapse
- #clear_terminal ⇒ Object
-
#initialize(stream: $stdout, cursor: TTY::Cursor, palette: Pastel.new) ⇒ Printer
constructor
A new instance of Printer.
- #print(text, color: nil) ⇒ Object
- #print_line(text, color: nil) ⇒ Object
- #print_template(template_name, cmd_binding) ⇒ Object
- #render(file_name) ⇒ Object
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_terminal ⇒ Object
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 |
#print(text, color: nil) ⇒ Object
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 |
#print_line(text, color: nil) ⇒ Object
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 |
#print_template(template_name, cmd_binding) ⇒ Object
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 |