Class: Gm::Notepad::BufferWrapper

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/gm/notepad/buffer_wrapper.rb

Overview

To provide a means for colorizing the output and defering output

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ BufferWrapper

Returns a new instance of BufferWrapper.



24
25
26
27
28
29
# File 'lib/gm/notepad/buffer_wrapper.rb', line 24

def initialize(*args)
  super
  if color
    buffer.extend(Term::ANSIColor)
  end
end

Class Method Details

.for_interactive(buffer:) ⇒ Object



9
10
11
# File 'lib/gm/notepad/buffer_wrapper.rb', line 9

def self.for_interactive(buffer:)
  new(buffer: buffer, color: Container[:config].interactive_color, append_new_line_on_close: true)
end

.for_output(buffer:) ⇒ Object



13
14
15
# File 'lib/gm/notepad/buffer_wrapper.rb', line 13

def self.for_output(buffer:)
  new(buffer: buffer, color: Container[:config].output_color, append_new_line_on_close: false)
end

Instance Method Details

#close!Object



39
40
41
42
43
44
# File 'lib/gm/notepad/buffer_wrapper.rb', line 39

def close!
  self.lines.each do |line|
    puts(line)
  end
  buffer.print("\n") if append_new_line_on_close
end

#puts(text) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/gm/notepad/buffer_wrapper.rb', line 31

def puts(text)
  if color
    buffer.puts("#{buffer.public_send(color)}#{text}#{buffer.reset}")
  else
    buffer.puts("#{text}")
  end
end