Class: Dry::CLI::Help::Screens::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/cli/help/screens/base.rb

Overview

Renders the configured sections a screen supports, in configured order, one blank line apart. A subclass lists the sections it supports in SECTIONS and renders each in a private render_<name> that returns lines, or nil when there is nothing to print.

Direct Known Subclasses

Command, Listing

Constant Summary collapse

Row =
Formatter::Row
INDENT =
Formatter::INDENT
HELP =
Row.new(term: "-h, --help", text: "Show help", term_style: :option)

Instance Method Summary collapse

Constructor Details

#initialize(config:, io:, terminal_width: Terminal.width) ⇒ Base

Returns a new instance of Base.

Parameters:

  • config (Configuration)
  • io (IO) —

    where the screen prints

  • terminal_width (Integer) (defaults to: Terminal.width)


20
21
22
23
# File 'lib/dry/cli/help/screens/base.rb', line 20

def initialize(config:, io:, terminal_width: Terminal.width)
  @config = config
  @format = Formatter.new(config, io, terminal_width:)
end

Instance Method Details

#render ⇒ String

Returns:

  • (String)


26
27
28
29
30
31
32
33
# File 'lib/dry/cli/help/screens/base.rb', line 26

def render
  config.visible_sections
        .select { self.class::SECTIONS.include?(it) }
        .filter_map { send(:"render_#{it}") }
        .reject(&:empty?)
        .map { it.join("\n") }
        .join("\n\n")
end