Class: Brut::CLI::Commands::Help::DescriptionList

Inherits:
Object
  • Object
show all
Defined in:
lib/brut/cli/commands/help.rb

Instance Method Summary collapse

Constructor Details

#initialize(term_align: :right, padding_bottom: 1) ⇒ DescriptionList

Returns a new instance of DescriptionList.



13
14
15
16
17
# File 'lib/brut/cli/commands/help.rb', line 13

def initialize(term_align: :right, padding_bottom: 1)
  @term_align = term_align
  @padding_bottom = padding_bottom
  @rows       = []
end

Instance Method Details

#<<(row) ⇒ Object



18
19
20
# File 'lib/brut/cli/commands/help.rb', line 18

def <<(row)
  @rows << row
end

#lipgloss_table(theme:, terminal:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/brut/cli/commands/help.rb', line 22

def lipgloss_table(theme:, terminal:)
  indent = "  "
  term_width = @rows.map { |r| r[0].length }.max
  description_width = terminal.cols - indent.length - term_width - 2
  formatted_rows = @rows.map { |row|
    [
      row[0],
      theme.wrap(row[1], indent: 0, max_width: description_width).strip,
    ]
  }
  Lipgloss::Table.new.
    border(:hidden).
    rows(formatted_rows).
    style_func(rows: formatted_rows.length, columns: 2) { |row,column|
    if column == 0
      Lipgloss::Style.new.inherit(theme.subheader).padding_bottom(@padding_bottom).align(@term_align)
    else
      Lipgloss::Style.new.padding_bottom(@padding_bottom)
    end
  }
end