class Chamomile::Layout::List
Public Class Methods
Source
# File lib/chamomile/layout/list.rb, line 6 def initialize(items, cursor: 0, height: nil, selected_color: "#7d56f4", dim_color: "#888888") @items = Array(items) @cursor = cursor @height = height @selected_color = selected_color @dim_color = dim_color end
Public Instance Methods
Source
# File lib/chamomile/layout/list.rb, line 15 def render(width:, height:) display_height = @height || height visible_items = @items.first(display_height) lines = visible_items.each_with_index.map do |item, i| text = item.to_s.ljust(width) if i == @cursor Chamomile::Style.new.foreground(@selected_color).reverse.render(text) else Chamomile::Style.new.foreground(@dim_color).render(text) end end lines.join("\n") end