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, with_guide: nil, output: $stdout) ⇒ void
Render a note box to the output stream.
Class Method Details
.render(message = "", title: nil, with_guide: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Render a note box to the output stream.
With guides on, a rail line precedes the box and the bottom-left corner is a T-connector so the rail continues below. With guides off there is no leading rail and the corner is rounded (upstream behavior).
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/clack/note.rb', line 18 def render( = "", title: nil, with_guide: nil, output: $stdout) guide = Core::Settings.with_guide?(with_guide) 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) if guide 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)} #{padded}#{Colors.gray(Symbols::S_BAR)}" end output.puts build_bottom_border(width, guide) end |