Module: Clack::Note
- Defined in:
- lib/clack/note.rb
Overview
Renders a bordered note box with optional title in the terminal.
Class Method Summary collapse
-
.render(message = "", title: nil, output: $stdout) ⇒ void
Render a note box to the output stream.
Class Method Details
.render(message = "", title: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Render a note box to the output stream.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/clack/note.rb', line 13 def render( = "", title: nil, output: $stdout) lines = .to_s.lines.map(&:chomp) # Add empty lines at start and end like original lines = ["", *lines, ""] title_len = Clack::Utils.visible_length(title) width = calculate_width(lines, title_len) output.puts Colors.gray(Symbols::S_BAR) output.puts build_top_border(title, title_len, width) lines.each do |line| pad = width - Clack::Utils.visible_length(line) padded = pad.positive? ? line + (" " * pad) : line output.puts "#{Colors.gray(Symbols::S_BAR)} #{Colors.dim(padded)}#{Colors.gray(Symbols::S_BAR)}" end output.puts build_bottom_border(width) end |